开发者

Mapping textid's to text

开发者 https://www.devze.com 2023-02-15 06:13 出处:网络
I have application written in spring, it communicate with another application, I received objects and now I have to map text id\'s to text in specific (given in object) language.

I have application written in spring, it communicate with another application, I received objects and now I have to map text id's to text in specific (given in object) language.

File with text id's and text looks like:

message.id=message

There is on开发者_C百科e file per language.

I'm looking for solution.


Spring provides some built-in support for internationalization in the form of MessageSources. See 3.13.1 Internationalization using MessageSource.


That's a job for the Java ResouceBundle class.

Basic usage:

ResourceBundle bundle = ResourceBundle.getBundle("path.on.the.classpath", requiredLocale);
String text = bundle.getString(textId);

You should handle MissingResourceExceptions etc. and maybe you even want to cache the bundles like some libraries/webframeworks do.

0

精彩评论

暂无评论...
验证码 换一张
取 消