User:Waldo/Internationalization API: Difference between revisions

Jump to navigation Jump to search
More fleshing out
(Begin work on a high-level overview of i18n support in SpiderMonkey)
 
(More fleshing out)
Line 5: Line 5:
The ECMAScript Internationalization API (ECMA-402) significantly extends these capabilities, to provide genuinely useful means of localization to ECMAScript.  Outputs may be customized in various ways by requesting different components be included in output, formatted in various ways.  The locale used for a formatting operation is customizable, and output formatting is intelligently determined in accordance with the locale.  It additionally provides means of locale-sensitively sorting data, according to the type of that data (for example, sorting names in phone book order, versus sorting them in dictionary order), considering or ignoring capitalization, accents, and so on.
The ECMAScript Internationalization API (ECMA-402) significantly extends these capabilities, to provide genuinely useful means of localization to ECMAScript.  Outputs may be customized in various ways by requesting different components be included in output, formatted in various ways.  The locale used for a formatting operation is customizable, and output formatting is intelligently determined in accordance with the locale.  It additionally provides means of locale-sensitively sorting data, according to the type of that data (for example, sorting names in phone book order, versus sorting them in dictionary order), considering or ignoring capitalization, accents, and so on.


== SpiderMonkey support for Internationalization ==
The Internationalization API introduces one new global property: <code>Intl</code>.  This property is an object with various properties corresponding to various sub-APIs: collation (sorting), number formatting, and date/time formatting.  (More capabilities will be added in future Internationalization API updates.)  The localization APIs from ES5 have been reformulated to use the localization capabilities provided by the Internationalization API.  Generally, however, it's preferable to use the Internationalization API directly, as this is more efficient by permitting caching of the structures needed to perform each operation.


SpiderMonkey includes significant support for the Internationalization API.  The fundamental primitives used to implement the API are provided by an in-tree imported copy of ICU in {{source|intl/icu}}.  This is an optional component of a SpiderMonkey build; support may be turned on using the <code>--enable-intl-api</code> configuration option.  The Internationalization API is enabled by default in Firefox builds.
== Internationalization in SpiderMonkey ==
 
SpiderMonkey includes significant support for the Internationalization API.  The fundamental primitives used to implement the API are provided by an in-tree imported copy of ICU in {{source|intl/icu}}.  This is an optional component of a SpiderMonkey build; support may be turned on using the <code>--enable-intl-api</code> configuration option.  The Internationalization API is enabled by default in Firefox builds.  Features and capabilities of the API itself are implemented in both C++ and in self-hosted JavaScript that accesses ICU functionality through various intrinsic functions in the self-hosting global.
 
=== Code organization ===
 
==== Integration ====
 
The <code>Intl</code> object is integrated into the global object through code in {{source|js/src/builtin/Intl.cpp}} and {{source|js/src/builtin/Intl.h}}.  <code>js_InitIntlClass</code> performs this operation when it's called during global object bootstrapping, in concert with various other initialization methods in the same file and in {{source|js/src/vm/GlobalObject.cpp}}.
 
The Internationalization API is added to SpiderMonkey in the {{source|js/src/builtin/Intl.cpp}} and {{source|js/src/vm/Intl.h}} headers.  These files integrate the <code>Intl</code> object into the global object, define This is primarily integration code to add <code>Intl</code> to the global object.
 
==== Self-hosted code ====
 
The majority of the self-hosted code implementing Internationalization is in {{source|js/src/builtin/Intl.js}}.  This file defines the functions exposed on the various <code>Intl.*</code> constructor functions and the various <code>Intl.*.prototype</code> objects.
 
Internationalization in various cases requires keeping around large data tables: to record the set of supported currency codes, to record language tag (hyphenated strings describing locales, and various options) mappings, and so on.  This data lives in {{source|js/src/builtin/IntlData.js}} and is generated by {{source|js/src/builtin/make_intl_data.py}}.  This script downloads original (large) plaintext databases, parses them, and extracts in the proper format the data used by Internationalization.
 
=== Key concepts ===
 
...
Confirmed users
446

edits

Navigation menu