本地化句子

发布于 2024-10-17 17:51:02 字数 446 浏览 4 评论 0原文

我正在使用 gettext 本地化一个 PHP 项目...那部分没问题。问题是,例如,我有这句话“记住密码”。我可以输入下一个代码(使用 gettext): echo _("记住密码")

这将在 PO 文件中生成一行,其中包含“记住密码”键,我将在英文文件中将其翻译为“记住密码” ,并在西班牙网站中将“Recordar 密码”记录在 MO 文件中。

如果将来我想更改该句子并输入英文“永远记住密码”(例如再次)...问题是关键“句子”将与英文翻译不同。

两种可能的情况:

1)所以,如果我想要干净,我可以再次更改密钥,并再次更改 PHP 代码,但这没有用。

2)另一方面,我可以使用通用键,例如“登录页面 - 记住”,它可以用于任何未来略有不同的句子。但这会延长“本地化”的时间,因为它不如添加 _(" 和 ")

你用什么?还有其他第三个选择吗?

感谢您的评论

I'm localizing a PHP project with gettext ... no problem that part. The thing is that, for example, I have this sentence "Remember password". I can put in code the next (to use gettext) : echo _("Remember password")

That will generate a line in PO file with the key "Remember password", and I will translate it in english file to "Remember password", and in spanish site to "Recordar password" in the MO files.

If in the future, I want to change that sentence and put in english "Remember password forever" (for example again) ... the issue is that the key "sentence" will be different than the english translation.

Two possible situations:

1) So, if I want to have this clean, I could change the key again, and change the PHP code again, but that is not useful.

2) In the other hand, I could use a generic key, like "Login Page - Remember", that can be used and serves for any future slightly different sentences. But this extends too much the time of "localizing", since it's not as fast as adding _(" and ")

What do you use ? Any other 3rd option ?

Thank you for your comments

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○闲身 2024-10-24 17:51:02

您几乎已经总结了您拥有的两个选项。请记住,如果您的原始语言中的句子发生了变化,那么它在本地化版本中也可能会发生变化,因此无论如何您都必须触及它的所有出现位置(拼写错误除外,所以不要做任何错误)。

一个好的策略可能是在繁重的开发过程中将主要语言保留在 PHP 文件中,因为它预计会经常更改。一旦应用程序稳定下来,您可以将其提取到 PO 文件中,并用通用占位符替换 PHP 中的字符串。这是否适合您取决于您​​的工作流程和项目的规模。

You pretty much have summed up the two options you have. Keep in mind that if the sentence changes in your original language, it'll probably change in the localized version as well, so you'd have to touch all occurrences of it anyway (except for typos, so don't make any).

A good strategy may be to keep the primary language in the PHP files during heavy development, since it's expected to change often. Once the app settles down somewhat, you can extract it into a PO file and replace the strings in PHP with generic placeholders. Whether this works for you or not depends on your workflow and size of the project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文