Perl , .po 都是古老的技术。Perl 存在感一直不错,.po 也是易于上手的。
最近做本地化时,发现这方面的内容不多,下面给出实用的代码,希望帮助采用此项技术的同仁能快速了解使用的最佳实践。
use Locale::PO;
......
#load the po file
my $aref = Locale::PO->load_file_asarray($from_file);
foreach my $tpo (@$aref) {
# lines that begin with #~ are obsolete
if ( $tpo->obsolete() || length(trim(Locale::PO->dequote($tpo->msgid())))<1){
...
}else{
#dequote removes the quotes.
my $theEn = Locale::PO->dequote($tpo->msgstr());
if ( length( $theEn) < 1) { #if msgstr is "", use msgid
$theEn = Locale::PO->dequote($tpo->msgid());
}
if( length( $theEn) > 0 ){
...
Encode::_utf8_on($theZh);
$tpo->msgstr($theZh);
}
}
}
#save the po
my $res = Locale::PO->save_file_fromarray($to_file,$aref);
本文分享了使用Perl和.po文件进行软件本地化的实践经验,包括加载和保存.po文件的具体代码,以及如何处理过时的翻译条目。
687

被折叠的 条评论
为什么被折叠?



