www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Do multilanguage application

reply bioinfornatics <bioinfornatics gmail.com> writes:
Dear,
I would like to know how do a multilanguage application. It seem it is possible
by using flag -J but they are no document for this feature.
link givent in this page http://www.digitalmars.com/d/2.0/dmd-linux.html seem
to be wrong

if you can do a little example, will be nice

thanks

kind regards
Aug 12 2011
parent reply Jacob Carlborg <doob me.com> writes:
On 2011-08-12 23:02, bioinfornatics wrote:
 Dear,
 I would like to know how do a multilanguage application. It seem it is
possible by using flag -J but they are no document for this feature.
 link givent in this page http://www.digitalmars.com/d/2.0/dmd-linux.html seem
to be wrong

 if you can do a little example, will be nice

 thanks

 kind regards
It's fairly simple. You just need a file containing keys and values. This file can be read either at compile time or runtime. Read the file into an associative array and when you need a piece of text translated just pass the key to a function which retries the corresponding value from the associative array. You could take a look at how internalization is don in Ruby on Rails, this can be applied to D as well: http://guides.rubyonrails.org/i18n.html -- /Jacob Carlborg
Aug 14 2011
parent reply Johannes Pfau <spam example.com> writes:
Jacob Carlborg wrote:
On 2011-08-12 23:02, bioinfornatics wrote:
 Dear,
 I would like to know how do a multilanguage application. It seem it
 is possible by using flag -J but they are no document for this
 feature. link givent in this page
 http://www.digitalmars.com/d/2.0/dmd-linux.html seem to be wrong

 if you can do a little example, will be nice

 thanks

 kind regards
It's fairly simple. You just need a file containing keys and values. This file can be read either at compile time or runtime. Read the file into an associative array and when you need a piece of text translated just pass the key to a function which retries the corresponding value from the associative array.
I think the std.string functions tr, translate, maketrans are meant to do that. But there's a lot more to proper i18n and even for translation a simple key/value table isn't perfect. gettext for example also handles plural forms and context information. (A translation might be different depending on it's context.) Implementing all this stuff can get quite difficult, just have a look at the plural formulas for different languages: http://translate.sourceforge.net/wiki/l10n/pluralforms
You could take a look at how internalization is don in Ruby on Rails, 
this can be applied to D as well:
http://guides.rubyonrails.org/i18n.html
-- Johannes Pfau
Aug 14 2011
parent Sean Kelly <sean invisibleduck.org> writes:
For serious i18n work I'd use ICU. I believe Mango even has a wrapper for so=
me of it.=20

Sent from my iPhone

On Aug 14, 2011, at 8:50 AM, Johannes Pfau <spam example.com> wrote:

 Jacob Carlborg wrote:
 On 2011-08-12 23:02, bioinfornatics wrote:
 Dear,
 I would like to know how do a multilanguage application. It seem it
 is possible by using flag -J but they are no document for this
 feature. link givent in this page
 http://www.digitalmars.com/d/2.0/dmd-linux.html seem to be wrong
=20
 if you can do a little example, will be nice
=20
 thanks
=20
 kind regards
=20 It's fairly simple. You just need a file containing keys and values.=20 This file can be read either at compile time or runtime. Read the file=20=
 into an associative array and when you need a piece of text translated=20=
 just pass the key to a function which retries the corresponding value=20
 from the associative array.
=20 I think the std.string functions tr, translate, maketrans are meant to do that. But there's a lot more to proper i18n and even for translation a simple key/value table isn't perfect. gettext for example also handles plural forms and context information. (A translation might be different depending on it's context.) =20 Implementing all this stuff can get quite difficult, just have a look at the plural formulas for different languages: http://translate.sourceforge.net/wiki/l10n/pluralforms =20
=20
 You could take a look at how internalization is don in Ruby on Rails,=20
 this can be applied to D as well:
 http://guides.rubyonrails.org/i18n.html
=20
=20 =20 --=20 Johannes Pfau =20
Aug 14 2011