0.2.2 • Published 6 years ago
@goldenthumb/simple-i18n-csv-to-json v0.2.2
simple-i18n-csv-to-json
Install
npm install @goldenthumb/simple-i18n-csv-to-jsonconst 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.jsonBasic
$ i18n-csv2json ./sample.csv ./output.jsonconst 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 --allowEmptyconst 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-jsonconst 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
6 years ago
0.2.1
7 years ago
0.2.0
7 years ago
0.1.13
7 years ago
0.1.12
7 years ago
0.1.11
7 years ago
0.1.10
7 years ago
0.1.9
7 years ago
0.1.8
7 years ago
0.1.7
7 years ago
0.1.6
7 years ago
0.1.5
7 years ago
0.1.4
7 years ago
0.1.3
7 years ago
0.1.2
7 years ago
0.1.1
7 years ago
0.1.0
7 years ago
0.0.4
7 years ago
0.0.3
7 years ago
0.0.2
7 years ago
0.0.1
7 years ago