Translate your JS applications
You can use yarn or npm to add the idiom.js to your project
$ yarn add idiom.js
or using npm:
$ npm install --save idiom.js
or download from CDN:
After that you need to create the language files
// ECMAScript 6
import idiom from 'idiom.js';
export default idiom({
'default': {
'hello': 'Hello!',
'bye': 'Bye!'
},
'pt-BR': {
'hello': 'Olá!',
'bye': 'Tchau!'
}
})(window.navigator.language);
// Common Modules
const idiom = require('idiom.js');
module.extends = idiom({
'default': {
'hello': 'Hello!',
'bye': 'Bye!'
},
'pt-BR': {
'hello': 'Olá!',
'bye': 'Tchau!'
}
})(window.navigator.language);
Import the idiom.min.js
file to your browser
<script src="/path/to/idiom.min.js"></script>
<script>
var lang = idiom({
'default': {
'hello': 'Hello!',
'bye': 'Bye!'
},
'pt-BR': {
'hello': 'Olá!',
'bye': 'Tchau!'
}
})(window.navigator.language);
</script>
After that, you can use text
function to get that correct string
// returns 'Olá!' if in pt-BR and 'Hello!' if not
lang.text('hello');
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Fabio Soares - Initial work - fabioars
This project is licensed under the MIT License - see the LICENSE.md file for details
- Hat tip to anyone whose code was used
- Inspiration
- etc