4

My Java app has been localised into several locales. For each locale there is a properties file with the translations. I load it as follows:

ResourceBundle bundle = ResourceBundle.getBundle("MessagesBundle", Locale.getDefault());

I'd like to determine at runtime all available resource bundles. The bundles are in my application's jar file.

How can I do this?

Steve McLeod
  • 51,737
  • 47
  • 128
  • 184

2 Answers2

1

There is no standard method with ResourceBundle class. You may use (hackish solution) - Thread.currentThread().getContextClassLoader().getResource() method or this.getClass().getResource("/"). Have look at another SO thread having same title.

Community
  • 1
  • 1
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
0

If you use Spring you can try with PathMatchingResourcePatternResolver:

ClassLoader cl = this.getClass().getClassLoader(); 
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
Resource[] resources = resolver.getResources("classpath*:/MessagesBundle.properties") ;
for (Resource resource: resources){
    logger.info(resource.getFilename());
}
mgsCatDev
  • 136
  • 1
  • 1
  • 10