i18n-xlsx
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

i18n-xlsx

Build Status Open Source Love PRs Welcome

Typesafe i18n

This module tries to solve problem of managing i18n data via transpiling excel files with i18n data into other typesafe formats. Currently supported formats are:

  • Typescript
  • Go

Installation

npm install -g i18n-xlsx

Tutorial (Typescript)

  1. Create excel file with i18n data:

Header should contain code column and list of supported languages (in this case hr and en). Library also supports multiple sheets.

  1. Use i18n-xlsx to create typescript file
i18n-xlsx -i translations.xlsx -o i18n.ts

Check i18n.ts file. It will have following output.

interface ISheet1 {
  testKey1: string;
  testKey2: string;
}
 
interface ISheets {
  sheet1: ISheet1;
}
 
enum Language {
  hr = 'hr',
  en = 'en',
}
 
const all: { [key in string]: ISheets } = {
  hr: {
    sheet1: {
      testKey1: 'vrijednost 1',
      testKey2: 'vrijednost 2',
    },
  },
  en: {
    sheet1: {
      testKey1: 'value 1',
      testKey2: 'value 2',
    },
  },
};
 
export default all;
  1. Use generated code
import i18n from './path/to/i18n.ts';
 
console.log(i18n.en.sheet1.testKey1); // typesafe + intellisense

License

MIT

Package Sidebar

Install

npm i i18n-xlsx

Weekly Downloads

0

Version

0.2.2

License

MIT

Last publish

Collaborators

  • ivpusic