我需要一些正则表达式来分割PO(语言翻译文件)文件的翻译计数、模糊计数和总字符串计数。
我的程序使用的是PHP,我到处找,但没有找到。
请帮助我。
最佳答案
gettext PO 文件非常古老且无处不在,它们是事实上的行业标准,并得到各种工具的大力支持。当您可以使用众多 PO 文件解析器之一时,尝试在此处使用 regexen 重新发明解决方案似乎非常不合适。例如oscarotero/Gettext :
$translations = Gettext\Extractors\Po::extract('messages.po');
$total = $translated = $fuzzy = 0;
foreach ($translations as $translation) {
$total++;
if (!$translation->hasTranslation()) {
$untranslated++;
}
if (in_array('fuzzy', $translation->getComments())) {
$fuzzy++;
}
}
(未经测试,但应该立即工作或稍作更改。)
事实上,已经有工具可以做到这一点:Translate Toolkit或Pology ,据我所知:
$ pocount locale/ko/LC_MESSAGES/
data/locale/ko/LC_MESSAGES/messages.po
type strings words (source) words (translation)
translated: 3 ( 0%) 7 ( 0%) 28
fuzzy: 0 ( 0%) 0 ( 0%) n/a
untranslated: 729 ( 99%) 1065 ( 99%) n/a
Total: 732 1072 28
unreviewed: 3 ( 0%) 7 ( 0%) 28
empty: 729 ( 99%) 1065 ( 99%) 0
$ posieve stats locale/ko/
- msg msg/tot w-or w/tot-or w-tr ch-or ch-tr
translated 3 0.4% 15 0.9% 26 93 114
fuzzy 0 0.0% 0 0.0% 0 0 0
untranslated 729 99.6% 1708 99.1% 0 17323 0
total 732 - 1723 - 26 17416 114
obsolete 0 - 0 - 0 0 0
关于php - 使用正则表达式从 po 文件获取翻译计数和模糊计数...,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21300860/