globalizejs/globalize

Docs: Use Globalize with Ecma-402

Open

#532 geöffnet am 10. Okt. 2015

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (645 Forks)batch import
docshelp wantedquick change

Repository-Metriken

Stars
 (4.759 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

We should provide examples demonstrating how certain modules (e.g., message, relative time, unit formatters) could be used along with Ecma-402.

:boom: It's important to highlight that such mixture of libraries will decrease the supported browsers (or will require user to polyfill when needed).

I think this topic deserves presence in the main documentation (REDAME.md) and specific examples inside of each of the mentioned modules.

Requires:

  • Add unit formatting #512
  • Relative Time: Accept numberFormatter as option #531

Examples:

var ecmaNumberFmt = Intl.NumberFormat( "en" );

Globalize.loadMessages({
  en: {
    task: [
      "You have {count, plural,",
      "     =0 {no tasks}",
      "    one {one task}",
      "  other {{formattedCount} tasks}",
      "} remaining"
    ]
  }
});

taskFormatter = Globalize( "en" ).messageFormatter( "task" );

taskFormatter({
  count: 0,
  formattedCount: ecmaNumberFmt( 0 )
});

var relativeTimeFormatter = Globalize( "en" ).relativeTimeFormatter(  "month", {
  numberFormatter: ecmaNumberFmt
});

var unitFormatter = Globalize( "en" ).unitFormatter(  "month", {
  numberFormatter: ecmaNumberFmt
});

Ref #399

Contributor Guide