Do resource bundles in Java support runtime string substitution?

前端 未结 8 754
夕颜
夕颜 2020-12-25 10:32

Can you do the following with a Java ResourceBundle?

In the properties file...

example.dynamicresource=You currently have {0} accounts.
8条回答
  •  -上瘾入骨i
    2020-12-25 11:19

    I don't think you can make this work for Non-English properties file.

    My message.properties file has the following line:

    info.fomat.log.message.start=Starting to parse log message in {0} format.

    And my message_fr_FR.properties file has the following line:

    info.fomat.log.message.start=A partir d'analyser le message connecter {0} format.

    This code works only for the English one

    String.format((String) messages .getString(GlobalConstants.MESSAGE_FORMAT_START), GlobalConstants.STR_JSON));

    It does NOT replace the placeholder with the value when my language / locale is French :-(

    Even MessageFormat.fomat() is no good

提交回复
热议问题