I make my Perl apps multilingual too. I have a Dictionary.pm module, which I wrote myself that works something like:

my $dict = new Dictionary(); # Dictionary is made a singleton. $some_string = $dict->trans("word");

My dictionary also has methods like $dict->check_in("word") that changes the meaning of a word if it exists or adds a new one.

Once you have a module you can implement the methods the way you want and you can change them later if you don't like it. I had two options for Dictionary internals when I started working on it:

First. Have XML dictionary files for each language: en_dictionary.xml, lt_dictionary.xml etc. Load the needed in the Dictionary constructor or change it at run-time. The problem with this option was that my app uses a windows-1257 charset and not utf-8. And the XML::Simple and other XML modules work only with utf-8 so far. So I dropped this option.

Second. Have a database table dictionary with fields: word, en, lt for it. The dictionary justs loads the needed field values when needed.

So, my way of doing might have been a reinvention of the wheel. However, my quick research on dictionary modules out there didn't give me good results. Conclusion: write a simple Dictionary wrapper around and choose a way to access your dictionary words inside it. You will be able to change it later when need. In your code you'll have delegation to the dictionary module: $dict->trans("word").

I thought about finishing my module properly and putting it on CPAN. Don't know yet if it's good enough and really needed for Perl community.


In reply to Re: Writing multilingual perl applications? by Heidegger
in thread Writing multilingual perl applications? by skx

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.