[OpenTripPlanner] Multilanguage proposal

77 views
Skip to first unread message

jvhigon

unread,
Apr 23, 2010, 5:34:38 AM4/23/10
to OpenTripPlanner Developers
Hi everyone,
I would like to propose a new way to deal with multilanguage in OTP.
That is, using the Openlayers approach.
The steps would be the following:
1.- It would be a javascript file for each language. This file would
extend the OpenLayers file defined for this language. For example:

OpenLayers.Lang.en_otp = OpenLayers.Util.extend(OpenLayers.Lang.en, {
'key' : 'translation_in_otp_code',
...
CLASS_NAME: "OpenLayers.Lang.en_otp"
});

2.- The language would be set at the beginning of the application,
using an OpenLayers function. For example:

OpenLayers.Lang.setCode('en_otp');

3.- The translatiosn would be done with another OpenLayers function:

OpenLayers.Lang.translate('key')

By the way, there is some source code that is not able to be
translated like "Templates.js" . With this new approach the changes
would be as described below:

Now:
TP_START : new Ext.XTemplate(
'<h4><a href="#">Start at</a> {name}</h4>'
).compile(),

With OpenLayers approax

TP_START = new Ext.XTemplate(
'<h4><a href="#">' + OpenLayers.Lang.translate('start_at')
+ '</a> {name}</h4>'
).compile();

What do you think?

Regards


--
Subscription settings: http://groups.google.com/group/opentripplanner-dev/subscribe?hl=en

David Turner

unread,
Apr 23, 2010, 12:34:19 PM4/23/10
to opentripp...@googlegroups.com
This sounds good to us. Would you be willing to write a patch to do
this?

David Turner

unread,
Apr 23, 2010, 1:00:33 PM4/23/10
to opentripp...@googlegroups.com
Actually, question: how does this deal with plurals? Because I just
found myself writing code to deal with plurals and realized that if I
had to do very much of that, I would go mad:

<tpl if="duration != 1.0">{[this.locale.time.minute]}</tpl>)<tpl
if="duration != 1.0">{[this.locale.time.minutes]}</tpl>)</span></tpl>

Also, it would not work for languages like Polish which have a separate
forms not just for 1 and n, but also for other numbers.

See this:
http://www.gnu.org/software/hello/manual/gettext/Plural-forms.html

jvhigon

unread,
Apr 23, 2010, 2:25:12 PM4/23/10
to OpenTripPlanner Developers
Hi,
regarding to write a patch, I could try it, ¿where should I send the
patches (one for each File which uses locale)?. I would rather commit
on SVN than write a patch but I understand that it is a problem for
you to give commit rights.
As regards plurals, this approach consider plurals as a new string so
the code for your example would be

<tpl if="duration != 1.0">{[OpenLayers.Lang.translate('singular')]}</
tpl>)<tpl
if="duration != 1.0">{[OpenLayers.Lang.translate('plural')]}</tpl>)</
span></tpl>

I don't know if it is enough for Polish, for Spanish it does.

Regards

Nicholas Bergson-Shilcock

unread,
Apr 23, 2010, 2:29:25 PM4/23/10
to opentripp...@googlegroups.com
Excerpts from jvhigon's message of Fri Apr 23 14:25:12 -0400 2010:
> Hi,
> regarding to write a patch, I could try it, ¿where should I send the
> patches (one for each File which uses locale)?. I would rather commit
> on SVN than write a patch but I understand that it is a problem for
> you to give commit rights.

The best thing would be to create a ticket and attach the patches there. We're
pretty welcoming to new contributors, and our policy
(http://opentripplanner.org/wiki/DevelopersGuide#Contributingtotheproject) only
requires you commit one useful/working patch before being eligible for svn
commit rights :)

> As regards plurals, this approach consider plurals as a new string so
> the code for your example would be
>
> <tpl if="duration != 1.0">{[OpenLayers.Lang.translate('singular')]}</
> tpl>)<tpl
> if="duration != 1.0">{[OpenLayers.Lang.translate('plural')]}</tpl>)</
> span></tpl>
>
> I don't know if it is enough for Polish, for Spanish it does.

