0.2.2 • Published 4 years ago
@goldenthumb/simple-i18n-csv-to-json v0.2.2
simple-i18n-csv-to-json
Install
npm install @goldenthumb/simple-i18n-csv-to-json
const toJson = require('@goldenthumb/simple-i18n-csv-to-json');
Usage
sample csv
ko | en | ja | zh_CN | zh_TW | |
---|---|---|---|---|---|
yes | 예 | Yes | はい | 是的 | 是的 |
No | No | いいえ | 没有 | 沒有 |
CLI
Usage: i18n-csv2json <input file> [<output file>] [--allowEmpty]
$ i18n-csv2json ./sample.csv ./output.json
Basic
$ i18n-csv2json ./sample.csv ./output.json
const toJson = require('@goldenthumb/simple-i18n-csv-to-json');
(async () => {
try {
const result = await toJson('./sample.csv');
console.log(result);
> result
{
ko: {
yes: '예'
},
en: {
yes: 'Yes',
no: 'No'
},
ja: {
yes: 'はい',
no: 'いいえ'
},
zh_CN: {
yes: '是的',
no: '没有'
},
zh_TW: {
yes: '是的',
no: '沒有'
}
};
} catch(e) {
console.log(e);
}
})();
Allow Empty String
$ i18n-csv2json ./sample.csv ./output.json --allowEmpty
const toJson = require('@goldenthumb/simple-i18n-csv-to-json');
(async () => {
try {
const result = await toJson('./sample.csv', { allowEmpty: true });
console.log(result);
> result
{
ko: {
yes: '예',
no: ''
},
en: {
yes: 'Yes',
no: 'No'
},
ja: {
yes: 'はい',
no: 'いいえ'
},
zh_CN: {
yes: '是的',
no: '没有'
},
zh_TW: {
yes: '是的',
no: '沒有'
}
};
} catch(e) {
console.log(e);
}
})();
Using by with @goldenthumb/simple
npm install @goldenthumb/simple-i18n @goldenthumb/simple-i18n-csv-to-json
const SimpleI18n = require('@goldenthumb/simple-i18n');
const toJson = require('@goldenthumb/simple-i18n-csv-to-json');
(async () => {
try {
const messages = await toJson('./sample.csv');
const i18n = new SimpleI18n({
defaultLocale: ['en'],
locale: 'en',
messages
});
i18n.message('yes')
> Yes.
i18n.switchLang('ja');
i18n.message('no');
> いいえ
} catch(e) {
console.log(e);
}
})();
License
MIT
0.2.2
4 years ago
0.2.1
5 years ago
0.2.0
5 years ago
0.1.13
5 years ago
0.1.12
5 years ago
0.1.11
6 years ago
0.1.10
6 years ago
0.1.9
6 years ago
0.1.8
6 years ago
0.1.7
6 years ago
0.1.6
6 years ago
0.1.5
6 years ago
0.1.4
6 years ago
0.1.3
6 years ago
0.1.2
6 years ago
0.1.1
6 years ago
0.1.0
6 years ago
0.0.4
6 years ago
0.0.3
6 years ago
0.0.2
6 years ago
0.0.1
6 years ago