New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@noreajs/i18n

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@noreajs/i18n

Library of tools necessary for the internationalization of an application, based on polyglot from airbnb

  • 0.0.1-0
  • next
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

i18n

Library of tools necessary for the internationalization of an application, based on polyglot from airbnb.

Installation

npm install @noreajs/i18n --save

The package already contains it's types definitions files for typescript developers.

Usage

Translations files

The default translation file is i18n. If the folder doesn't exit, it will be created automatically by the package.

Synchronous initialize i18n

import I18n from "../i18n/I18n";

const i18n = new I18n({
    locales: ["en-US", "en-FR"],
    fallback: "en-fr",
    languagesFolder: "i18n" // i18n is the default value and it is optional.
});

// set the locale
i18n.setLocale("en-US");

i18n.t("users.index.empty");

Asynchronous initialization

import I18n from "../i18n/I18n";

const i18n = new I18n({
    locales: ["en-US", "en-FR"],
    fallback: "en-fr",
    syncLoading: false
});

// load translations (asynchronous method)
i18n.loadTranslations((data) => {
    i18n.setLocale("en-fr");
    console.log("t:", i18n.t("users.index.empty"));
});

I18n parameters

To initialize a the i18n package, you need to fill some parameters.

PropertyTypeDefaultNote
localesArrayLocale supported
fallbackstringfirst locales valueFallback locale
languagesFolderstringi18nFolder where translations files are stored. This folder is automatically created when not exists
lazyLoadingbooleanfalseResolve translation key while translate
caseSensitivebooleanfalseusers.index.empty and users.index.EMPTY will be treated the same way
syncLoadingbooleantrueLoad translations during initialization
polyglotOptionspolyglot optionsOnly interpolation, allowMissing and onMissingKey is allowed

I18n methods

MethodDescription
setLocaleChange the current locale
getLocaleGet the current locale
getTranslationsGet the available translations loaded from files
loadTransactionsAsynchronous method to load translations when syncLoading is false
tTranslate a given key

Keywords

FAQs

Package last updated on 08 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc