Perl 操作 .po 文件 示例代码

本文分享了使用Perl和.po文件进行软件本地化的实践经验,包括加载和保存.po文件的具体代码,以及如何处理过时的翻译条目。

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);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值