Skip to content
/ i18n Public

Lightweight i18n solution for universal JavaScript apps and modules.

Notifications You must be signed in to change notification settings

Draggable/i18n

Repository files navigation

i18n NPM Version

Add multi-lingual support to any JavaScript app or module with this light-weight package.

Features:

  • Isomorphic/Universal
  • easy translation of static text files
    • benefits: anyone can translate, no more xliff
    • reduced margin of error.
  • Variable support
  • Dependency free
  • Fast

Usage

import { I18n } from '@draggable/i18n'

const i18nOptions = {
  extension: '.lang', // extnsion used by your language files, defaults to ".lang"
  location: 'https://location.of/language/files/', // absolute or relative url to language files
  langs: [
    // locales you would like to be active
    'en-US',
    'pt-BR',
    'de-DE', // will attempt to load `https://location.of/language/files/de-DE.lang` with current config
  ],
  locale: 'en-US', // default locale
  override: {
    'en-US': {
      autocomplete: 'Autofinish', // override individual keys or provide entire language definition
    },
  },
}
const i18n = new I18n(i18nOptions)

... then in your app

<label>{i18n.get('addOption')}</label>

Add a Language after initialization

i18n.addLanguage('fr-FR', {
  addOption: 'Ajouter une option',
})

Process a confige file

i18n.processConfig(configFileString)

Example .lang file

de-DE = Deutsch
en-US = German

addOption = Option hinzufügen
allFieldsRemoved = Alle Felder wurden entfernt.
allowMultipleFiles = Upload mehrerer Dateien erlauben
autocomplete = Autovervollständigung