[mochikit] MochiKit.I18n -- proposed new module for internationalization
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
[mochikit] typeName() function -- introspecting object types
Being tired of all the idiosyncrasies of the typeof() operator, I tried to make something better: function typeName(value) { if (typeof(value) !== object !(value instanceof RegExp)) { return typeof(value); } else if (value == null) { return null; } else { var c = value.constructor || {}; return c.name || c.NAME || Object; } } See here: https://github.com/cederberg/mochikit/commit/582a51531f68a17aa0ddea41df5957cd09424a25 I was thinking about including this in MochiKit.Base, possibly modifying typeMatcher() on the go. That would break backward compatibility a bit, so the question is if it would be worthwhile? This is how typeName() works right now: undefined == undefined null == null false == boolean new Boolean(true) == Boolean 42 == number new Number(42) == Number [1] test == string new String() == String [1] { a: 1 } == Object [2] [1,2,3] == Array new Date() == Date /\d+/ == RegExp new MyClass() == MyClass [3] Notes: [1]: There are two forms of these built-in types, but normally the constructor form is not used much. [2]: These objects constructor actually point to the Object function, hence the upper-case initial. [3]: For this to work, the constructor property must be set and the constructor function must have either a name or a NAME property. Cheers, /Per -- 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.