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

i18n-format

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18n-format

Text formatter with Unicode CLDR Plural Rules and choices support

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by800%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage Status Published on webcomponents.org Bower

<i18n-format>

Text formatter with Unicode CLDR plural rules and choices (like gender) support.

Demo and API Docs

Install

    bower install --save i18n-format

Import

    <link rel="import" href="/path/to/bower_components/i18n-format/i18n-format.html">

Usage

Simple Template Format
    <p>
      <i18n-format>
        <span>{1} element is effective for UI localization with {2}.</span>
        <code>i18n-format</code>
        <a href="https://www.google.com/">parameters</a>
      </i18n-format>
    </p>

This renders as follows:

    <p><code>i18n-format</code> element is effective for UI localization with <a href="https://www.google.com/">parameters</a>.</p>
Compound Template Format

An appropriate template in json-data is selected by plural categories, gender, etc.

    <p>
      <i18n-format lang="{{lang}}">
        <json-data>{
          "0": "You ({3}) gave no gifts.",
          "1": {
            "male": "You ({3}) gave him ({4}) {5}.",
            "female": "You ({3}) gave her ({4}) {5}.",
            "other": "You ({3}) gave them ({4}) {5}."
          },
          "one": {
            "male": "You ({3}) gave him ({4}) and one other person {5}.",
            "female": "You ({3}) gave her ({4}) and one other person {5}.",
            "other": "You ({3}) gave them ({4}) and one other person {5}."
          },
          "other": "You ({3}) gave them ({4}) and {1} other people gifts."
        }</json-data>
        <i18n-number lang="{{effectiveLang}}" offset="1">{{recipients.length}}</i18n-number>
        <span>{{recipients.0.gender}}</span>
        <span>{{sender.name}}</span>
        <span>{{recipients.0.name}}</span>
        <span>a gift</span>
      </i18n-format>
    </p>

With these values for the parameters, the template path .one.female is selected from <json-data>.

ParametersValues
lang'en'
recipients.length2
recipients.0.gender'female'
sender.name'James'
recipients.0.name'Alice'

So this example renders as follows:

  <p>You (<span>James</span>) gave her (<span>Alice</span>) and one other person <span>a gift</span>.</p>

<i18n-number> specifies plural categories for CLDR plural rules.

License

BSD-2-Clause

Keywords

FAQs

Package last updated on 16 May 2017

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