Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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 contemplating the Monastery: (9)
As of 2018-08-20 12:34 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (191 votes). Check out past polls.