http://www.perlmonks.org?node_id=1140952
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