Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Translation selection advise

by afoken (Abbot)
on Sep 04, 2015 at 06:11 UTC ( #1140959=note: print w/replies, xml ) Need Help??

in reply to Translation selection advise

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?

This is at least better than a huge bunch of if-then-else.

NetWallah++ is right, you better use a locale library.

BUT: If you really need just about 20 terms, a library might be overkill. Use a HoH instead:

my %translations=( en => { wind => 'wind', humidity => 'humidity' # ... }, de => { wind => 'Wind', humidity => 'Feuchtigkeit', # ... }, # ... ); print $translations{$language}->{'wind'},':';

Alternatively, you can use the terms as first-level keys and the language as second-level key:

my %translations=( wind => { en => 'wind', de => 'Wind', # ... }, humidity => { en => 'humidity', de => 'Feuchtigkeit', # ... }, # ... ); print $translations{'wind'}->{$language},':';


Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1140959]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-12-13 20:39 GMT
Find Nodes?
    Voting Booth?
    How many stories does it take before you've heard them all?

    Results (62 votes). Check out past polls.