Gettext:消息 ID 是英文文本是个好主意吗?

2022-01-18 00:00:00 internationalization gettext php

我们正准备将我们的 PHP 网站翻译成各种语言,PHP 中的 gettext 支持看起来是可行的方法.

We're getting ready to translate our PHP website into various languages, and the gettext support in PHP looks like the way to go.

我看到的所有教程都建议使用英文文本作为消息 ID,即

All the tutorials I see recommend using the english text as the message ID, i.e.

gettext("你好!")

gettext("Hi there!")

但这真的是个好主意吗?假设营销人员想要将文本更改为Hi there, y'all!".那么您是否不必更新所有语言文件,因为该字符串(实际上是消息 ID)已更改?

But is that really a good idea? Let's say someone in marketing wants to change the text to "Hi there, y'all!". Then don't you have to update all the language files because that string -- which is actually the message ID -- has changed?

拥有某种通用 ID(如hello.message")和英文翻译文件会更好吗?

Is it better to have some kind of generic ID, like "hello.message", and an english translations file?

推荐答案

我使用有意义的 ID,例如welcome_back_1",即welcome back, %1"等等.我总是将英语作为我的基础"语言,所以在最坏的情况下,当特定语言没有消息 ID 时,我会使用英语.

I use meaningful IDs such as "welcome_back_1" which would be "welcome back, %1" etc. I always have English as my "base" language so in the worst case scenario when a specific language doesn't have a message ID, I fall-back on English.

我不喜欢使用实际的英语短语作为消息 ID,因为如果英语发生变化,ID 也会发生变化.如果您使用一些自动化工具,这可能不会对您产生太大影响,但它让我很困扰.我不喜欢使用简单的代码(比如 msg3975),因为它们没有任何意义,所以阅读代码会更加困难,除非你到处乱扔评论​​.

I don't like to use actual English phrases as message ID's because if the English changes so does the ID. This might not affect you much if you use some automated tools, but it bothers me. I don't like to use simple codes (like msg3975) because they don't mean anything, so reading the code is more difficult unless you litter comments everywhere.

相关文章