使用gettext和.po文件时,将键和全文结合在一起 [英] Combining keys and full text when working with gettext and .po files

查看:123
本文介绍了使用gettext和.po文件时,将键和全文结合在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看 gettext.po文件,用于创建多语言应用程序.我的理解是,在.po文件中,msgid是源文件,而msgstr是翻译文件.因此,我看到了两种定义msgid的方法:

I am looking at gettext and .po files for creating a multilingual application. My understanding is that in the .po file msgid is the source and msgstr is the translation. Accordingly I see 2 ways of defining msgid:

使用全文(例如"My name is %s.\n")具有以下优点:

Using full text (e.g. "My name is %s.\n") with the following advantages:

  • 调用gettext时,您可以清楚地看到即将发生的情况 已翻译
  • 翻译.po文件比较容易,因为它们 包含要翻译的实际内容
  • when calling gettext you can clearly see what is about to be translated
  • it's easier to translate .po files because they contain the actual content to be translated

使用具有以下优点的密钥(例如my-name %s):

Using a key (e.g. my-name %s) with the following advantages:

  • 当源文本较长(例如,有关公司的段落)时,gettext调用会更简洁,从而使您的视图更简洁
  • 易于维护多个.po文件和视图,因为密钥更改的可能性较小(例如company-description的密钥更改的可能性远小于实际公司描述)
  • when the source text is long (e.g. paragraph about company), gettext calls are more concise which makes your views cleaner
  • easier to maintain several .po files and views, because the key is less likely to change (e.g. key of company-description far less likely to change than the actual company description)

因此我的问题:
是否有一种使用gettext.po文件的方法,可以结合使用这两种方法的优点,即:
-gettext呼叫的键用法
译员是否可以查看需要翻译的全文?

Hence my question:
Is there a way of working with gettext and .po files that allows combining the advantages of both methods, that is:
-usage of a keys for gettext calls
-ability for the translator to see the full text that needs to be translated?

推荐答案

我刚刚回答了一个类似的问题(年龄更大)

I just answered a similar (much older) question here.

简短版本:

PO文件格式非常简单,因此可以从另一个工作流程生成PO/MO文件,从而提供您所需要的灵活性. (您的开发人员需要标识符,翻译人员需要单词)

The PO file format is very simple, so it is possible to generate PO/MO files from another workflow that allows the flexibility you're asking for. (your devs want identifiers, your translators want words)

您可以自己推出此解决方案,也可以使用基于云的应用程序(例如 Loco )来管理翻译和导出当开发人员需要时,带有标识符的Gettext文件.

You could roll this solution yourself, or use a cloud-based app like Loco to manage your translations and export a Gettext file with identifiers when your devs need them.

这篇关于使用gettext和.po文件时,将键和全文结合在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