Oki, there is code from this page http://www.maxi-tip.cz : views/layouts/main.tt -------------------------------------------------------------------- [% SET langs = { cs = "Čeština" vi = "tiếng Việt" } %] <li id="languages" class="pull-right"><a href="#"><span class="selected-language"> <img src="img/icons/flag_[% session.item('language') %].png" alt="[% session.item('language') %] " /> </span></a> <div> <ul> [% SET pos=0; FOREACH j IN installed_languages.keys. sort %] [% IF langs.item(j) %] <li [% pos == 0 ? 'class="first"' : "" %]><a href="[% uri_for('index') %]?lang=[% j %]" alt="[% j %]"><img alt="[ % j %]" src="img/icons/flag_[% j %].png" /> [% langs.item(j) ? langs.item(j) : j %]</a></li> [% END %] [% SET pos=pos+1; END %] </ul> </div> </li> -------------------------------------------------------------------- There is everything. I use my plugin http://search.cpan.org/~ koceasy/Dancer-Plugin-I18N-0.40/lib/Dancer/Plugin/I18N.pm which make everything. In hash 'SET langs = []' where keyname must be setted as LANG name from this http://cpansearch.perl.org/src/GUIDO/libintl-perl-1.20/ lib/Locale/Util.pm for me is 'cs' for Czech and 'vi' from Vietnamese When you put in any page param such 'lang=vi', plugin automatically switched to this new language if existed translation file for this language. In my Dancer directory must created directory I18N where for me is translated files such as "cs.mo,vi.mo" Next, I make make_i18n.sh script which read every template files or modules and add new text for localization to po files which is archived in directory "I18N/pot/". Must be run form main dancer directory. Now you can open actually 'po' files such as I18N/pot/cs.po and make translation to this and rerun make_i18n.sh repeatably to make translation files "I18N/cs.mo" For translation you must use ASCII letters. In template files I use l() function for this, but you can defined own functions for this via options: plugins: I18N: func: "N_" For using xgettext.pl I must use localize() function in *.pm modules for translation. There is simply and translation which I use has 2 way: 1) translation via function in template such as this code [% l('Sazkova kancelar') %] can change text in l() function to given language or in module is same but for gettext.pl I used 'localize' function such as this code: return localize('Sazkova kancelar') 2) translation big of text blocks in template or module via function language_tag() such as: [% IF language_tag('vi') %] ....some big text in vietnamese.. [% ELSIF language_tag('cs') %] ....some big text in Czech.. [% ELSE %] ..... some big text in native language.... [% END %] make fun and dance Igor This is make_I18N.sh skript ---------------------------------------------------------------------------- #!/bin/bash # Print available locales via : `locale -a` LANGS="cs vi en de" #NOW=$(date +"%Y-%m-%d.%H:%M:%S") NOW=$(date +"%s") DIR="I18N/pot" if [ ! -d $DIR ];then echo "Not existed $DIR" elif [ $# -eq 0 ];then echo "Must put locale names such as parameter (cs,en) " fi rm -f $DIR/*.mo if [ "$1" = "1" ];then for i in $LANGS;do [ -f $DIR/$i.po ] && msgfmt --output-file=I18N/$i.mo $DIR/$i.po done exit fi POT=$DIR/$NOW.pot xgettext.pl -P Locale::Maketext::Extract::Plugin::TT2 -P Locale::Maketext::Extract::Plugin::Perl -w --output=$POT --directory=views/ --directory=lib/ -v for i in $LANGS;do f=$DIR/${i}_$NOW.pot msginit --no-translator --input=$POT --output=$f --locale=$i.utf8 #msgfmt $VERB -o /dev/null -c --statistics $f if [ -f $DIR/$i.po ];then mv $DIR/$i.po $DIR/$i-$NOW.bck msgmerge $VERB -o $DIR/$i.po $DIR/$i-$NOW.bck $f else cp -p $f $DIR/$i.po fi msgfmt --output-file=I18N/$i.mo $DIR/$i.po done # Remove obsolete translations: #for i in *.po; do msgattrib -o $i.no-o --no-obsolete $i && mv $i.no-o $i; done ------------ Původní zpráva ------------ Od: Alex <800@ru07.com> Předmět: Re: [Dancer-users] Website in Dancer Datum: 12.6.2012 13:10:30 --------------------------------------------- Good site! Please, can you show the example of the code in perl dancer where the switch between the Czech and vietnamese languages is realized? Soon I will have to work on a multi-language project, so I want to understand what is the best way to make it.
Hi,
I wrote this website http://www.maxi-tip.cz/ (http://www.maxi-tip.cz/) in Dancer, that use
this Plugins(Database, Email, my localization Plugin-I18N).
For now is localized in Czech or vietnamese.
All of code has about 2.000 lines + code in templates.
This website is 2x fasten when old website writen in PHP.
Bye Igor Bujna
_______________________________________________
Dancer-users mailing list
Dancer-users@perldancer.org(mailto:Dancer-users@perldancer.org)
http://www.backup-manager.org/cgi-bin/listinfo/dancer-users (http://www.backup-manager.org/cgi-bin/listinfo/dancer-users)