This looks good to me, though I too don't know anything about Polish.

David Turner

unread,
Apr 23, 2010, 2:55:52 PM4/23/10
to opentripp...@googlegroups.com
On Fri, 2010-04-23 at 11:25 -0700, jvhigon wrote:
> Hi,
> regarding to write a patch, I could try it, ¿where should I send the
> patches (one for each File which uses locale)?. I would rather commit
> on SVN than write a patch but I understand that it is a problem for
> you to give commit rights.
> As regards plurals, this approach consider plurals as a new string so
> the code for your example would be
>
> <tpl if="duration != 1.0">{[OpenLayers.Lang.translate('singular')]}</
> tpl>)<tpl
> if="duration != 1.0">{[OpenLayers.Lang.translate('plural')]}</tpl>)</
> span></tpl>
>
> I don't know if it is enough for Polish, for Spanish it does.

Please read the Gettext link -- it explains the problems with this
approach.

> > See this:http://www.gnu.org/software/hello/manual/gettext/Plural-forms.html

Could we just use jsgettext?

http://jsgettext.berlios.de/

Karel Novotny

unread,
Apr 23, 2010, 3:36:16 PM4/23/10
to opentripp...@googlegroups.com
On Fri, 2010-04-23 at 13:00 -0400, David Turner wrote:
> Actually, question: how does this deal with plurals? Because I just
> found myself writing code to deal with plurals and realized that if I
> had to do very much of that, I would go mad:
>
> <tpl if="duration != 1.0">{[this.locale.time.minute]}</tpl>)<tpl
> if="duration != 1.0">{[this.locale.time.minutes]}</tpl>)</span></tpl>
>
> Also, it would not work for languages like Polish which have a separate
> forms not just for 1 and n, but also for other numbers.
>
> See this:
> http://www.gnu.org/software/hello/manual/gettext/Plural-forms.html

I am glad you brought this up. I am czech and haven't actually realized
that just '1 vers. many' system doesn't work for my language either.

karel

jvhigon

