Android localize es-r419

前端 未结 4 1300
情歌与酒
情歌与酒 2021-02-01 21:51

I\'m localizing my app and one of the language/region supported is Espanol-419. Android doesn\'t support the naming convention values-es-r419 but it does accept values-en-rGB.

相关标签:
4条回答
  • 2021-02-01 22:28
    es-r419 = es-rUS. 
    

    change the folder name to values-es-rUS for consistency with runtime user options.

    When using Google Translation services, when you request translation to Spanish for Latin America, you will receive es-r419 folder returned.

    When looking at AOSP source, or in the settings->language and input->language, you will see Spanish and Spanish (United States).

    At runtime, selecting language = Spanish (United States), you will not see strings pulled from values-es-r419, and of course you will see strings pulled from values-es-rUS

    0 讨论(0)
  • 2021-02-01 22:37

    Android 7.0 (API level 24) brings more robust resource resolution, and finds better fallbacks automatically. However, to speed up resolution and improve maintainability, you should store resources in the most common parent dialect. For example, if you were storing Spanish resources in the values-es-rUS directory before, move them into the values-b+es+419 directory, which contains Latin American Spanish.

    Source: https://developer.android.com/guide/topics/resources/multilingual-support.html

    We offered language selection in-app, so to work well on new and old phones we kept duplicate resources in values-es-rUS Español (Estados Unidos) as well as values-b+es+419 Español (Latinoamérica)

    0 讨论(0)
  • 2021-02-01 22:40

    I don't know where r419 comes from. The only thing I could think that it would be is an LCID but 419 is for Russian, or a country code, but there's nothing for 419. Here are a list of locale codes for Spanish, perhaps the one you want is in here:

    es-ar  Spanish - Argentina
    es-bo  Spanish - Bolivia    
    es-cl  Spanish - Chile
    es-co  Spanish - Colombia
    es-cr  Spanish - Costa Rica
    es-do  Spanish - Dominican Republic
    es-ec  Spanish - Ecuador
    es-sv  Spanish - El Salvador
    es-gt  Spanish - Guatemala
    es-hn  Spanish - Honduras
    es-mx  Spanish - Mexico
    es-ni  Spanish - Nicaragua
    es-pa  Spanish - Panama
    es-py  Spanish - Paraguay
    es-pe  Spanish - Peru
    es-pr  Spanish - Puerto Rico
    es-es  Spanish - Spain (Traditional)
    es-uy  Spanish - Uruguay
    es-ve  Spanish - Venezuela
    

    References:

    • Microsoft's LCID table
    • ISO 3166-1
    • ISO 3166-1 Numeric

    Update:

    So apparently 419 is from the UN M.49 standard taken up by BCP 47 for the IETF language tag. Google's documentation on alternative resources says:

    The language is defined by a two-letter ISO 639-1 language code, optionally followed by a two letter ISO 3166-1-alpha-2 region code (preceded by lowercase "r").

    Clearly (by the "r" alone) you can see that these are not standard IETF language tags. Unfortunately, I believe this also means that you won't be able to find a suitable two letter region equivalent to 419. You can also check the official ISO list. It's not on there, there are only two letter tags for countries. Apparently it's very common not to support the 3-digit tags.

    The only solution I can think of is to provide a default set for es and then a more specific set for a subdivision of es countries. You could provide resources for each region (like es-rAR) that you think matches up with 419, but looking at that list, I think it'd be easier to do the opposite and use es to provide resources for Latin American Spanish, and then provide resources for es-rES for Spain. As es-rES is more specific than es, it should take precedence (if the locale matches).

    0 讨论(0)
  • 2021-02-01 22:46

    419 comes from here, and is for any LatinoAmérica (Spanish) regions.

    Español (Colombia), Español (México), etc, will use values-es-r419

    We can also use this for each region instead of names, although it is more difficult

    values-en-r840 intead of values-en-rUS

    But, if we want a language for each region, the file must have the language followed by "-r" and the country code. The name is added automatically when choosing the region.

    To do that, create a "value resource file", choose the "Locale" option and choose the region.

    If the device language is "English (United States)" will take values-en-rUS/strings.xml.

    If the device has a language with a country that we do not support, will use values-en/strings.xml (is used by any region).

    Now, if you want to programmatically add the language, you cannot set the language as "en_US" or "en-rUS" because it doesn't exists, "en_US" is still "en". That's why you need to add the country to the Locale language (android supports upper or lower case)

    //Example language = "en" country = "US"
    private void setLanguage(Context context, String language, String country) {
        Configuration config = new Configuration(context.getResources().getConfiguration());
        config.setLocale(new Locale(language, country));
    
        //Copies the fields from delta into this Configuration object, keeping track of which ones have changed.
        config.updateFrom(new Resources(context.getResources().getAssets(),
                context.getResources().getDisplayMetrics(), config).getConfiguration());
    
        context.createConfigurationContext(config);
    }
    
    0 讨论(0)
提交回复
热议问题