Correct java.util.ResourceBundle Organization

后端 未结 2 1999
灰色年华
灰色年华 2021-01-28 15:43

I have an internationalized project with many modules. Each module has its own set of bundles:

- database-module
    + com_naugler_project_database.properties
           


        
2条回答
  •  無奈伤痛
    2021-01-28 15:55

    As Paweł Dyda indicated, resource bundles on their own do not support class hierarchy resolution. However the Rincl project, which my company just released, should do just what you're looking for---and handle UTF-8 .properties files and XML properties files as well. It even does message formatting for you on the fly.

    As explained in the in the Rincl quick start, you can simply implement Rincled and then call getResources(); Rincl will load your resource bundles even if declared in a parent class or interface:

    public class MyClass extends BaseClass implements Rincled {
      …
    
        final String userName = "Jane Doe";
        //Retrieve the formatted user label based upon the current locale.
        //en-US: "Settings for user Jane Doe."
        //pt-BR: "Definições para usuário Jane Doe."
        final String userLabel = getResources().getString("user-label", userName);
      …
    

    Rincl is available at http://rincl.io/ with an intro and even a full lesson on Java internationalization. There are many new features coming up, but the latest version should already work for you. Let me know if you have any questions or problems.

提交回复
热议问题