Ticket #352 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

i18n support

Reported by: fredj Assigned to:
Priority: major Milestone: 1.1
Component: GeoExt Version: trunk
Keywords: Cc:
State: Commit

Description

From: http://www.geoext.org/pipermail/dev/2010-May/000755.html

The idea is to use the same system as extjs to create translation files.

We need one new directory in geoext core (in lib/GeoExt/locale/) and a directory per ux (in ux/<ux name>/lib/GeoExt.ux/locale/).

For the ux, the translation files should be prefixed with the ux name to avoid name collision, for example ux/Measure/lib/locale/Measure-lang-fr.js and ux/SimplePrint/lib/locale/SimplePrint-lang-fr.js.

Attachments

352.ux.0.patch (2.8 kB) - added by fredj on 09/29/10 15:14:12.
352.core.0.patch (0.7 kB) - added by fredj on 09/29/10 15:50:03.
depends on #353
352.patch (14.6 kB) - added by tschaub on 11/14/10 05:10:25.
simple i18n framework
352.1.patch (14.6 kB) - added by fredj on 11/18/10 09:32:04.
fix a syntax error in GeoExt-fr.js and add requires GeoExt/Lang.js

Change History

09/29/10 15:14:12 changed by fredj

  • attachment 352.ux.0.patch added.

09/29/10 15:50:03 changed by fredj

  • attachment 352.core.0.patch added.

depends on #353

10/13/10 13:58:45 changed by fredj

  • state changed from None to Review.

Please review

11/14/10 05:10:25 changed by tschaub

  • attachment 352.patch added.

simple i18n framework

11/14/10 05:11:10 changed by tschaub

I'll provide justification for this in a bit.

11/18/10 01:10:25 changed by tschaub

The ext-fr.js style of localization files have a couple shortcomings in my opinion: 1) they require a build time decision about the language (instead of using a client's runtime settings), and 2) they include a fair bit of logic that translators shouldn't have to worry about (if this, apply that).

I think a simple i18n framework could be put together with the following goals:

  1. Support runtime preferences where possible (browser language settings), allowing a single build to include translations for multiple languages.
  2. Make language files as simple as possible for translators to work with.
  3. Allow applications (or the library in the future) to support setting the language after initialization (or initial library load).

The attached patch accomplishes these goals without adding a lot of overhead (in my opinion). The GeoExt.Lang object is an observable singleton. The add method takes a language tag (of the rfc3066 form) and a lookup object. The lookup object has a member for each object in the application with localizable strings. The member name is a dot delimited string that resolves to the target object (e.g. "GeoExt.MapPanel.prototype") and the member value is an object that should be applied to the target object to localize string properties. The add method can be called multiple times to compile the dictionary for a given language. The set method actually sets localizable strings on target objects based on entries in the dictionary. Setting to a language with a subtag (e.g. "en-CA") first applies all strings from the primary tag (e.g. "en") before applying any subtag strings. This allows for partial or absent regional dictionaries where the primary language settings will still be applied.

When the library loads, the browser language settings are set as the default locale. This means that dictionaries for multiple locations can be included in a single build and the user should get strings based on their local language settings. If the app developer wants to set a single language (regardless of user settings), they call set after add.

Tests demonstrate a few examples of use.

11/18/10 09:32:04 changed by fredj

  • attachment 352.1.patch added.

fix a syntax error in GeoExt-fr.js and add requires GeoExt/Lang.js

11/23/10 00:06:13 changed by ahocevar

  • state changed from Review to Commit.

Looks good. Thumbs up - please commit.

11/23/10 14:43:49 changed by tschaub

  • status changed from new to closed.
  • resolution set to fixed.

(In [2486]) Adding simple i18n framework to facilitate localization of applications. Thanks fredj for the French strings. r=ahocevar (closes #352)

11/23/10 14:58:36 changed by tschaub

(In [2487]) Adding French strings from fredj for the ux (see #352).