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

sg-i18n

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sg-i18n

Fork of https://github.com/ccqgithub/i18n-s

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

i18n-s

A simple tool to translate i18n.

use

install

npm install i18n-s -S

use

import I18n from 'i18n-s';

let locale = 'zh-cn';
let localeData = {
  "test": "test string",
  "b.test": "test string b",
  "a is b's father": "${a} is ${b}'s father",

  "c": {
    "test": "test string c"
  }
}

let i18n = new I18n({
  locale: 'zh-CN', // init locale
  i18nData: {}, // init data,
  log: process.env.NODE_ENV !== 'production', // is log when no translate
  // log: function(msg) { console.log(msg) }, // log can be a function
});

// set current locale and locale data
i18n.setLocaleData(locale, i18nData);
i18n.setLocale(locale);

// translate with vars
let str = i18n.__('test');

// translate with dot
let str = i18n.__('b.test');

// translate with context
let str = i18n.__('c.test');

// translate with vars
let str = i18n.__('a is b\'s father', {
  a: 'Json',
  b: 'Joy'
});

api

  • i18n.setLocaleData(locale, localeData)
  • i18n.setLocale(locale)
  • i18n.translate(key, vars={})
  • i18n.__(key, vars={}): alias to i18n.translate

FAQs

Package last updated on 22 Mar 2021

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