mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 21:42:07 +01:00
[core] Correctly handle BCP 42 language tag creation from Locale for xml:lang
Fixes SMACK-952
This commit is contained in:
parent
94375e3208
commit
49379afd3f
1 changed files with 12 additions and 10 deletions
|
@ -544,19 +544,21 @@ public abstract class ConnectionConfiguration {
|
||||||
* Returns the xml:lang string of the stream language to use when connecting to the server.
|
* Returns the xml:lang string of the stream language to use when connecting to the server.
|
||||||
*
|
*
|
||||||
* <p>If the developer sets the language to null, this will also return null, leading to
|
* <p>If the developer sets the language to null, this will also return null, leading to
|
||||||
* the removal of the xml:lang tag from the stream. If a Locale("") is configured, this will
|
* the removal of the xml:lang tag from the stream.</p>
|
||||||
* return "", which can be used as an override.</p>
|
|
||||||
*
|
*
|
||||||
* @return the stream language to use when connecting to the server.
|
* @return the stream language to use when connecting to the server or <code>null</code>.
|
||||||
*/
|
*/
|
||||||
public String getXmlLang() {
|
public String getXmlLang() {
|
||||||
// TODO: Change to Locale.toLanguageTag() once Smack's minimum Android API level is 21 or higher.
|
if (language == null) {
|
||||||
// This will need a workaround for new Locale("").getLanguageTag() returning "und". Expected
|
return null;
|
||||||
// behavior of this function:
|
}
|
||||||
// - returns null if language is null
|
|
||||||
// - returns "" if language.getLanguage() returns the empty string
|
String languageTag = language.toLanguageTag();
|
||||||
// - returns language.toLanguageTag() otherwise
|
if (languageTag.equals("und")) {
|
||||||
return language != null ? language.toString().replace("_", "-") : null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return languageTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue