Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: A multilingual solution for PERL CGI web applicationsby kbrannen (Beadle) |
on Jul 18, 2013 at 23:21 UTC ( [id://1045226]=note: print w/replies, xml ) | Need Help?? |
In our product we use a DB to hold the translation tokens. However, if you're going to do it with files, why not just create a hash for each language, use Freeze then write it to store it, and later pull it in and Thaw it? I'd probably create a CGI app to maintain the data, rows for each token, a column for each language, and when saving it, each column is a hash with the row name as the key and that's what's frozen for the real app to use later. Use the same hash for each one so you have the same name (e.g. %tokens). Then your normal app can slurp in the frozen hash by opening the needed language file and it has all the correct token values. Then you can substitute $tokens{msg1} or whatever you need without worrying about the language and off you go. In fact, once you have your tokens in memory and assuming you have a unique pattern for them (e.g. [[msg1]]), it's a matter of doing something like: and you're good to go. No need to manipulate @INC or anything else tricky. That also means that adding new languages is easy. Just create an empty file for the new language in your language dir, your CGI editing app will see it and create a new column of empty cells, then when you've filled it out and save, you'll get a new frozen hash in it's own file. If you want to remove a language, just remove the file.
In Section
Cool Uses for Perl
|
|