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

intljulep

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intljulep

Super lightweight yet powerful i18n library

  • 0.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by42.86%
Maintainers
1
Weekly downloads
 
Created
Source

:tropical_drink: intljulep

Super lightweight yet powerful i18n library

dependencies minified + brotlied size minified + zipped size

types npm version license

Why

Only 20 lines of code to get i18n with internal references (translations in your translations) and simple plurals such as in English or in French. No dependencies.

NodeJS

Installation

npm install intljulep

Import

import { i18n } from 'intljulep'

Browser

Intljulep uses ES modules, widely supported in browsers nowadays. Import the i18n function from the intljulep.min.js file. This file can be located in a CDN (example below) or copied in any directory of your website (for better performance and to be GDPR compliant, since you don’t have to connect to a third party server).

<script type="module">
  import { i18n } from 'https://cdn.jsdelivr.net/npm/intljulep@0.2.3/intljulep.min.js'
</script>

Usage

i18n.addLocale('en', {
  foo: "the bar",
  plurals: {
    msg: ["message", "messages"],
    man: ["man", "men"],
    woman: ["woman", "women"]
  },
  email: {
    hey: "Hey!",
    // Note the `@` prefix to use other translations in your translation
    info: "Hi {name}. {@email.hey} You have {number} {@plurals.msg(number)}."
  }
})
i18n.setLocale('en')

i18n('foo') // "the bar"
i18n('email.baz') // "email.baz"
i18n('plurals.msg', 0) // "messages"
i18n('plurals.msg', 1) // "message"
i18n('plurals.msg', 2) // "messages"
i18n('plurals.msg', 3) // "messages"
i18n('email.info', { name: "Laurent", number: 0 }) // "Hi Laurent. Hey! You have 0 messages."
i18n('email.info', { name: "Laurent", number: 1 }) // "Hi Laurent. Hey! You have 1 message."
i18n('email.info', { name: "Laurent", number: 2 }) // "Hi Laurent. Hey! You have 2 messages."
i18n('email.info', { name: "Laurent", number: 3 }) // "Hi Laurent. Hey! You have 3 messages."

i18n.addLocale('fr', {
  foo: "le bar"
})
i18n.setLocale('fr')
i18n('foo') // "le bar"

i18n.setLocale('en')
i18n('foo') // "the bar"

Note that you don’t have to use the plurals key specifically as nothing is hardcoded. You could use a single character key like s for convenience:

i18n.addLocale('en', {
  s: {
    msg: ["message", "messages"],
    man: ["man", "men"],
    woman: ["woman", "women"]
  },
})
i18n.setLocale('en')

i18n('s.man', 3) // "men"

License

MIT

Keywords

FAQs

Package last updated on 28 Sep 2023

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