unread,
Apr 26, 2010, 1:34:58 AM4/26/10
to OpenTripPlanner Developers
Hello,
I've never used jsgettext so I can't help doing a patch at this moment
(I could contribute with the changes that I commented few days ago).
The approach with gettext seems to be better than the OpenLayers
solution (I don't know if OL have already worked this problem out). I
wiil wait for your answer in order to do the patch.
Regards

Nicholas Bergson-Shilcock

unread,
Apr 26, 2010, 11:49:25 AM4/26/10
to opentripp...@googlegroups.com
Excerpts from jvhigon's message of Mon Apr 26 01:34:58 -0400 2010:
> Hello,
> I've never used jsgettext so I can't help doing a patch at this moment
> (I could contribute with the changes that I commented few days ago).
> The approach with gettext seems to be better than the OpenLayers
> solution (I don't know if OL have already worked this problem out). I
> wiil wait for your answer in order to do the patch.

If Dave or I took a pass at moving what's currently localized to the gettext
system, would you be able to then help out in bringing some of the remaining
items (e.g., those listed in ticket #220 http://opentripplanner.org/ticket/220)
over to the new system?

-Nick

> Regards
>
> On 23 abr, 21:36, Karel Novotny <novotny.ka...@gmail.com> wrote:
> > On Fri, 2010-04-23 at 13:00 -0400, David Turner wrote:
> > > Actually, question:  how does this deal with plurals?  Because I just
> > > found myself writing code to deal with plurals and realized that if I
> > > had to do very much of that, I would go mad:
> >
> > > <tpl if="duration != 1.0">{[this.locale.time.minute]}</tpl>)<tpl
> > > if="duration != 1.0">{[this.locale.time.minutes]}</tpl>)</span></tpl>
> >
> > > Also, it would not work for languages like Polish which have a separate
> > > forms not just for 1 and n, but also for other numbers.
> >
> > > See this:
> > >http://www.gnu.org/software/hello/manual/gettext/Plural-forms.html
> >
> > I am glad you brought this up. I am czech and haven't actually realized
> > that just '1 vers. many' system doesn't work for my language either.
> >
> > karel
> >
> >
> >
> >
> >
> > > On Fri, 2010-04-23 at 12:34 -0400, David Turner wrote:
> > > > This sounds good to us.  Would you be willing to write a patch to do
> > > > this?  
> >
> > > > On Fri, 2010-04-23 at 02:34 -0700, jvhigon wrote:
> > > > > Hi everyone,
> > > > > I would like to propose a new way to deal with multilanguage in OTP..

Krzysztof Witalewski

unread,
Apr 28, 2010, 4:15:08 AM4/28/10
to OpenTripPlanner Developers
Hi there,

our Polish team would of course also appreciate making use of the
gettext approach.

Cheers,
Chris

jvhigon

unread,
Apr 28, 2010, 7:07:12 AM4/28/10
to OpenTripPlanner Developers
Of course I would.
I will wait for your step and I will contribute as much as I can.
Regards

On 26 abr, 17:49, Nicholas Bergson-Shilcock <nichola...@openplans.org>
wrote:
> Excerpts from jvhigon's message of Mon Apr 26 01:34:58 -0400 2010:
>
> > Hello,
> > I've never used jsgettext so I can't help doing a patch at this moment
> > (I could contribute with the changes that I commented few days ago).
> > The approach with gettext seems to be better than the OpenLayers
> > solution (I don't know if OL have already worked this problem out). I
> > wiil wait for your answer in order to do the patch.
>
> If Dave or I took a pass at moving what's currently localized to the gettext
> system, would you be able to then help out in bringing some of the remaining
> items (e.g., those listed in ticket #220http://opentripplanner.org/ticket/220)

Frank

unread,
May 1, 2010, 8:15:52 AM5/1/10
to OpenTripPlanner Developers
To clarify, I'm seeing the proposal shaping up like this:

1. move the exiting English.js and Spanish.js translation content over
to gettext Portable Object (PO) files
2. use jsgettext within the .js webapp to read the PO, and translate
our strings.

That's great. I'm +1 on this idea, with the addition that we maintain
the PO translation files in a single place available for use
throughout the project, to both java and javascript modules (as
opposed to locking translations away in the webapp / javascript
specific). My question is in what module do we house the PO files?
Do we use an exiting module (e.g., opentripplanner-utils) or create a
new module (e.g., opentripplanner-localizations)?

On Apr 26, 8:49 am, Nicholas Bergson-Shilcock
<nichola...@openplans.org> wrote:
> Excerpts from jvhigon's message of Mon Apr 26 01:34:58 -0400 2010:
>
> > Hello,
> > I've never used jsgettext so I can't help doing a patch at this moment
> > (I could contribute with the changes that I commented few days ago).
> > The approach with gettext seems to be better than the OpenLayers
> > solution (I don't know if OL have already worked this problem out). I
> > wiil wait for your answer in order to do the patch.
>
> If Dave or I took a pass at moving what's currently localized to the gettext
> system, would you be able to then help out in bringing some of the remaining
> items (e.g., those listed in ticket #220http://opentripplanner.org/ticket/220)

David Turner

unread,
May 1, 2010, 9:34:43 AM5/1/10
to opentripp...@googlegroups.com
Since so far we have no strings anywhere but the webapp (and the gui,
but that's developers-only), let's just put the po files in the webapp.

Frank

unread,
May 1, 2010, 1:50:34 PM5/1/10
to OpenTripPlanner Developers
Dave, what do our print, text-planner and mobile solutions look like
(myself, I see some server-side .html generation in our future ...
something that up to now has not happened inside of the webapp module,
although server-side could easily happen there)? If all of our web
UI work is going to be co-located under the webapp module, and the po
files will be reachable by both java and javascript, then I'm +0 on
putting the po files there.

David Turner

unread,
May 2, 2010, 4:15:41 PM5/2/10
to opentripp...@googlegroups.com
Yes, webapp does sound like a good place for those.

Karel Novotny

unread,
May 2, 2010, 4:46:57 PM5/2/10
to opentripp...@googlegroups.com
This sounds great. Did you guys think about how to combine this solution
with some simple way of switching between various language mutations
(gettext files) from within GUI?
I myself don't know how, but maybe it is good to keep this requirement
in mind when implementing this.

karel

On Sat, 2010-05-01 at 05:15 -0700, Frank wrote:

Karel Novotny

unread,
May 3, 2010, 2:48:29 PM5/3/10
to opentripp...@googlegroups.com
I have created 3 new tickets for this based on this thread (261-263).

karel

On Sat, 2010-05-01 at 05:15 -0700, Frank wrote:

Marko Burjek

unread,
Mar 20, 2014, 3:43:02 AM3/20/14
to opentripp...@googlegroups.com

Is anyone working on this?

If not I will look into it because I need localization in local deployment.
I will compare JsGettext and Pomo to see which is better. They both support gettext po files. Pomo seems to be more modern jsgettext is 5 years old. I also found Jed and i18next but first seem to only works on node-js I have to look into i18next. Anybody knows any other js gettext library?

I would like to know which branch to branch for this and on what client to work? Openlayers or Leaflet. And is Openlayers abandoned because it doesn't work on master?

I posted something on the tracker on issue #261

Andrew Byrd

unread,
Mar 20, 2014, 7:15:40 AM3/20/14
to opentripp...@googlegroups.com
On 03/20/2014 08:43 AM, Marko Burjek wrote:
> I would like to know which branch to branch for this and on what client
> to work? Openlayers or Leaflet. And is Openlayers abandoned because it
> doesn't work on master?

Thanks for looking into localization.

The OpenLayers client is unlikely to be supported much longer. The
Leaflet client is more commonly used now. Can you explain what you mean
by "doesn't work"?

-Andrew

Andrew Byrd

unread,
Mar 20, 2014, 7:28:15 AM3/20/14
to opentripp...@googlegroups.com
My mistake, I misunderstood you and was concerned that the Leaflet
client was not working right. Yes, the OpenLayers client is on the way
out, and as we make changes to the API in preparation for 1.0 the
OpenLayers client may not keep up in the development branch (master).
Definitely work on the Leaflet client.

-Andrew

Andrew Byrd

unread,
Mar 20, 2014, 8:43:41 AM3/20/14
to Marko Burjek, opentripp...@googlegroups.com
It doesn't have the height graph. We will have to move some of these
features over to the new client.

-Andrew

On 03/20/2014 01:23 PM, Marko Burjek wrote:
> Thanks for information. I'll start working in this week. But will
> Leaflet client got all the functionalit of Openlayers(height graph,
> wheelchair etc..)?
>
>
> 2014-03-20 12:28 GMT+01:00 Andrew Byrd <and...@fastmail.net
> <mailto:and...@fastmail.net>>:
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "OpenTripPlanner Developers" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/__topic/opentripplanner-dev/__KLdzJdmx94k/unsubscribe
> <https://groups.google.com/d/topic/opentripplanner-dev/KLdzJdmx94k/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to
> opentripplanner-...@googlegroups.com
> <mailto:opentripplanner-dev%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/__optout
> <https://groups.google.com/d/optout>.
>
>

Frank P

unread,
Mar 21, 2014, 12:26:36 AM3/21/14
to opentripp...@googlegroups.com
Hey Marko ... feel free to use some .po files I've been building over at https://github.com/OpenTransitTools/view/tree/master/ott/view/locale.  I'm thinking a fair number of the strings I've localized into Spanish will map to strings within the Leaflet client.

BTW, here you can see these localizations work against an OTP backend here:
 - and -

It would benefit me to know that the .po files that I've been using with Babel / Pyramid / Python also work with other libraries like Pomo / JsGettext.  
Reply all
Reply to author
Forward
0 new messages