代码之家  ›  专栏  ›  技术社区  ›  Jigar Joshi

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

  •  0
  • Jigar Joshi  · 技术社区  · 15 年前

    如果我能拥有这样一个逻辑资源包(即位于上下文中而不是物理文件中),那将是最好的。

    相关的:

    How to load a resource bundle from a file resource?

    1 回复  |  直到 4 年前
        1
  •  3
  •   Kevin    15 年前

    ListResourceBundle ? 它提供了一个扩展点,用于添加您自己的 Object[][]

    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
             };
         }
     }
    

    本例返回一个硬编码的列表,但您可以修改该列表以从数据库或其他任何地方返回您想要的任何内容。