mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-19 04:16:27 -04:00
parent 219f9752f5ce3d40ae109a35bc7d32fd55d868c6
author Hritik Wadhwa <akkywadhwa@gmail.com> 1584491357 +0530 committer Hritik Wadhwa <akkywadhwa@gmail.com> 1584532410 +0530
This commit is contained in:
parent
219f9752f5
commit
db02ca43c1
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Kiwix Android
|
* Kiwix Android
|
||||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
@ -15,46 +15,44 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.kiwix.kiwixmobile.core.utils;
|
package org.kiwix.kiwixmobile.core.utils
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap
|
||||||
import java.util.Locale;
|
import java.util.Locale
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mhutti1 on 19/04/17.
|
* Created by mhutti1 on 19/04/17.
|
||||||
*/
|
*/
|
||||||
|
class BookUtils {
|
||||||
public class BookUtils {
|
val localeMap: Map<String, Locale>
|
||||||
|
|
||||||
public final Map<String, Locale> localeMap;
|
|
||||||
|
|
||||||
// Create a map of ISO 369-2 language codes
|
// Create a map of ISO 369-2 language codes
|
||||||
public BookUtils() {
|
init {
|
||||||
String[] languages = Locale.getISOLanguages();
|
val languages = Locale.getISOLanguages()
|
||||||
localeMap = new HashMap<>(languages.length);
|
localeMap = HashMap(languages.size)
|
||||||
for (String language : languages) {
|
languages
|
||||||
Locale locale = new Locale(language);
|
.asSequence()
|
||||||
localeMap.put(locale.getISO3Language(), locale);
|
.map(::Locale)
|
||||||
}
|
.forEach { localeMap.put(it.isO3Language, it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the language from the language codes of the parsed xml stream
|
// Get the language from the language codes of the parsed xml stream
|
||||||
public String getLanguage(String languageCode) {
|
fun getLanguage(languageCode: String?): String {
|
||||||
|
var language = ""
|
||||||
if (languageCode == null) {
|
if (languageCode == null) {
|
||||||
return "";
|
language = ""
|
||||||
}
|
} else {
|
||||||
|
if (languageCode.length == 2)
|
||||||
if (languageCode.length() == 2) {
|
language = LanguageContainer(languageCode).languageName
|
||||||
return new LanguageContainer(languageCode).getLanguageName();
|
else if (languageCode.length == LANGUAGE_CODE_LENGTH_THREE) {
|
||||||
} else if (languageCode.length() == 3) {
|
val locale = localeMap[languageCode]
|
||||||
try {
|
language = locale?.displayLanguage.toString()
|
||||||
return localeMap.get(languageCode).getDisplayLanguage();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return language
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val LANGUAGE_CODE_LENGTH_THREE = 3
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user