简体   繁体   English

使用Java国际化(i18n)修改Wicket的XML资源包

[英]Modify Wicket's XML Resource Bundle with Java internationalization (i18n)

In the resource XML there are all these values associated with keys.I want to modify a value associated with a key directly from Java. 在资源XML中,所有这些与键相关联的值。我想直接从Java修改与键相关联的值。

For instance,I have <entry key="greetingMessage">Welcome to my app</entry> and this is displayed in the view,but also the message can be modified from the view and I want to be automatically updated in the XML. 例如,我有<entry key="greetingMessage">Welcome to my app</entry> ,它显示在视图中,但是消息也可以从视图中修改,我想在XML中自动更新。

I have managed to do this by parsing and changing the XML with javax.xml and org.w3c but I feel I am missing something.Does Java internationalization or Wicket framework have a method to achieve this? 我已经设法通过使用javax.xmlorg.w3c解析和更改XML来做到这一点,但是我感觉缺少了一些东西。Java国际化或Wicket框架是否可以实现这一目标?

Wicket only has facilities to read i18n resources (for example, XmlFilePropertiesLoader ). Wicket仅具有读取i18n资源的功能(例如XmlFilePropertiesLoader )。 Properties.storeToXML() is not used in Wicket 6 code, while Properties.loadFromXML() is used to read those XML properties files. Properties.storeToXML()未在检票6的代码中使用,而Properties.loadFromXML()是用来读取这些XML属性文件。

To store those translations back to XML files you need to be cautious. 要将这些翻译存储回XML文件,您需要谨慎。 At least, synchronization has to be implemented to make sure that simultaneous edits are not lost. 至少必须实现同步,以确保同时进行的编辑不会丢失。

I'd not recommend to store the edits in XML (especially in the original XML files). 我不建议将编辑内容存储为XML(尤其是原始XML文件)。 It seems better to have two levels of properties: 具有两个级别的属性似乎更好:

  1. First, immutable, level, is based on the original (and immutable) XML files. 首先,不可变级别基于原始(且不可变)XML文件。
  2. Second level consisting of 'edits' acts like a patch over the first level. 由“编辑”组成的第二级就像在第一级上的补丁一样。 It may be stored in a database which is much more convenient for storing a constantly updating data (like such edits). 可以将其存储在数据库中,该数据库对于存储不断更新的数据(如此类编辑)更加方便。

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

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