[OpenLayers-Trac] [OpenLayers] #109: Pull all strings out and into a single js file for localization
OpenLayers
trac at openlayers.org
Wed Jan 30 11:57:09 EST 2008
#109: Pull all strings out and into a single js file for localization
----------------------+-----------------------------------------------------
Reporter: euzuro | Owner: madair
Type: task | Status: new
Priority: minor | Milestone: 2.6 Release
Component: general | Version: 2.3
Resolution: | Keywords:
State: Review |
----------------------+-----------------------------------------------------
Comment (by tschaub):
Thanks for the work on this Mike. I've got some general comments I'd like
to discuss - perhaps in IRC. Regarding this patch, what do you think
about using the existing OpenLayers.String.format instead of introducing
the formatMessage function? Then your translate signature could look
something like:
{{{
OpenLayers.String.translate(key, context);
}}}
Where you'd have "named args" in the context instead of positional ones.
In long templates or in templates that want to repeat a variable, named
arguments are a bit handier than positional ones.
In addition, I wonder if we can have an i18n function right in the
OpenLayers namespace. So, the following would do the same as your current
translate:
{{{
OpenLayers.i18n(key, context);
}}}
Finally, I do like the suggestion that we tack dictionaries on to
individual components. This is what I'd like to discuss more on IRC. I
do see value in having a global dictionary, but I also think it makes
sense to maintain translation relative to some context. As a simple
example, one control may want to capitalize "Layer" and another might want
to print "layer". We have to have a whole lot of forethought to pick keys
that make sense in all cases. This job becomes easier when your context
is limited (to a single control).
I think a static property on classes that use strings makes sense. If
others like this idea, we could have an i18n method on all classes. If an
instance comes from a class with a static "lang" property, then its i18n
method looks there. If that property doesn't exist, i18n falls back to
the global dictionary. Then your calls to translate (in code that belongs
to a particular class) is shortened to:
{{{
this.i18n(key, context);
}}}
An alternative would be to stick "lang" properties on the prototypes.
Then we'd get inheritance (with all it's blessings and curses), and people
could customize strings by setting their own "lang" property in the
familiar options argument to a constructor.
Personally, I like the name "lang" or OpenLayers.Language over
OpenLayers.Strings. Would be good to get a chance to discuss again on
IRC.
--
Ticket URL: <http://trac.openlayers.org/ticket/109#comment:10>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer
More information about the Trac
mailing list