In Java how do I find out what languages I have available my Resource Bundle

后端 未结 4 2027
梦如初夏
梦如初夏 2021-01-01 11:26

I have some resource bundles packaged in my main jar

widget_en.properties
widget_de.properties

I retrieve a resource bundle based on my de

4条回答
  •  [愿得一人]
    2021-01-01 11:47

    A solve it by listing files.

    public class JavaApplication1 {
    
        public static final ArrayList LOCALES = new ArrayList<>();
    
        static {
            try {
                File f = new File(JavaApplication1.class.getResource("/l10n").toURI());
                final String bundle = "widget_";// Bundle name prefix.
                for (String s : f.list(new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        return name.startsWith(bundle);
                    }
                })) {
                    LOCALES.add(s.substring(bundle.length(), s.indexOf('.')));
                }
            } catch (URISyntaxException x) {
                throw new RuntimeException(x);
            }
            LOCALES.trimToSize();
        }
    
        ...
    
    }
    

提交回复
热议问题