英文:
How to localize TwinCAT PLC project's string literals?
问题
您可以轻松地通过将翻译添加到文本列表,然后编辑表格来翻译TwinCAT PLC的可视化界面。不幸的是,似乎无法用同样的方式处理嵌入在PLC代码中的字符串文字。例如,具有嵌入式描述的格式化错误消息,如零件计数、位置等等。至少我无法弄清楚如何从PLC代码中访问文本列表。
我遇到了项目本地化,起初看起来很有希望。您可以生成标准的gettext .pot模板,然后使用Poedit或其他工具进行翻译。然后,您可以切换语言,整个项目就被翻译了。不幸的是,这显然只是一种外观上的改变,对执行没有任何影响,变量仍然包含未翻译的字符串。甚至在翻译后也无法登录。
我只是不知道如何正确使用文本列表和/或项目本地化,还是它们真的像它们看起来的那样不完善?
英文:
You can easily translate TwinCAT PLC's visualizations by just adding a translation to a text list and then editing the table. Unfortunately, this doesn't seem to work for string literals embedded in PLC code. For instance, formatted error messages with embedded descriptions like part counts, locations etc. At least I couldn't figure out how to access text lists from the PLC code.
I ran into project localizations which looked promising at first. You can generate standard gettext .pot templates and translate them with Poedit or whatever. You can then switch the language and voila, the whole project is translated. Unfortunately, this is apparently just a cosmetic change which doesn't affect the execution at all and variables still contain untranslated strings. You can't even login while translated.
Do I just not know how to properly use text lists and/or project localizations or are they really as half-baked as they seem?
答案1
得分: 1
显然,我不了解你的用例,但在我的项目中,“如何本地化TwinCAT PLC项目的字符串文字?”的答案是你不需要,因为代码中没有包含自然语言的字符串文字。
人类阅读的文本位于表示层。表示层可以接收某种标识符(错误代码,错误对象路径),然后可以用它来检索适当表示语言中的文本元素(PLC对此一无所知)。如果有额外的数据,它被传递为结构化数据(由表示层读取),而不是由PLC预先准备的字符串。
英文:
Obviously, I do not know your use case, but in my projects the answer to "How to localize TwinCAT PLC project's string literals?" is that you don't because there are no string literals containing natural language in the code.
Text intended to be read by humans resides at the presentation layer. The presentation layer can receive some kind of identifier (error code, error object path) that can then be used to retrieve a text element in the appropriate presentation language (which the PLC knows nothing about). If there is additional data, it is conveyed as structured data (read by the presentation layer), not as strings already prepared by the PLC.
答案2
得分: 0
如Fred所提到的,这不应该出现在您的PLC代码中,而应该出现在您的HMI/演示层。有关如何在您的HMI中创建本地化文本的示例可以在InfoSys上找到。
英文:
As mentioned by Fred, that shouldn't be something in your PLC code. Instead, it should be in your HMI/presentation layer. An example on how to create localized texts in your HMI is on InfoSys.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论