Skip to content

Commit 85577fd

Browse files
authored
Merge pull request #4608 from EmmanuelMess/emmanuelmess/fix/luri_locale
2 parents 2d0587f + e6b9ada commit 85577fd

4 files changed

Lines changed: 30 additions & 41 deletions

File tree

app/src/main/java/com/amaze/filemanager/utils/ContextLocaleExt.kt

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -67,51 +67,39 @@ fun Context.getLocaleListFromXml(): LocaleListCompat {
6767
* For preference drop down convenience.
6868
*/
6969
fun Context.getLangPreferenceDropdownEntries(): Map<String, Locale> {
70-
val localeList = getLocaleListFromXml()
71-
val currentLocaleList: List<Locale> =
72-
(
73-
if (!AppCompatDelegate.getApplicationLocales().isEmpty) {
74-
AppCompatDelegate.getApplicationLocales()
75-
} else {
76-
LocaleListCompat.getDefault()
77-
}
78-
).let { appLocales ->
79-
ArrayList<Locale>().apply {
80-
for (x in 0 until appLocales.size()) {
81-
appLocales.get(x)?.let {
82-
this.add(it)
83-
}
84-
}
85-
}
70+
val appLocales =
71+
if (AppCompatDelegate.getApplicationLocales().isEmpty) {
72+
LocaleListCompat.getDefault()
73+
} else {
74+
AppCompatDelegate.getApplicationLocales()
8675
}
76+
77+
val currentLocaleList = ArrayList<Locale>()
78+
79+
for (i in 0 until appLocales.size()) {
80+
val appLocale = appLocales.get(i) ?: continue
81+
currentLocaleList.add(appLocale)
82+
}
83+
84+
val xmlLocales = getLocaleListFromXml()
8785
val map = mutableMapOf<String, Locale>()
8886

89-
for (a in 0 until localeList.size()) {
90-
localeList[a].let {
91-
it?.run {
92-
val displayName: String =
93-
if (currentLocaleList.isEmpty()) {
94-
this.getDisplayName(Locale.getDefault())
95-
} else {
96-
this.getDisplayName(
97-
currentLocaleList.first { locale ->
98-
this.getDisplayName(locale).isNotEmpty()
99-
},
100-
)
87+
for (i in 0 until xmlLocales.size()) {
88+
val xmlLocale = xmlLocales[i] ?: continue
89+
val displayName: String =
90+
if (currentLocaleList.isEmpty()) {
91+
xmlLocale.getDisplayName(Locale.getDefault())
92+
} else {
93+
val nameInCurrentLocale =
94+
currentLocaleList.first { locale ->
95+
xmlLocale.getDisplayName(locale).isNotEmpty()
10196
}
102-
map.put(displayName, this)
97+
98+
xmlLocale.getDisplayName(nameInCurrentLocale)
10399
}
104-
}
100+
101+
map[displayName] = xmlLocale
105102
}
106-
return map
107-
}
108103

109-
/**
110-
* [Context] extension to set app locale fluently.
111-
*
112-
* Calls [AppCompatDelegate.setApplicationLocales] under the hood.
113-
*/
114-
fun Context.setLocale(langTag: String) {
115-
val appLocale: LocaleListCompat = LocaleListCompat.forLanguageTags(langTag)
116-
AppCompatDelegate.setApplicationLocales(appLocale)
104+
return map
117105
}
File renamed without changes.

app/src/main/res/xml/locales_config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<locale android:name="bg" />
1111
<locale android:name="bn" />
1212
<locale android:name="bn-BD" />
13-
<locale android:name="bqi-LU" />
13+
<locale android:name="bqi-IR" />
1414
<locale android:name="br-FR" />
1515
<locale android:name="bs-BA" />
1616
<locale android:name="ca" />

transifex.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ settings:
4848
en_IN: en-IN
4949
es_ES: es-rES
5050
es_VE: es-rVE
51+
bqi: bqi-rIR
5152
ms_MY: ms-rMY
5253
bg_BG: bg-rBG
5354
hu: hu-rHU

0 commit comments

Comments
 (0)