Setting application locale to pt_BR programmatically

后端 未结 1 1056
忘掉有多难
忘掉有多难 2020-12-06 11:33

I have an application that has support for the Portuguese language, both for Portugal and Brazil regions. I have created a values-pt (containing the Portugal translation) an

相关标签:
1条回答
  • 2020-12-06 11:55

    I assume you're targeting Android OS > 2.2, because both Portuguese languages are supported by Android starting at version 2.3+.
    I tested it on the emulator, by swapping language & keyboard and having only 1 string different: app_name, so it appeared in application title and it worked just fine.

    The only difference is that I named Portugal region values-pt-rPT insead of values-pt.
    I didn't test on the fly-relocalization, but I guess it works as well.
    I think that when you work with regions, you MUST specify a region for every localization (i.e. fr-rFR for France and fr-rCA for Canada) and can't use the default (pt in your case, or fr in my second example).

    This link illustrates the whole thing more deeply.

    [EDIT]

    When creating a new locale by code, try:

    final Locale myLocale = new Locale("pt", "PT");
    

    and

    final Locale myLocale = new Locale("pt", "BR");
    

    Here's another page from the reference site.

    0 讨论(0)
提交回复
热议问题