从i18n资源包中生成干净代码的任何库?

时间:2022-10-20 19:04:58

In my project I would like to have compile time checks on my existing resource bundle. I already have a set of *.properties localized files and I'm about to hook them up to some i18n tool. I was thinking about regular ResourceBundles, but I don't like the fact, that this mechanism does not guarantee any kind of checks, neither compile-time or maintenance checks like - finding duplicates or finding unused keys.

在我的项目中,我希望对现有的资源包进行编译时间检查。我已经有一组* .properties本地化文件,我将把它们连接到一些i18n工具。我正在考虑常规的ResourceBundles,但我不喜欢这样的事实,即这种机制不保证任何类型的检查,无论是编译时还是维护检查,例如 - 查找重复项或查找未使用的密钥。

So, I'm looking for a library, which would take my existing *.properties files and converted them into neat and clean Java code, which I could use in my project.

所以,我正在寻找一个库,它将我现有的* .properties文件转换成干净利落的Java代码,我可以在我的项目中使用它。

The best possible outcome would be to have a mechanism similar to GWT i18n support. One, clean interface with all messages as a separate methods.

最好的结果是建立类似于GWT i18n支持的机制。一个,干净的界面,所有消息作为单独的方法。

I have looked at jlibs and ForgeRock. I really like jlibs, but it's not a separate lib, so it's hard for me to imagine introducing so huge lib dependency just for i18n. ForgeRock does pretty much what I would like, but it produces constants rather than clean interfaces to work with, like jlibs does.

我看过jlibs和ForgeRock。我真的很喜欢jlibs,但它不是一个单独的lib,所以我很难想象只为i18n引入如此巨大的lib依赖。 ForgeRock几乎完全符合我的要求,但是它产生常量而不是干净的接口,就像jlibs一样。

This entry blog is also helpful in understanding which approach I would like to use. I made a big research regarding available i18n tools, I just cannot find 'that one', which would suit my needs the best.

此入门博客也有助于了解我想使用哪种方法。我对可用的i18n工具进行了大量的研究,我找不到那个最符合我需求的“那个”。

Regards.

问候。

4 个解决方案

#1


0  

I am currently working exactly on the kind of library you are looking for, check it out. It's still work in progress, but I should be having my first release fairly soon.

我目前正在寻找您正在寻找的那种库,请查看它。它仍然在进行中,但我应该很快就会发布我的第一个版本。

The first release will just contain support for annotation based translations. I don't yet have any ideas on how to migrate existing projects into c10n style, though. Any ideas, suggestions are always welcome!

第一个版本将仅包含对基于注释的翻译的支持。但是,我对如何将现有项目迁移到c10n样式还没有任何想法。任何想法,建议总是欢迎!

#2


1  

Another library satisfying your requirements of code generation would be i18n-binder.

满足您的代码生成要求的另一个库将是i18n-binder。

Personally, I would approach this problem from another angle, using the gettext framework you would mark translatable strings in the source code and generate the resource bundles from them. There are tools and editors that can then update the translations based on the extracted strings, and detect no longer used or modified strings.

就个人而言,我会从另一个角度处理这个问题,使用gettext框架,你可以在源代码中标记可翻译的字符串,并从中生成资源包。有工具和编辑器可以根据提取的字符串更新翻译,并检测不再使用或修改的字符串。

#3


0  

To solve this problem I implemented a Message Compiler, which creates the resource bundle files and constant definitions as Java enum for the keys from one single source file. So the constants can be used in the Java source code, which is a much safer way. The message compiler cannot only be used for Java. It creates also resource files and constants for Objective-C or Swift and can be extended for other Programming environments.

为了解决这个问题,我实现了一个Message Compiler,它为一个源文件中的键创建资源包文件和常量定义作为Java enum。因此常量可以在Java源代码中使用,这是一种更安全的方式。消息编译器不仅可以用于Java。它还为Objective-C或Swift创建资源文件和常量,并可以扩展到其他编程环境。

#4


-1  

I like JUnit. Not exactly what you are looking for, but by creating tests you are sure that all the items in de propertyfiles are available.

我喜欢JUnit。不完全是您正在寻找的,但通过创建测试,您可以确保de propertyfiles中的所有项目都可用。

#1


0  

I am currently working exactly on the kind of library you are looking for, check it out. It's still work in progress, but I should be having my first release fairly soon.

我目前正在寻找您正在寻找的那种库,请查看它。它仍然在进行中,但我应该很快就会发布我的第一个版本。

The first release will just contain support for annotation based translations. I don't yet have any ideas on how to migrate existing projects into c10n style, though. Any ideas, suggestions are always welcome!

第一个版本将仅包含对基于注释的翻译的支持。但是,我对如何将现有项目迁移到c10n样式还没有任何想法。任何想法,建议总是欢迎!

#2


1  

Another library satisfying your requirements of code generation would be i18n-binder.

满足您的代码生成要求的另一个库将是i18n-binder。

Personally, I would approach this problem from another angle, using the gettext framework you would mark translatable strings in the source code and generate the resource bundles from them. There are tools and editors that can then update the translations based on the extracted strings, and detect no longer used or modified strings.

就个人而言,我会从另一个角度处理这个问题,使用gettext框架,你可以在源代码中标记可翻译的字符串,并从中生成资源包。有工具和编辑器可以根据提取的字符串更新翻译,并检测不再使用或修改的字符串。

#3


0  

To solve this problem I implemented a Message Compiler, which creates the resource bundle files and constant definitions as Java enum for the keys from one single source file. So the constants can be used in the Java source code, which is a much safer way. The message compiler cannot only be used for Java. It creates also resource files and constants for Objective-C or Swift and can be extended for other Programming environments.

为了解决这个问题,我实现了一个Message Compiler,它为一个源文件中的键创建资源包文件和常量定义作为Java enum。因此常量可以在Java源代码中使用,这是一种更安全的方式。消息编译器不仅可以用于Java。它还为Objective-C或Swift创建资源文件和常量,并可以扩展到其他编程环境。

#4


-1  

I like JUnit. Not exactly what you are looking for, but by creating tests you are sure that all the items in de propertyfiles are available.

我喜欢JUnit。不完全是您正在寻找的,但通过创建测试,您可以确保de propertyfiles中的所有项目都可用。