How to do an app with truly multilingual strings?

前端 未结 4 1948
渐次进展
渐次进展 2021-02-03 14:34

what should be the best approach to make strings for different languages? I have this problem, I am trying to display strings such as \'month\', \'months\', \'year\', \'years\'.

4条回答
  •  执笔经年
    2021-02-03 15:01

    Sounds like you want a ChoiceFormat, or at least using one through a MessageFormat:

    public static void main(String... args) {
        String[] formats = { 
            // NOTE - In a real app, you'd fetch the format strings from a language,
            // file, not hard-code them in your program. Obviously.
            "{0,number} {0,choice,0#years|1#year|1

    In your program, you would of course get the format string from your string file.

提交回复
热议问题