Socket
Book a DemoInstallSign in
Socket

locale-translate

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

locale-translate

Locale Translate is an NPM module made to make managing locales as easy as possible. With LT, you can define new locales, and easily use them afterwards.

latest
npmnpm
Version
1.0.2
Version published
Weekly downloads
1
-75%
Maintainers
1
Weekly downloads
 
Created
Source

Locale Translate

Locale Translate is an NPM module made to make managing locales as easy as possible. With LT, you can define new locales, and easily use them afterwards.

Installation

npm i translate-it

Usage

First, you need to create a JSON file. Feel free to name it whatever you like. We recommend locales.json. Then use this format, changing what you need:

{
  "en-US": {
    "started": "Your project has been initialized.",
    "colorChange": "Your project's color has changed."
  },
  "en-UK": {
    "started": "Your project has been initialised.",
    "colorChange": "Your project's colour has changed."
  }
}

Then, in your JS file, use this,

let translator = require('locale-translate')

translator.importLocales(require('locales.json'), 'memory') // stores the locales in memory

let translated = translator.translate('started', 'en-US')

console.log(translated) // Expected result 'Your project has been initialized.'

Parameters

Using {} in a translation string allows use of parameters. This is so you can easily pass data into your translated strings. For example,

{
  "en-US": {
    "started": "Your project, {}, has been initialized.",
    "colorChange": "Your project's color has changed to {}."
  },
  "en-UK": {
    "started": "Your project, {}, has been initialised.",
    "colorChange": "Your project's colour has changed to {}."
  }
}

Use the same usage, but use .translateParams()

Keywords

translate

FAQs

Package last updated on 24 Mar 2019

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.