简体   繁体   English

如何在Wicket中访问中央ResourceBundle

[英]How can I access an central ResourceBundle in Wicket

The Internationalization of Wicket is realized with many little Properties-Files in the same folders like there html-Files. Wicket的国际化是通过与html-Files相同的文件夹中的许多小Properties-Files实现的。

My architekture ist one Properties-File in the webapp-Folder or an other unique Folder. 我的架构包括webapp文件夹中的一个Properties-File或另一个唯一的Folder。

My favorite Example: src/java/main/net/kog/WicketApplikation.java: 我最喜欢的示例:src / java / main / net / kog / WicketApplikation.java:

getResourceSettings().getResourceFinders().add(
       new WebApplicationPath(getServletContext(), "resource"));
BundleStringResourceLoader bundle = new BundleStringResourceLoader("text.properties");
getResourceSettings().getStringResourceLoaders().add(bundle);
// Test
String str = bundle.loadStringResource(net.kog.resource.Text.class, "login.noscript", Locale.getDefault(), null, null);
System.out.println(str);

Markup: 标记:

<div wicket:id="login.noscript" id="js"/>

But whereever I locate the File text.properties the ResourceBundle not found, no String was returned. 但是无论我在哪里找到File text.properties,都找不到ResourceBundle,都没有返回字符串。 tried Locations: 尝试过的位置:

  • src/main/webapp src / main / webapp
  • src/main/webapp/resource src / main / webapp / resource
  • src/main/webapp/WEB-INF/resource src / main / webapp / WEB-INF / resource
  • src/main/webapp/WEB-INF/classes/resource src / main / webapp / WEB-INF / classes / resource
  • src/main/resources src / main / resources
  • src/main/resources/resource src / main / resources / resource
  • src/main/resources/net/kog/resource src / main / resources / net / kog / resource

请阅读http://wicket.apache.org/guide/guide/i18n.html ,以获取有关如何在应用程序中拆分或组合资源包的更多信息。

Solution: 解:

  1. First, the answer of martin-g has given the right direktion. 首先,martin-g的答案已被正确地指出。 The properties-File have to be the same name like the Application-class ("WicketApplication.properties"). 属性文件必须与应用程序类(“ WicketApplication.properties”)相同。
  2. Second, very useful was to change the debuglevel in Wicket (src\\main\\resources\\log4j2.xml) from LEVEL.INFO to LEVEL.DEBUG. 其次,非常有用的是将Wicket(src \\ main \\ resources \\ log4j2.xml)中的调试级别从LEVEL.INFO更改为LEVEL.DEBUG。 There was a many Information about the URL (Path) which Wicket has tried to loaded. Wicket尝试加载许多有关URL(路径)的信息。
  3. Third, I make the way to access my properties-File shorter, because I delete IsoPropertiesFilePropertiesLoader (ISO-8859 formated Properties-Files) and XmlFilePropertiesLoader in net.kog.WicketApplication.init(). 第三,我使访问属性文件的方式更短,因为在net.kog.WicketApplication.init()中删除了IsoPropertiesFilePropertiesLoader(ISO-8859格式的Properties-Files)和XmlFilePropertiesLoader。 Code: 码:

     List<IPropertiesLoader> propertiesLoader = ((PropertiesFactory)getResourceSettings().getPropertiesFactory()).getPropertiesLoaders(); getResourceSettings().getPropertiesFactory().clearCache(); propertiesLoader.clear(); propertiesLoader.add(new UtfPropertiesFilePropertiesLoader("properties", "utf-8")); 

The full path of my UTF-8 properties-File is src/main/webapp/net/kog/WicketApplication.properties 我的UTF-8属性文件的完整路径是src / main / webapp / net / kog / WicketApplication.properties

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

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