我可以动态地加载资源包?我可以动态编辑资源包?

这将是最好的,如果我能有这样的逻辑资源束(即位于上下文没有物理文件)。

相关:

如何从文件加载一个资源包资源?

有帮助吗?

解决方案

您是否能够覆盖 ListResourceBundle的?它提供了一个扩展点,在你自己的资源键对Object[][]加入。

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

此示例返回一个硬编码的房源,但你可以修改返回任何你想要从数据库或其他任何东西。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top