This is pretty cool, something I always imagined that I might do if I
were doing this kind of localization. We've only done en and zh at
Mochi, so haven't needed anything outside of the system format.

On Mon, Jan 10, 2011 at 6:38 PM, Per Cederberg <cederb...@gmail.com> wrote:
> Since I found the MochiKit.Format.formatLocale() function too limited,
> I hacked up a new MochiKit.I18n module:
>
>  https://github.com/cederberg/mochikit/blob/i18n/MochiKit/I18n.js
>
> It is backwards compatible and adds locales for most languages on
> earth (data derived from Wikipedia and Google Closure sources). At the
> moment it only contains numeric formatting information, but can be
> extended with currency and datetime formatting information if needed.
>
> My intention is to include this in the default MochiKit 1.4 tree and
> update the MochiKit.Text module to properly support the number
> formatting specified in these locales (some are not currently
> supported).
>
> Please let me know if you have any issues with this.
>
> Cheers,
>
> /Per
>
> PS. Pasting in the source rst docs below to give a clue as to how it
> is supposed to work.
>
> ----
>
> Name
> ====
>
> MochiKit.I18n - internationalization, localization and globalization
>
>
> Synopsis
> ========
>
> ::
>
>   assert( locale().decimal == "." );
>   assert( locale("sv_SE").decimal == "," );
>
>
> Description
> ===========
>
> This module contains numeric localization information for most languages
> and regions on earth. Actual text formatting lives in other modules (such
> as :mochiref:`MochiKit.Text`).
>
>
> Dependencies
> ============
>
> - :mochiref:`MochiKit.Base`
>
>
> Overview
> ========
>
> Locale Names
> ------------
> MochiKit uses IETF language codes [1] to identify a locale, e.g.
> ``"en_US"``. The locale database also supports the use of previously
> unknown locale identifiers by creating a new locale based on the
> language code or the default locale. A number of built-in locale
> identifiers are also supported:
>
>    +-------------+---------------------------------------------------------+
>    | Language    | Description                                             |
>    +=============+=========================================================+
>    | ``system``  | The built-in system locale. It is identical to a        |
>    |             | ``"en_US"`` locale for backward compatibility.          |
>    +-------------+---------------------------------------------------------+
>    | ``user``    | The user locale, as reported by the browser. This       |
>    |             | points to a specific language locale (or the            |
>    |             | ``"system"`` locale.)                                   |
>    +-------------+---------------------------------------------------------+
>    | ``default`` | The default locale, used when no language code is       |
>    |             | provided. This points to the ``"system"`` locale by     |
>    |             | default.                                                |
>    +-------------+---------------------------------------------------------+
>
> The default locale is modified by accessing the ``MochiKit.I18n.LOCALE``
> cache of resolved locale objects:
>
> ::
>
>    MochiKit.I18n.LOCALE["default"] = locale("user");
>
>
> Locale Objects
> --------------
>
> The locale objects returned by :mochiref:`locale()` and stored in the
> ``MochiKit.I18n.LOCALE`` cache all have the following properties (some
> inherited through the prototype chain):
>
>    +---------------------+-----------------------------------------+
>    | Name                | Description                             |
>    +=====================+=========================================+
>    | ``decimal``         | The decimal dot character.              |
>    +---------------------+-----------------------------------------+
>    | ``separator``       | The thousands grouping character.       |
>    +---------------------+-----------------------------------------+
>    | ``separatorGroups`` | The size of thousands groups (from      |
>    |                     | right to left). Repeats when exhausted. |
>    +---------------------+-----------------------------------------+
>    | ``percent``         | The percent character.                  |
>    +---------------------+-----------------------------------------+
>    | ``permille``        | The permille character.                 |
>    +---------------------+-----------------------------------------+
>    | ``plus``            | The plus sign character.                |
>    +---------------------+-----------------------------------------+
>    | ``minus``           | The minus sign character.               |
>    +---------------------+-----------------------------------------+
>    | ``signAtEnd``       | The boolean sign at end of string flag. |
>    +---------------------+-----------------------------------------+
>    | ``infinity``        | The infinity character.                 |
>    +---------------------+-----------------------------------------+
>
>
>
> API Reference
> =============
>
> Functions
> ---------
>
> :mochidef:`locale(spec="default")`:
>
>    Returns the locale object corresponding to ``spec``. The locale
>    object returned contains formatting and localization information
>    that is used when displaying data in non-English languages (see
>    description above for details).
>
>    Note that the cached locale database entry is returned, so any
>    modifications to this object will affect other calls.
>
>    ``spec``:
>        The optional ISO/IETF language code [1] or an object to merge
>        with the default locale.  If ``spec`` is omitted, the default
>        locale is returned. If ``spec`` is not recognized or is not a
>        string, a custom locale will be created (based on the default
>        locale).
>
>    *Availability*:
>        Available in MochiKit 1.5+
>
>
> See Also
> ========
>
> .. [1] IETF BCP 47:
>       http://en.wikipedia.org/wiki/BCP_47
>
> --
> You received this message because you are subscribed to the Google Groups 
> "MochiKit" group.
> To post to this group, send email to mochi...@googlegroups.com.
> To unsubscribe from this group, send email to 
> mochikit+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/mochikit?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to mochi...@googlegroups.com.
To unsubscribe from this group, send email to 
mochikit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en.

Reply via email to