Giter Club home page Giter Club logo

webpack-amdi18n-loader's Introduction

amdi18n-loader

Travis branch npm

Webpack i18n loader similar to require.js i18n plugin. The loader also support CommonJS module and .json files, and more, .coffee files.

Install

npm install amdi18n-loader

Usage

First look at require.js i18n plugin's docs at here.

The language part is like this:

  • lang.js
  • zh-cn/lang.js
  • zh-hk/lang.js

lang.js:

define({
    // root means the common language package
    root:{
        HELLO:'hello'
    },
    // we have the language packages below:
    'zh-cn':true,
    'zh-hk':true
});

zh-cn/lang.js example:

define({
    // please note: no wrapper object here!
    HELLO:'hello in zh-cn'
});

Then use it like this:

define([
    'amdi18n!lang'
],function(amdi18n){

    // By default, it will lookup `window._i18n.locale`,
    // If not found, it will try to use the html[lang] attribute,
    // For example: <html lang="en"> then language `en` was used,
    // If nothing found, `root` was used.
    // You can manully change the language by
    // `amdi18n.init(language)`;

    console.log(amdi18n.HELLO);


});

Advanced Usage

You can pass queries to enable or disable some langs.

// We use commonjs now. It matters nothing.
var lang = require('amdi18n?enable=[zh-cn]!');

// It's not ok to use zh-hk now!
lang.init('zh-hk');

The code below behaviors the same:

// We use commonjs now. It matters nothing.
var lang = require('amdi18n?disable=[zh-hk]!');

// It's not ok to use zh-hk now!
lang.init('zh-hk');

It's ok to use both enable and disable, but if any one disables a lang, the lang will not be usable. You can decide which to use by the length of list.

History

v0.5.1 (2017-01-14)

  • Fix: AMD lang file without factory function not working. #8

v0.5.0 (2017-01-13)

  • Add enable and disable queries. #6
  • Detect default language by html[lang] attribute. #7
  • Rewrite the method that extract language definitions.
  • Add testing & travis CI.

v0.4.0 (2016-01-18)

  • Support .coffee language files. (By Mullerzs)

v0.3.2 (2015-12-15)

  • Fix bug using in UMD mode. (By Rick)

v0.3.1 (2015-12-15)

  • Fix bug on IE. (By Rick)

v0.3.0 (2015-12-14)

  • Support load CommonJS module and json file. (By Rick)

v0.2.0 (2015-10-15)

  • Auto init.

v0.1.0 (2015-10-14)

  • First release.

webpack-amdi18n-loader's People

Contributors

mullerzs avatar toobug avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.