Android localization values-** folder names

后端 未结 3 1460
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 18:56

I have seen several conflicting tables that show localizations and what names they should take

A lot of them suggest that there are versions of the language for each

相关标签:
3条回答
  • 2020-12-15 19:18

    The folder name of Android string files is formatted as the following:

    • without region variant: values-[locale]
    • with region variant: values-[locale]-r[region]
    • For example: values-en, values-en-rGB, values-el-rGR.

    In your case, you just need to create a folder values-el for the Greek translation, and values-el-rGR for the country-specific Greek translation.

    Also, you can make use of the resources fallback mechanism in Android, to allow particular strings to be further translated locally.

    For example, suppose you have a string called “R.string.title” and the locale is ‘el-GR’, Android will look for a value of “R.string.title” by searching the files in the following order:

    • res/values-el-rGR/strings.xml
    • res/values-el/strings.xml
    • res/values/strings.xml

    Therefore, you can just put the country-specific translation inside the res/values-el-rGR/strings.xml, and let the res/values-el/strings.xml stores the general translations.

    It can avoid duplicating your strings in different language files by utilizing this fallback mechanism.

    0 讨论(0)
  • 2020-12-15 19:19

    Right click "res" folder in your project. Pick > New > Android resource file > Localization - and it will offer you all the possible Language and Locales options and even create required folders.

    0 讨论(0)
  • 2020-12-15 19:43

    all can find in https://developer.android.com/index.html

    1. in https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

    the page descript multiple resouce define, like drawable , value

    1. in https://developer.android.com/training/basics/supporting-devices/languages.html

    the page provide Language res define, it‘s import How Create Locale Directories and Resource Files .

    the format is <resource type>-b+<language code>[+<country code>].

    and the language code country code reference https://developer.android.com/reference/java/util/Locale.html

    language ISO 639 alpha-2 or alpha-3 language code, or registered language subtags up to 8 alpha letters (for future enhancements). When a language has both an alpha-2 code and an alpha-3 code, the alpha-2 code must be used. You can find a full list of valid language codes in the IANA Language Subtag Registry (search for "Type: language"). https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry

    country (region) ISO 3166 alpha-2 country code or UN M.49 numeric-3 area code. You can find a full list of valid country and region codes in the IANA Language Subtag Registry (search for "Type: region").

    https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry

    Other reference: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

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