@smartface/i18n
TypeScript icon, indicating that this package has built-in type declarations

5.1.7 • Public • Published

Twitter: @Smartface_io License: MIT

i18n

Intro

This module implements multi language support for Smartface applications.

Getting started

Create language files like below, for detailed instructions you can check out https://www.i18next.com/overview/getting-started#basic-sample

en.ts

export default {
  helloWorld: "Hello World",
  welcomeUser: "Welcome {{user}}",
  keyWithCount_one: "{{count}} key",
  keyWithCount_other: "{{count}} keys"
};

tr.ts

export default {
  helloWorld: "Merhaba Dünya",
  welcomeUser: "Hoşgeldin {{user}}",
  keyWithCount_one: "{{count}} anahtar",
  keyWithCount_other: "{{count}} anahtarlar"
};

Initialize i18n instance

import i18n from "@smartface/i18n";
import System from "@smartface/native/device/system"

import en from "./en";
import tr from "./tr";

new i18n({
  lng: Device.language,
  debug: System.isEmulator,
  resources: {
    en: {
      translation: en
    },
    tr: {
      translation: tr
    }
  },
  fallbackLng: "en"
  // many options available
  // https://www.i18next.com/overview/configuration-options
});

//You can get formatted string like this
i18n.instance.t("helloWorld");
i18n.instance.t("welcomeUser", { user: "Smartface" });
i18n.instance.t("keyWithCount", { count: 0 });
i18n.instance.t("keyWithCount", { count: 1 });
i18n.instance.t("keyWithCount", { count: 5 });

//Change the language without app reload, it updates the instance
i18n.changeLanguage("tr");

//subscribe to locale changes
const unsubscribe = i18n.on('change', () => {
  console.log("subscribe trigger");
});

//this will unsubscribe
unsubscribe();

Readme

Keywords

none

Package Sidebar

Install

npm i @smartface/i18n

Weekly Downloads

0

Version

5.1.7

License

MIT

Unpacked Size

8.76 kB

Total Files

8

Last publish

Collaborators

  • sbasbug
  • alnyli07
  • smf
  • furkan.arabaci