简体   繁体   English

没有文件系统的Gettext

[英]Gettext without a filesystem

For an embedded system with GUI, we are using our custom translation system. 对于带GUI的嵌入式系统,我们使用自定义翻译系统。 The strings are stored in the code ROM of a microcontroller. 字符串存储在微控制器的代码ROM中。

Currently we have up to 10 languages and about 400 translated strings (varies depending on the product variant). 目前,我们有多达10种语言和大约400个翻译字符串(根据产品型号而有所不同)。

Our current system is rather cumbersome and I believe that gettext would be a better solution. 我们当前的系统相当繁琐,我相信gettext将是一个更好的解决方案。

As far as I understand gettext, it requires the use of bindtextdomain to set the directory containing the compiled translations files (*.mo). 据我所知,gettext需要使用bindtextdomain来设置包含已编译翻译文件(* .mo)的目录。

Is there a way to instead read the translation from memory? 有没有办法从内存中读取翻译? That is I would like to include the compiled *.mo files in the binary, and set up gettext to use these. 那就是我想在二进制文件中包含已编译的* .mo文件,并设置gettext来使用它们。 Alternatively, the translation data would be stored in a data EEPROM without a filesystem. 或者,翻译数据将存储在没有文件系统的数据EEPROM中。

Or can you recommend a different translation system for use in a microcontroller system (16 or 32 bit, 256 to 512 kbyte ROM) with a C interface? 或者你能推荐一个不同的翻译系统用于带C接口的微控制器系统(16或32位,256到512 KB ROM)吗?

Edit: I should add that being able to maintain translations apart from the microcontroller firmware would be a reason to switch to gettext. 编辑:我应该补充说,能够维持除微控制器固件之外的翻译是切换到gettext的原因。 The appropriate translation data would be loaded by the user with a configuration software that we already supply with our systems. 用户将使用我们已经提供给我们系统的配置软件加载适当的翻译数据。

This is what I would do: I would include the binary ".mo" in constant variables in the code. 这就是我要做的:我会在代码中的常量变量中包含二进制“.mo”。 You can write a simple converter from binary to a char array and have that ".mo" file compiled inside your program. 您可以编写一个从二进制到char数组的简单转换器,并在程序中编译“.mo”文件。 You would have an array of ".mo" file data, each with a different language. 您将拥有一组“.mo”文件数据,每个数据都使用不同的语言。

I would modify libintl sourcecode to access one of those arrays. 我会修改libintl源代码来访问其中一个数组。 Check the file loadmsgcat.c, the function _nl_load_domain . 检查文件loadmsgcat.c,函数_nl_load_domain See there how it tries to use mmap() (so it's prepared to have everything in memory). 看看它是如何尝试使用mmap() (因此它准备将所有东西都放在内存中)。 Just add some code there to decide which element of your ".mo" array to use based on the language requested. 只需在那里添加一些代码,根据请求的语言决定使用“.mo”数组的哪个元素。

I haven't tried this, but this is what I would try given your situation. 我没试过这个,但这是我会根据你的情况尝试的。 It doesn't look too hard. 看起来并不太难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM