1.0.0 • Published 7 years ago
message-loader v1.0.0
i18n properties message loader for webpack
When import / require i18n.properties, import all other properties files in the same directory, and output as json.
Usage
npm i message-loader -DAdd message-loader into webpack config.
{
module: {
rules: [
{
test: /i18n[a-zA-Z_]*\.properties$/,
use: 'message-loader'
}
]
}
}src/i18n/i18n.properties
default properties
hello = 你好
invoice.title = 发票抬头
app.name = 测试 Appsrc/i18n/i18n_en.properties
hello = hello
invoice.title = invoice titlesrc/i18n/i18n_fr.properties
fr = frsrc/index.js
import messages from './i18n/i18n.properties';
console.log(messages);
// should output following code
/*
{
default: {
hello: '你好',
'invoice.title': '发票抬头',
'app.name': '测试 App'
},
en: {
hello: 'hello',
'invoice.title': 'invoice title',
'app.name': '测试 App'
},
fr: {
hello: '你好',
'invoice.title': '发票抬头',
'app.name': '测试 App',
fr: 'fr'
}
}
*/options
Override default options with following loader config.
{
test: /message(?:_([a-zA-Z_]+))?\.properties$/,
use: {
loader: 'message-loader',
options: {
filePattern: /message(?:_([a-zA-Z_]+))?\.properties$/,
locales: ['en']
}
}
}options.filePattern
default to: /i18n(?:_([a-zA-Z_]+))?\.properties$/.
Means will search following files in the same directory, i18n.properties, i18n_en.properties, i18n_zh_CN.properties, and so on.
when use file name to match pattern, the result at index 1 will be the locale.
options.locales
Should be an array with locale string, e.g. ['en', 'zh_CN'].
Means only specific locale messages will be returned, Notice: default message will be return if exist.
1.0.0
7 years ago