Skip to content

Commit

Permalink
Change language code region to ISO 3166-1-alpha-2 region code where n…
Browse files Browse the repository at this point in the history
…eeded
  • Loading branch information
wmontwe committed Jan 24, 2025
1 parent ce09eff commit 92c6116
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
10 changes: 5 additions & 5 deletions app-k9mail/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ android {
"de",
"el",
"en",
"en_GB",
"en-rGB",
"eo",
"es",
"et",
Expand All @@ -66,8 +66,8 @@ android {
"nl",
"nn",
"pl",
"pt_BR",
"pt_PT",
"pt-rBR",
"pt-rPT",
"ro",
"ru",
"sk",
Expand All @@ -78,8 +78,8 @@ android {
"tr",
"uk",
"vi",
"zh_CN",
"zh_TW",
"zh-rCN",
"zh-rTW",
)
}

Expand Down
10 changes: 5 additions & 5 deletions app-thunderbird/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
"de",
"el",
"en",
"en_GB",
"en-rGB",
"eo",
"es",
"et",
Expand All @@ -65,8 +65,8 @@ android {
"nl",
"nn",
"pl",
"pt_BR",
"pt_PT",
"pt-rBR",
"pt-rPT",
"ro",
"ru",
"sl",
Expand All @@ -77,8 +77,8 @@ android {
"tr",
"uk",
"vi",
"zh_CN",
"zh_TW",
"zh-rCN",
"zh-rTW",
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.thunderbird.cli.translation

object AndroidLanguageCodeHelper {

/**
* Fix the language code format to match the Android resource format.
*/
fun fixLanguageCodeFormat(languageCode: String): String {
return if (languageCode.contains("-r")) languageCode.replace("-r", "_") else languageCode
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ class LanguageCodeLoader(
return languages.filter { it.translatedPercent >= threshold }
.map {
languageCodeLookup[it.code] ?: throw IllegalArgumentException("Language code ${it.code} is not mapped")
}.map { fixLanguageCodeFormat(it) }
.sorted()
}

private fun fixLanguageCodeFormat(languageCode: String): String {
return if (languageCode.contains("-r")) languageCode.replace("-r", "_") else languageCode
}.sorted()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package net.thunderbird.cli.translation
class ResourceConfigurationsFormatter {
fun format(languageCodes: List<String>) = buildString {
appendLine("android {")
appendLine(" defaultConfig {")
appendLine(" resourceConfigurations.addAll(")
appendLine(" listOf(")
appendLine(" androidResources {")
appendLine(" // Keep in sync with the resource string array \"supported_languages\"")
appendLine(" localeFilters += listOf(")
languageCodes.forEach { code ->
appendLine(" \"$code\",")
appendLine(" \"$code\",")
}
appendLine(" ),")
appendLine(" )")
appendLine(" }")
appendLine("}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@ class TranslationCli(

override fun run() {
val languageCodes = languageCodeLoader.loadCurrentAndroidLanguageCodes(token, threshold)
val androidLanguageCodes = languageCodes.map { AndroidLanguageCodeHelper.fixLanguageCodeFormat(it) }
val size = languageCodes.size

echo("\nLanguages that are translated above the threshold of ($threshold%): $size")
echo("--------------------------------------------------------------")
echo("For androidResources.localeFilters:")
echo(languageCodes.joinToString(", "))
echo()
echo("For array resource supported_languages:")
echo(androidLanguageCodes.joinToString(", "))
if (printAll) {
echo()
echo("--------------------------------------------------------------")
echo(configurationsFormatter.format(languageCodes))
echo("--------------------------------------------------------------")
echo("--------------------------------------------------------------")
echo(supportedLanguagesFormatter.format(languageCodes))
echo(supportedLanguagesFormatter.format(androidLanguageCodes))
echo("--------------------------------------------------------------")
echo("Please read docs/translating.md for more information on how to update language values.")
echo("--------------------------------------------------------------")
Expand Down

0 comments on commit 92c6116

Please sign in to comment.