简体   繁体   English

如何从Java中的DB加载资源包消息?

[英]How to load resource bundle messages from DB in Java?

Can I load a resource bundle dynamically? 我可以动态加载资源包吗? Can I edit a resource bundle dynamically? 我可以动态编辑资源束吗?

It would be best if I can have such a logical resource bundle (ie located in context not as physical file). 最好是可以有这样一个逻辑资源包(即,位于上下文中而不是作为物理文件)。

Related: 有关:

How to load a resource bundle from a file resource? 如何从文件资源加载资源包?

Would you be able to override the ListResourceBundle ? 您可以覆盖ListResourceBundle吗? It provides an extension point for adding in your own Object[][] of resource key pairs. 它提供了一个扩展点,用于添加您自己的资源密钥对的Object[][]

From the javadoc: 从javadoc:

public class MyResources extends ListResourceBundle {
     protected Object[][] getContents() {
         return new Object[][] = {
         // LOCALIZE THIS
             {"s1", "The disk \"{1}\" contains {0}."},  // MessageFormat pattern
             {"s2", "1"},                               // location of {0} in pattern
             {"s3", "My Disk"},                         // sample disk name
             {"s4", "no files"},                        // first ChoiceFormat choice
             {"s5", "one file"},                        // second ChoiceFormat choice
             {"s6", "{0,number} files"},                // third ChoiceFormat choice
             {"s7", "3 Mar 96"},                        // sample date
             {"s8", new Dimension(1,5)}                 // real object, not just string
         // END OF MATERIAL TO LOCALIZE
         };
     }
 }

This example returns a hard coded listing but you can modify that to return whatever you want from a database or anything else. 本示例返回一个硬编码的清单,但是您可以对其进行修改以返回数据库或其他任何想要的东西。

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

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