Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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},':';

Alexander

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-10-17 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (97 votes). Check out past polls.

    Notices?