Should I use java.text.MessageFormat for localised messages without placeholders?

前端 未结 5 2211
北海茫月
北海茫月 2021-02-20 03:55

We are localising the user-interface text for a web application that runs on Java 5, and have a dilemma about how we output messages that are defined in properties files - the k

5条回答
  •  走了就别回头了
    2021-02-20 04:51

    Just write your own implementation of MessageFormat without this annoying feature. You may look at the code of SLF4J Logger.

    They have their own version of message formatter which can be used as followed:

    logger.debug("Temperature set to {}. Old temperature was {}.", t, oldT);
    

    Empty placeholders could be used with default ordering and numbered for some localization cases where different languages do permutations of words or parts of sentences.

提交回复
热议问题