GithubHelp home page GithubHelp logo

formatjs / formatjs-extract-cldr-data Goto Github PK

View Code? Open in Web Editor NEW
11.0 13.0 10.0 326 KB

[MIGRATED] Utility library that extracts the CLDR data that's needed by the FormatJS libraries.

License: Other

JavaScript 100.00%

formatjs-extract-cldr-data's Introduction

This package has been migrated to the FormatJS monorepo repository.

FormatJS Extract CLDR Data

Utility library that extracts the CLDR data that's needed by the FormatJS libraries.

npm Version Build Status Dependency Status

Usage

This package offers a function to extract the CLDR data needed by the FormatJS libraries via its default export. The data is returned as an object keyed by locale language tags; e.g., "en-US". This package leverages the fact that language tags are hierarchical and will only return the unique, de-duplicated data that's needed.

The following example shows how the locale hierarchy is used to return the unique data:

var extractData = require('formatjs-extract-cldr-data');

var data = extractData({
    locales    : ['en-US', 'en-GB'],
    pluralRules: true
});

console.log(data); // =>

{ 'en-US': { locale: 'en-US', parentLocale: 'en' },
  'en-GB': { locale: 'en-GB', parentLocale: 'en-001' },
  'en-001': { locale: 'en-001', parentLocale: 'en' } },
  en: { locale: 'en', pluralRuleFunction: [Function] }

Since the pluralRuleFunction for the root locale "en" is the same as used in the locales: "en-US" and "en-GB", the function is located in the "en" entry. The entries for the en-* locales all contain a parentLocale property which can be followed up to "en".

Data Shape

The data object returned from this package will have the following shape, here's the data for US English:

{ en:
   { locale: 'en',
     pluralRuleFunction: [Function],
     fields:
      { year: [Object],
        "year-short": [Object],
        month: [Object],
        "month-short": [Object],
        week: [Object],
        "week-short": [Object],
        day: [Object],
        "day-short": [Object],
        hour: [Object],
        "hour-short": [Object],
        minute: [Object],
        "minute-short": [Object],
        second: [Object],
        "second-short": [Object] } } }

Each field has the following shape, here's the data for English year:

{ displayName: 'Year',
  relative: { '0': 'this year', '1': 'next year', '-1': 'last year' },
  relativeTime:
   { future: { one: 'in {0} year', other: 'in {0} years' },
     past: { one: '{0} year ago', other: '{0} years ago' } } }

Options

In order for any data to be returned, the value true must be assigned to either the pluralRules and/or relativeFields options. By default, data will be returned for all locales in the CLDR; to limit which locales, assign an array of them to the locales option.

locales

An optional array of locales to extract data for, specified as string language tags. By default, data will be returned for all locales in the CLDR.

Note: This package leverages the language tag hierarchy to de-duplicate data and also normalizes the casing of language tags. There will be an entry for every locale specified in locales, plus an entry to each parent locale up to the root. When a locale has a parent, a parentLocale field will be present in that locale's entry.

pluralRules

Boolean for whether or not pluralRuleFunctions should be extracted for the specified locales. These functions will support both cardinal and ordinal pluralization. These functions are generated using the make-plural project.

relativeFields

Boolean for whether or not fields should be extracted for the specified locales. The field data that's extracted is limited to the data required to support FormatJS' relative time formatting features, and it's organized in the shape described above.

Updating the CLDR Data

The CLDR version and data used by this package can be easily updated by changing the cldr-* package versions in package.json.

Note: It's recommended to keep the package versions exact and not use ~ or ^ modifiers.

License

This software is free to use under the Yahoo Inc. BSD license. See the LICENSE file for license text and copyright information.

The CLDR data contained in this packaged is licensed under the Apache, ICU, and Unicode licenses. See the CLDR license files for their license text and copyright information.

formatjs-extract-cldr-data's People

Contributors

artursvonda avatar dtm5011 avatar ericf avatar jasonmit avatar longlho avatar okuryu avatar ykzts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

formatjs-extract-cldr-data's Issues

Update CLDR 33.0 release

Issue to track updating CLDR data to the 33.0 release.

Also, should this library be using cldr-numbers-full or cldr-numbers-modern? I'm a bit confused as to the different.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.