New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

simple-languages

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-languages

A tiny package for switching languages

latest
Source
npmnpm
Version
1.0.4
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Simple Languages

A small wrapper for switching languages. Inspired by react-localization and rewritten using Proxy for a much smaller code base (50 ~ 80 lines of codes).

Installation

npm install --save simple-languages or yarn add simple-languages

Usage

Basic usage

import createLanguages from 'simple-languages'

// create the Languages object
const Languages = createLanguages()

// set the language, it is 'en' by default
Languages.lang = 'vi'

/* set the language data, it can be overwrite anytime
 * please note that the words "formatString", "lang" and "data" are reserved
 */
Languages.data = {
  en: {
    hello: 'Hello'
  },
  vi: {
    hello: 'Xin chào'
  }
}

console.log(Languages.hello) // => Xin chào

Languages.lang = 'en' // change language by setting the lang property

console.log(Languages.hello) // => Hello

Format string with placeholder

Basic usage

import createLanguages from 'simple-languages'
import formatString from 'simple-languages/formatString'

const Languages = createLanguages()
Languages.data.en = {
  hello: 'Hello, {0} and {1}!!!'
}

// ...do the same as above then
Languages.formatString = formatString

console.log(Languages.formatString(Languages.hello, 'John', 'David')) // => Hello, John and David!!!

With react

import formatString from 'simple-languages/formatString-react'

Caveats

Since this plugin using Proxy which is only supported by modern browsers. https://caniuse.com/#search=proxy.

However, a polyfill can be used to support IE9+.

Keywords

react

FAQs

Package last updated on 26 Sep 2024

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