Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

signavio-i18n

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

signavio-i18n

Minimalist gettext style i18n for JavaScript

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
46
increased by27.78%
Maintainers
1
Weekly downloads
 
Created
Source

signavio-i18n

Minimalist gettext style i18n for JavaScript

Features

  • Pluralization support (ngettext style)
  • Supports React components as interpolations
  • Optional markdown support
  • Compatible with webpack po-loader
  • Comes with scripts for extracting translation strings from JavaScript (Babel) sources and updating .pot and .po files

Installation

npm install --save signavio-i18n

Setup

Add the configuration for gettext message extraction to your .babelrc:

    "extra": {
        "gettext": {
            "headers": <POT_HEADERS>,
            "fileName": <PATH_TO_POT>,
            "baseDirectory": <PATH_TO_BASEDIR>
        }
    }

All available options are documented here: https://github.com/getsentry/babel-gettext-extractor

Add a section like the following to the packages.json:

    scripts": {
        "i18n-init": "cd src/locales && msginit --no-translator --input messages.pot --locale",
        "i18n": "i18n-extract \"src/**/!(*.spec).js?(x)\" src/locales/messages.pot && i18n-merge src/locales/messages.pot src/locales/*.po"
    },

Usage

Add the translations to the PO files, and initialize the i18n module in your application using the init function:

import i18n, { init, setLocale, reset } from '@signavio/i18n';

function getLangLoader(locale) {
    // Lazy load the translation bundles
    let bundleLoader = require(`bundle?lazy!json!po./locales/${locale}.po`);
    return bundleLoader;
};

var config = {
    default: 'en_US', // the default locale to use if the browser preference locale is not available
    map: {  // optional mapping of locales
        en: 'en_US',
        de: 'de_DE'
    }
};

init(getLangLoader, config).then(() => {
    // promise will be resolved when the translation bundle for the active locale has been loaded
    alert(i18n("Hello world!"));
})

FAQs

Package last updated on 23 Dec 2016

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