Skip to content

fabioars/idiom.js

Repository files navigation

idiom.js

Translate your JS applications

Build Status

Getting Started

Installing

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:

Usage

If you use JS Modules

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);

In Browser

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'); 

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Fabio Soares - Initial work - fabioars

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Hat tip to anyone whose code was used
  • Inspiration
  • etc

About

Multilanguage support to your JS application

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published