poedit动态gettext的解决方法

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

我已经开始使用 gettext 来翻译我发送给用户的文本和消息.我正在使用 poedit 作为编辑器,但我正在努力处理动态消息.

I have started using gettext for translating text and messages i send to user. I am using poedit as an editor, but i am struggling with dynamic messages.

例如,我有类似登录之类的东西,其中有一个变量告诉错误类型.

For example i have things like the login where i have a variable that tells the type of error.

$this->translate('page-error-' . $error);

当我从 poedit 自动更新时,它会读取为page-error-".我所做的是有一个文件,我在其中对 translate 方法进行虚拟调用,其中包含所有可能的键,以便在自动更新时将它们添加到我的 poedit 中.

When i auto update from poedit this gets read like "page-error-". What i do is have a file where i place dummy calls to the translate method with all the possible keys to have them added in my poedit when auto updating.

我不是特别喜欢这种情况.你们是怎么做到的.

I don't particularly like this situation. How do you guys do it.

感谢您的想法

推荐答案

不——这是不可能的,因为编辑器(和 gettext 工具)正在读取您的源代码,而不是执行您的程序.您必须自己保留虚拟调用或将密钥添加到翻译文件中.

No -- this is not possible, because the editor (and the gettext tools) are reading your sources, not executing your program. You'll have to keep the dummy calls or add the keys to the translation files yourself.

相关文章