整理本地化翻译文件的最佳方法 [英] Best way to organize your localized translation file

查看:151
本文介绍了整理本地化翻译文件的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我开始构建项目时,.po转换文件中将有很多条目.我使用Poedit来构建它们.

As I've started building a project, there will be quite a few entries in the .po translation file. I use Poedit to build these.

我的问题是,此文件中条目的最佳实践是什么?我在想,而不是引用诸如以下条目:

My question is, what is the best practice for entries within this file? I was thinking, instead of referencing entries such as:

echo _('This is an entry.');

我正在考虑像这样组织它们:

I was thinking of organizing them like:

echo _('error_pwd');
echo _('error_user_taken');

浏览翻译文件后,会输出类似以下内容的

Which, once ran through the translation file, would output something like:

Password incorrect. Please try again.
Username is already taken. Please try another.

因此,我的所有翻译都可以按类型进行组织,例如error_msg_status_tip_等.

So, all my translations can be organized by type, such as error_, msg_, status_, tip_, etc.

有人看到过这种方式吗?或者对更井井有条的方法有何建议?

Has anyone seen it done this way, or have any suggestions on a more organized method?

推荐答案

实际上没关系!

这取决于您.

但是,我建议您不要将翻译分成几部分. 这样做没有任何好处.实际上,大多数项目对所有msgid条目都使用一个文件方法. 像django一样,请参见.

However, I advise you do not split translations in sections. No there's any benefit in doing so. Actually, the most projects use the one file approach for all msgid entries. Like django, see.

当然,如果您仍然希望按部分进行翻译,则可能需要查看

Of course, If you still want split translation by sections, might you want take a look on Domains:

来自PHP文档:

此函数(textdomain())设置在调用以下对象时要在其中搜索的域 gettext(),通常以应用程序命名.

This function (textdomain()) sets the domain to search within when calls are made to gettext(), usually the named after an application.

此外,如前所述,将msgid用作真实短语或单词(而不是带下划线或点号的键)时,其优势在于,如果没有可翻译的内容,它将保留为默认消息.

Also, as earlier said, the advantage when using msgid as a real phrase ou word (instead underline or dotted notation key) is that it stays as default message if no there's a translation for entry.

还有一些有用的链接:

  • Django Porject - i18n, Definition
  • PHP textdomain function
  • What is bindtextdomain, textdomain in gettext?
  • How to determine which catalog to be used

这篇关于整理本地化翻译文件的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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