I wouldn't do it that way. It looks far to hard to maintain.

I think I wouuld reverse the order of the indexes, $lang first, so you can take a reference to the whole hash of all translations for one language. I do assume that you actually want to use just one language for the output, and this way, you can drop the reference to the language itself throughout the code. Yes, I would use hashes, and string indexes, in order to get something you can read. A bit like:

$translat{English}{red} = 'red'; $translat{English}{blue} = 'blue'; $translat{English}{yellow} = 'yellow'; $translat{Spanish}{red} = 'rojo'; $translat{Spanish}{blue} = 'azul'; $translat{Spanish}{yellow} = 'amarillo';
(but not actually generation it this way), then, in your code, you can do:
$t = $translat{Spanish}; print "The proper word for red is '$t->{red}'\n";
producing:
The proper word for red is 'rojo'
Now, as for maintaining the translations, you could use a spreadsheet-like file, perhaps as a CSV file or tab delimited text. Your people can maintain the translation data even using Excel. Part of the data can look like:

 EnglishSpanishFrench
redredrojorouge
blueblueazulbleu
yellowyellowamarillojaune

The first row is the languages, the first column the hash keys. You might think that it's redundant with the English word, but this is a way to distinguish between synonyms, the hash key doesn't have to be the same as the English word, for example with a word "blue" having more than one meaning, you can use "colour_blue" as the hash key for the colour.

Back to your question... You can combine strings into one hash key, for example "colour_0" for red, "colour_1" for blue, and "colour_2" for yellow, thus you can do your lookup using $t->{"colour_$colour"}. Maintainable and flexible. I like that.

Addendum: Some Perl code to read such a tab delimited text file into a HoH as described:

$_ = <TABLE>; chomp; (undef, my @lang) = split /\t/; while(<TABLE>) { chomp; my($key, @text) = split /\t/; for my $i (0 .. $#lang) { $translat{$lang[$i]}{$key} = $text[$i]; } }
You can do this once, and then save the data with, for example, Storable, or Data::Dumper, so it can be loaded more quickly when in live use. Hmm... the latter can actually produce such a Perl library file as you contemplated to use.

In reply to Re: Do I need an array within an array by bart
in thread Do I need an array within an array by meetn2veg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.