default-locale

0.3.4 • Public • Published

default-locale

npm version npm downloads dependencies license

default-locale - is a tool that helps you to add multilanguage option 🌏 in your web application.

Default Locale Logo

Installation

Install it from npm

npm install default-locale --save

or check out the wiki for documentation.

Examples of usage

Before starting to use this library, you need to prepare a config file and your localized resources. Make it easier. 💪

The structure of my folders with resources is

  • res.js (default locale)
  • res.en.js (english locale)
  • res.ru.js (russian locale)

res.js

// Export must be the JSON object!
module.exports = {
    text: 'Hello World!'
};

Config file

'use strict'
 
module.exports = path => {
    return {
        CONTEXT: path, // current path to the root folder. This folder must contain resources directory.
        RESOURCE_FOLDER: 'resources', // the name of resource folder
        RESOURCE_DEFAULT_FILE: 'res.js', // name of the file, which contain default localized resources
        RESOURCE_FILE_PREFIX: 'res.', // prefix of localized files
        RESOURCE_FILE_EXTENSION: '.js', // extensions of  of localized files
        localeList: ['ru'] // the list of support locales
    };
};

Main program

'use strict';
 
const localeConfig = require('./localeConfig')(__dirname);
const LocaleService = require('default-locale');
 
LocaleService.init(localeConfig);
console.log(LocaleService.getString('text'));
console.log(LocaleService.getString('text', 'ru'));

Support

Please, report bugs on the issue tracker

License

The MIT License (MIT)

Copyright (c) 2016 Uni-Q Lab

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.3.4
    2
    • latest

Version History

Package Sidebar

Install

npm i default-locale

Weekly Downloads

2

Version

0.3.4

License

MIT

Last publish

Collaborators

  • sasd97