Skip to content

LiShiSangZi/lang-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Language Loader

This is a webpack loader which can help to load and parse lang.json file. So that you don't have to pack all your language files. It is used to help reduce the compiled JS size if you use i18n.

Install

npm i --save-dev lang-loader

Usage

Build your lang.json

{
  "en": {
    "test": "TEST"
  },
  "zh-CN": {
    "test": "测试"
  }
}

webpack.config.js

module.exports = {
  module: {
    rules: [{
        loader: 'lang-loader',
        test: /lang.json$/,
        query: {
          language: language
        }
    }]
  }
}

Use it in your file

const __ = require('./lang.json');

If your language is set to 'en', the __ will look like this:

{
  "test": "TEST"
}

Benifit

The benifit of this loader is that you don't have to put all your i18n content in a single JS. You can generate your JS file for each language like: en.content.min.js zh-CN.content.min.js Then your JS file's size can be reduced.

Have fun!

About

Lang.json loader for different language.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published