ivpusic / i18n-xlsx

Typesafe i18n

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 Language]: 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

About

Typesafe i18n

License:MIT License


Languages

Language:TypeScript 57.5%Language:HTML 22.4%Language:JavaScript 20.1%