From 49379afd3f5801bb85c4c97027d4af5e968cc237 Mon Sep 17 00:00:00 2001
From: Florian Schmaus 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
- * return "", which can be used as an override.
null
.
*/
public String getXmlLang() {
- // TODO: Change to Locale.toLanguageTag() once Smack's minimum Android API level is 21 or higher.
- // This will need a workaround for new Locale("").getLanguageTag() returning "und". Expected
- // behavior of this function:
- // - returns null if language is null
- // - returns "" if language.getLanguage() returns the empty string
- // - returns language.toLanguageTag() otherwise
- return language != null ? language.toString().replace("_", "-") : null;
+ if (language == null) {
+ return null;
+ }
+
+ String languageTag = language.toLanguageTag();
+ if (languageTag.equals("und")) {
+ return null;
+ }
+
+ return languageTag;
}
/**