Coder Social home page Coder Social logo

phensley / cldr-engine Goto Github PK

View Code? Open in Web Editor NEW
46.0 5.0 3.0 48.67 MB

Internationalization and localization in Typescript with Unicode CLDR, batteries included

Home Page: https://phensley.github.io/cldr-engine/

License: Apache License 2.0

TypeScript 98.20% JavaScript 0.28% Shell 0.18% Python 1.18% HTML 0.16%
internationalization typescript unicode cldr arbitrary-precision i18n math language locale decimal

cldr-engine's Introduction

cldr-engine

Internationalization in Typescript with Unicode CLDR, batteries included.

build npm version

Links

Install

Install the NPM package:

npm install --save @phensley/cldr

Using Yarn:

yarn add @phensley/cldr

Versioning

This project follows semantic versioning:

PATCH

  • Bug fixes
  • Backwards-compatible
  • Resource pack compatibility maintained (packs from 1.0.0 are guaranteed to work for all 1.0.* versions)

MINOR

  • New features
  • Backwards-compatible
  • Internal schema breaking changes (applications must load resource packs from the same major.minor version)
  • CLDR data upgrades which maintain backwards-compatibility

MAJOR

  • Public API breaking changes
  • CLDR data upgrades which change break API compatibility (unit deprecation / renaming, etc)

Features

Package Naming

Packages with the cldr-* prefix represent pieces of the larger library and are designed to work together. The @phensley/cldr package pulls in the full functionality of the library.

Packages without the cldr-* prefix can be used in an application individually without pulling in the larger core library.

You can use any of the packages independent of the rest of the library:

package size dependencies
@phensley/cldr-utils min+gzip
@phensley/decimal min+gzip
@phensley/language-tag min+gzip
@phensley/locale min+gzip size includes language-tag package
@phensley/locale-matcher min+gzip size includes locale and language-tag packages
@phensley/messageformat min+gzip size includes cldr-utils, decimal, and plurals packages
@phensley/plurals min+gzip size includes decimal package
@phensley/timezone min+gzip size includes cldr-utils package
@phensley/unit-converter min+gzip size includes cldr-utils and decimal packages

Goals

  • Support a broad set of CLDR features in the browser "out of the box".
  • Support all scripts and regions for a language in a single compact resource pack.
  • Resolve the CLDR data size and dimensionality problems.
    • In the case of English: ~49MB of JSON for 106 locales is compressed to a 227KB resource pack (42KB gzip), a factor of approx. 220:1 uncompressed, 1200:1 with gzip compression.
  • No additional library dependencies required.
  • No custom extraction of CLDR data or precompilation of formatters required.
  • Correctness and consistency across browsers, Node.js, and other Javascript ES5 runtime environments.
  • Provide type-safety, reducing programming errors.
  • No familiarity with CLDR structure is required for developers to use this library.
  • High performance.
  • Arbitrary precision decimal math, to achieve the same accuracy in the browser as on the server.

License

Copyright 2018-present Patrick Hensley

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Affiliation

This project is not affiliated with the Unicode Inc. or the Unicode CLDR project.

cldr-engine's People

Contributors

phensley avatar tim-stasse avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

cldr-engine's Issues

Time interval and 'begin-sentence' context

This is more a question than a bug report.
In a time interval, when I use the default 'middle-of-text' context with the fr language, this is what I get:

cldr.Calendars.formatDateInterval(
  start,
  end,
  {
    skeleton: 'yMMMEd',
    context: 'middle-of-text',
  }
)
mar. 1 janv. – mar. 31 déc. 1963

Now, with context set to 'begin-sentence', I get the following:

Mar. 1 janv. – Mar. 31 déc. 1963

I would expect 'begin-sentence' to return something like this:

Mar. 1 janv. – mar. 31 déc. 1963

With only the first part of the interval capitalised, and the second part in lower case.

Is this the intended behaviour of CLDR?

General.getLanguageDisplayName returns nothing for multi-subtag language tags

Hey Patrick,

I stumbled upon this small bug, just thought I would leave this for you here. Testing for v0.25.1 with an English bundle loaded, this statement returns nothing instead of "Simplified Chinese":

cldr.General.getLanguageDisplayName('zh-Hans');

It only works for plain language ids, like 'en' or 'es'. I've included a snippet from the English bundle for reference, note that in most cases, the tag in question includes a region subtag, except in the case of Chinese.

"ar-001": "Modern Standard Arabic",
"de-AT": "Austrian German",
"de-CH": "Swiss High German",
"en-AU": "Australian English",
"en-CA": "Canadian English",
"en-GB": "British English",
"en-US": "American English",
"es-419": "Latin American Spanish",
"es-ES": "European Spanish",
"es-MX": "Mexican Spanish",
"fa-AF": "Dari",
"fr-CA": "Canadian French",
"fr-CH": "Swiss French",
"nds-NL": "Low Saxon",
"nl-BE": "Flemish",
"pt-BR": "Brazilian Portuguese",
"pt-PT": "European Portuguese",
"ro-MD": "Moldavian",
"sr-ME": "Montenegrin",
"sw-CD": "Congo Swahili",
"zh-Hans": "Simplified Chinese",
"zh-Hant": "Traditional Chinese",

(Source: https://github.com/unicode-cldr/cldr-localenames-modern/blob/master/main/en/languages.json)

Example on codesandbox.io

Edit @phensley/cldr language name bug example

Possible issue location

https://github.com/phensley/cldr-engine/blob/master/packages/cldr-schema/src/code/names.ts#L6

Once again, thanks for all the hard work.

Get time interval with formatDateInterval

I'm trying to get a localised time interval using cldr.Calendars.formatDateInterval. It always returns the date no matter what skeleton I pass as an option. e.g.:

cldr.Calendars.formatDateInterval(
  start,
  end,
  {
    skeleton: 'Hmm',
    ca: 'gregory',
  }
)

Returns something like this with the ja language:

1/1 18:15~12/31 18:45

I'd like to get:

18:15~18:45
// Or even better:
18時15分~18時45分

When I look inside the language pack for Japanese, I see patterns like this one:

H時mm分~H時mm分

So it looks like the information is there, but somehow not surfaced.

I'd like to either have this function to comply more closely to the skeleton or a different function called cldr.Calendars.formatTimeInterval.

CLDR: let's talk

Hi, @phensley — stumbled on this while trying to get another beta of the cldr json v38 data out.

tl;dr (yes, sounds like cldr) is, let's talk! Can you drop me an email? All my contact info is at https://github.com/srl295


Looking at:

I'm working on https://unicode-org.atlassian.net/browse/CLDR-14258 right now.

anyway, i'm working on another drop of the v38 beta CLDR JSON data on NPM. - i'll send an email to cldr-users when ready…  It's already checked in to the new monorepo on the branch https://github.com/unicode-org/cldr-json/tree/for-38-beta2

Date/Number parsing

Hi there, I was just wondering if there are any plans to add parsing to the feature stack. In some scenarios it would be nice to parse the date or number against the current user culture.

Regards
Benjamin

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.