Skip to content

Instantly share code, notes, and snippets.

@DenisIzmaylov
Last active May 3, 2021 21:12
Show Gist options
  • Save DenisIzmaylov/dbd7e85f384016e3e07a to your computer and use it in GitHub Desktop.
Save DenisIzmaylov/dbd7e85f384016e3e07a to your computer and use it in GitHub Desktop.
Easy i18n translation in your ES6 apps
{
"ru": {
"Your original english text": "Твой оригинальный русский текст"
}
}
const i18n = require('./i18n-data.json');
let currentLang = 'en';
export function setLanguage(id) {
currentLang = id;
}
export function t(text) {
return (i18n[currentLang] && i18n[currentLang][text]) || text;
}
import React, { Component } from 'react';
import t from './i18n';
export default MyComponent extends Component {
render() {
<div>
{t('Your original english text')}
</div>
}
}
@itsmepetrov
Copy link

Missing import { t } from './i18n' in my-component.js :)

@DenisIzmaylov
Copy link
Author

Thanks a lot! 👍

@a1exlism
Copy link

a1exlism commented Dec 7, 2016

Thanks for sharing:-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment