By default, Android has always displayed Serbian in Cyrillic, but since 7.0, users can choose between Cyrillic and Latin script. Apps (mostly from Google) ususally puts the Cyrillic strings in sr and the Latin strings in b+sr+Latn. However, b+sr+Latn is very different from the usual convention of using dashes (e.g. sr-rRS-port).
What does b stand for? What is the syntax, and what more can I specify with this?
It's a BCP 47 language tag. It's starts with b and followed by a language, script, region and variant.
BCP 47 documentation
b+sr+Latn would be Serbian with the Latin script.
b+sr+Latn+RS would be Serbian in Serbia, with the Latin script.
The same can be applied to Azerbaijani:
b+az+Latn – Latin script
b+az+Cyrl – Cyrillic script
b+az+Arab – Arabic script
But you can virtually do any combination possible:
b+ja+Hrkt – Japanese with only Hiragana and Katakana
b+ru+Latn – Russian with the Latin script
b+hu+Hung – Hungarian with the Hungarian Runic script
b+en+Cyrl+US – American English with the Cyrillic script
b+hy+Piqd+DE – German Armenian with the Klingon script
(but support will be very limited)
See also:
ISO 639-3 language list
ISO 15924 script list
ISO 3166-1 alpha-2 country list
The "b+" prefix was supported starting in Android 7.0. Prefixing "b+" to a language tag list tells Android that the remaining tags are BCP 47 language tags.
Other answers correctly mention this document, which defines those tags: https://tools.ietf.org/html/bcp47
However, the use of "b+" is not found in that document. The specific meaning behind "b+" is clarified in the Android docs:
To use a BCP 47 language tag, concatenate b+ and a two-letter ISO
639-1 language code, optionally followed by additional subtags
separated by +.
source: https://developer.android.com/guide/topics/resources/providing-resources
Other reference in code:
A BCP 47 language tag. The BCP-47 tag uses + instead of - as
separators, and has the prefix b+. Therefore, the BCP-47 tag
"zh-Hans-CN" would be written as "b+zh+Hans+CN" instead.
source:
https://android.googlesource.com/platform/tools/base/+/master/sdk-common/src/main/java/com/android/ide/common/resources/configuration/LocaleQualifier.java
Related
I have an issue with Serbian Cyrillic language in my app which have 14 different languages. Russian Cyrillic is working just fine.
For example, if user set the app to work in Serbian language, therefore strings.xml from values-sr should be read. And it does. However, output is in equivalent Latin script.
For example, in strings.xml there is a word:
<string name="Password"><DATA><![CDATA[Лозинка]]></DATA></string>
R.string.Password should display Лозинка but instead it is displaying transliterated word as Lozinka... all characters changed to Latin equivalents.
I have tried this on my Mate 20 Pro device. However, on Android simulator in all software versions is working just fine.
Any idea?
It's a bug specific to some Huawei models. If you set Serbian(Latin) as language in the phone settings, it transliterate all Cyrillic string resources to Latin. It also messes up other Cyrillic languages defined as string resources.
From a question received privately:
I'm currently creating an Android app and one of the requirements is that it supports a second language. I've Googled the language codes but I'm not finding the one that I need; could you tell me if you support the Welsh language, which is a place in the United Kingdom? And if so, what is the country code for it?
That would be on Android’s side, not on the IDE side, to support; the resources are bundled within the APK itself and you should put localised strings in a localised values folder within the res/ folder. For example:
res/
values/ # Default locale (e.g., American English)
values-en-rGB/ # British English
values-it/ # Italian (any country)
In general, localisations on Android are defined as 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). Wales is not an independent country, but is part of Great Britain, and as such there is no ISO code for Wales as a region. But, there is a Welsh language code! So you should be able to localise your app by putting your Welsh strings in the res/values-cy or res/values-cy-rGB. The former will be used on all devices that are set to Cymraeg, regardless of the country they’re set to; the latter is specific to devices in Welsh with the country set to Great Britain. For Welsh, the two things are essentially the same, since there aren’t variations of it outside the UK, but this mechanism can be used for example to differentiate Traditional Chinese (zh-rTW) from simplified Chinese (zh-rCN).
For more details on how localisation works on Android, I recommend referring to the Localisation guide on the Android Developers website: https://developer.android.com/guide/topics/resources/localization
For the list of supported ISO languages and countries, you can refer to the Wikipedia: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for the countries, and https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes for the languages.
android resources folder values. What is the values**-b** option i read about here?
What i want to do is have my app support two different languages, french and spanish. But i had a thought. it would be much more organized if instead of doing strings-es.xml and strings-fr.xml if i could do this:
values-es
|
Strings.xml
values-fr
|
Strings.xml
this way if there is any other things that should be localized they can easily go into the respective folders. Is this possible ?
The synax of -b+ allows you to include the script of the language, for languages that use multiple script like Serbian, whilst the old method don't allow this.
The default format that Android uses (as of 7.1) is as following:
values-sr is Serbian in the Cyrillic script
values-b+sr+Latn is Serbian in the Latin script
It is known as a BCP 47 language tag. BCP 47 documentation
Using '-b' is a newer way of supporting locales. You can support locales using the method you indicate above, but you can also support locales by putting them in directories like this:
values-b+es/strings.xml
values-b+fr/strings.xml
By default, Android has always displayed Serbian in Cyrillic, but since 7.0, users can choose between Cyrillic and Latin script. Apps (mostly from Google) ususally puts the Cyrillic strings in sr and the Latin strings in b+sr+Latn. However, b+sr+Latn is very different from the usual convention of using dashes (e.g. sr-rRS-port).
What does b stand for? What is the syntax, and what more can I specify with this?
It's a BCP 47 language tag. It's starts with b and followed by a language, script, region and variant.
BCP 47 documentation
b+sr+Latn would be Serbian with the Latin script.
b+sr+Latn+RS would be Serbian in Serbia, with the Latin script.
The same can be applied to Azerbaijani:
b+az+Latn – Latin script
b+az+Cyrl – Cyrillic script
b+az+Arab – Arabic script
But you can virtually do any combination possible:
b+ja+Hrkt – Japanese with only Hiragana and Katakana
b+ru+Latn – Russian with the Latin script
b+hu+Hung – Hungarian with the Hungarian Runic script
b+en+Cyrl+US – American English with the Cyrillic script
b+hy+Piqd+DE – German Armenian with the Klingon script
(but support will be very limited)
See also:
ISO 639-3 language list
ISO 15924 script list
ISO 3166-1 alpha-2 country list
The "b+" prefix was supported starting in Android 7.0. Prefixing "b+" to a language tag list tells Android that the remaining tags are BCP 47 language tags.
Other answers correctly mention this document, which defines those tags: https://tools.ietf.org/html/bcp47
However, the use of "b+" is not found in that document. The specific meaning behind "b+" is clarified in the Android docs:
To use a BCP 47 language tag, concatenate b+ and a two-letter ISO
639-1 language code, optionally followed by additional subtags
separated by +.
source: https://developer.android.com/guide/topics/resources/providing-resources
Other reference in code:
A BCP 47 language tag. The BCP-47 tag uses + instead of - as
separators, and has the prefix b+. Therefore, the BCP-47 tag
"zh-Hans-CN" would be written as "b+zh+Hans+CN" instead.
source:
https://android.googlesource.com/platform/tools/base/+/master/sdk-common/src/main/java/com/android/ide/common/resources/configuration/LocaleQualifier.java
What languages are supported by android for localization with their respective values folder name, the best link i could find was http://developer.android.com/reference/java/util/Locale.html
any body can help me with more languages what if we need to support more languages then listed above.
My app uses the following undocumented languages, and they work:
ca Catalan
el Greek
es Spanish
pl Polish
pt Portuguese
ro Romanian
ru Russian
sv Swedish
More generally, it should be the string in the "639-1" column of this table.
I suggest use the list of the ISO 639-1 standard
Virtually any language defined by the Strings representing the language code (as specified by ISO 639-1) and (optionally) country (as defined by Alpha 2 representation of ISO 3166-1). You can specify only the language (i.e. "en") or the language used specifically in one area (i.e. "en","US"). You do not need to use the constants (though convenient) that come with Locale.
// This is to get spanish locale of Spain
Locale spanish = new Locale("es", "ES");
The problem is not only specifying the correct languages, but also assuring that the mobile phone supports literals/formatting for the indicated Locale. I.e. a mobile phone sold in Spain will support "es" and "es_ES", almost surely "en" and "en_US" too and probably "ca_ES", "ba_ES" and "gl_ES". It is not likely that it will support for example "es_AR" or "zh_CN". So I think that the answer to your question is "it depends on the market of your application".