5.0.0 • Published 3 years ago

i18n-format v5.0.0

Weekly downloads
3
License
BSD-2-Clause
Repository
github
Last release
3 years ago

Build Status Coverage Status npm version Published on webcomponents.org

<i18n-format>

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

Demo and API Docs

Install

    npm install i18n-format

Import

    import "i18n-format/i18n-format.js";

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.

Demo

Prerequisite for Building and Serving Demo

    npm install -g polymer-cli

On-the-fly Build

    # Serve at http://localhost:8080/components/i18n-format/demo/
    polymer serve --npm --module-resolution=node -p 8080

Static Builds

  • Build
    polymer build
  • Targets
targetbrowserminifybundled
build/esm-unbundledes6,modulesnono
build/esm-bundledes6,modulesyesyes
build/es6-bundledes6yesyes
build/es5-bundledes5yesyes
  • Serve
    # Serve at http://localhost:8080/
    cd build/{esm-unbundled|esm-bundled|es6-bundled|es5-bundled}
    python -m SimpleHTTPServer 8080 # or any HTTP(S) server

License

BSD-2-Clause

5.0.0

3 years ago

4.0.1

4 years ago

4.0.0

5 years ago

4.0.0-pre.13

5 years ago

4.0.0-pre.12

5 years ago

4.0.0-pre.11

5 years ago

4.0.0-pre.10

5 years ago

4.0.0-pre.9

5 years ago

4.0.0-pre.8

5 years ago

4.0.0-pre.7

5 years ago

4.0.0-pre.6

5 years ago

4.0.0-pre.5

5 years ago

4.0.0-pre.4

5 years ago

4.0.0-pre.3

5 years ago

4.0.0-pre.2

5 years ago

4.0.0-pre.1

5 years ago

3.0.1

5 years ago

2.0.1

5 years ago

3.0.0

5 years ago

3.0.0-pre.12

5 years ago

3.0.0-pre.11

5 years ago

3.0.0-pre.10

5 years ago

3.0.0-pre.9

5 years ago

3.0.0-pre.8

5 years ago

3.0.0-pre.7

5 years ago

3.0.0-pre.6

5 years ago

3.0.0-pre.5

5 years ago

3.0.0-pre.4

5 years ago

3.0.0-pre.3

5 years ago

3.0.0-pre.2

5 years ago

2.0.0

7 years ago

1.0.0

8 years ago