johnfl68 has asked for the wisdom of the Perl Monks concerning the following question:
Hello, looking for advise. I have some stock phrases that need to show up in different languages. Looking for the best means to do this.
Language is set with a variable, and then that is used to select which phrase to use at different places to display. There are only about 20 or so phrases that I need, but I keep adding additional languages.
I started out doing it this way (striped down a bit, but you should get the idea):
my $language = "fr"; # ar, bs, de, en, es, fr, it, nl, pl, pt, ru, sk, sv, tet, tr, + uk, zh if ( $language eq "en" ) { $windTranslation = "Wind:"; $humidityTranslation = "Humidity:"; } if ( $language eq "de" ) { $windTranslation = "Wind:"; $humidityTranslation = "Feuchtigkeit:"; } if ( $language eq "es" ) { $windTranslation = "Viento:"; $humidityTranslation = "Humedad:"; } if ( $language eq "fr" ) { $windTranslation = "Vent:"; $humidityTranslation = "Humidité:"; } if ( $language eq "nl" ) { $windTranslation = "Wind:"; $humidityTranslation = "Vochtigheid:"; }
But maybe it would be better to do it like this, as each phrase set would be together and cleaner code:
my $language = "de"; # ar, bs, de, en, es, fr, it, nl, pl, pt, ru, sk, sv, tet, tr, + uk, zh my %windTranslation = ( 'en' => "Wind:", 'de' => "Wind:", 'es' => "Viento:", 'fr' => "Vent:", 'nl' => "Wind:", ); my %humidityTranslation = ( 'en' => "Humidity:", 'de' => "Feuchtigkeit:", 'es' => "Humedad:", 'fr' => "Humidité:", 'nl' => "Vochtigheid:", ); my $windPhrase = $windTranslation{$language}; my $humidityPhrase = $humidityTranslation{$language};
Or is there maybe a better way, that I am not thinking of?
Please let me know your thoughts?
Thanks!
John
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Translation selection advise
by afoken (Chancellor) on Sep 04, 2015 at 06:11 UTC | |
|
Re: Translation selection advise
by Laurent_R (Canon) on Sep 04, 2015 at 07:23 UTC | |
|
Re: Translation selection advise
by NetWallah (Canon) on Sep 04, 2015 at 02:51 UTC | |
by Anonymous Monk on Sep 04, 2015 at 04:06 UTC | |
|
Re: Translation selection advise
by QuillMeantTen (Friar) on Sep 04, 2015 at 07:44 UTC | |
by Laurent_R (Canon) on Sep 04, 2015 at 08:33 UTC | |
|
Re: Translation selection advise
by johnfl68 (Scribe) on Sep 04, 2015 at 13:13 UTC | |
|
Re: Translation selection advise
by Anonymous Monk on Sep 04, 2015 at 12:20 UTC |