Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: JetBrains/compose-multiplatform-core
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 113fe26ff1b788b21113a9d287c3887d07cce881
Choose a base ref
..
head repository: JetBrains/compose-multiplatform-core
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c574c9bb95bfe396609a2fbd27346255012ceda5
Choose a head ref
19 changes: 11 additions & 8 deletions buildSrc/src/main/kotlin/UpdateTranslationsTask.kt
Original file line number Diff line number Diff line change
@@ -248,22 +248,25 @@ abstract class UpdateTranslationsTask : DefaultTask() {
it.appendLine()
it.appendLine("""
/**
* Maps each locale tag we have a translation for to a function that creates the translation.
* Returns the translation for the given locale; `null` if there isn't one.
*/
internal val TranslationProviderByLocaleTag = mapOf(
internal fun translationFor(localeTag: String) = when(localeTag) {
""".trimIndent())
for (locale in locales) {
it.appendLine(" \"${locale.toKotlinTag()}\" to " +
"Translations::${locale.translationFunctionName()},")

fun emitTranslationEntry(localeTag: String, locale: Locale) {
it.appendLine(" \"${localeTag}\" -> " +
"Translations.${locale.translationFunctionName()}()")
}
for (locale in locales) {
emitTranslationEntry(locale.toKotlinTag(), locale)
val newLanguageCode = OldToNewLanguageCode[locale.language]
if (newLanguageCode != null) {
val newLocale = locale.copy(language = newLanguageCode)
it.appendLine(" \"${newLocale.toKotlinTag()}\" to " +
"Translations::${locale.translationFunctionName()},")
emitTranslationEntry(newLocale.toKotlinTag(), locale)
}
}
it.appendLine(")")
it.appendLine(" else -> null")
it.appendLine("}")
}
}

Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@

package androidx.compose.material

import androidx.compose.material.l10n.TranslationProviderByLocaleTag
import androidx.compose.material.l10n.en
import androidx.compose.material.l10n.translationFor
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.text.intl.Locale
@@ -73,15 +73,9 @@ private fun localeTagChain(locale: Locale) = sequence {
/**
* Finds a [Translation] for the given locale.
*/
private fun findTranslation(locale: Locale): Translation {
for (tag in localeTagChain(locale)) {
// We don't need to merge translations because each one should contain all the strings.
val translation = TranslationProviderByLocaleTag[tag]?.invoke()
if (translation != null) {
return translation
}
}
error("Root translation must be present")
private fun findTranslation(locale: Locale): Map<Strings, String> {
// We don't need to merge translations because each one should contain all the strings.
return localeTagChain(locale).firstNotNullOf { translationFor(it) }
}

/**
Original file line number Diff line number Diff line change
@@ -19,93 +19,94 @@ package androidx.compose.material.l10n
import androidx.compose.material.Translations

/**
* Maps each locale tag we have a translation for to a function that creates the translation.
* Returns the translation for the given locale; `null` if there isn't one.
*/
internal val TranslationProviderByLocaleTag = mapOf(
"" to Translations::en,
"en_AU" to Translations::enAU,
"en_CA" to Translations::enCA,
"en_GB" to Translations::enGB,
"en_IN" to Translations::enIN,
"af" to Translations::af,
"am" to Translations::am,
"ar" to Translations::ar,
"as" to Translations::`as`,
"az" to Translations::az,
"be" to Translations::be,
"bg" to Translations::bg,
"bn" to Translations::bn,
"bs" to Translations::bs,
"ca" to Translations::ca,
"cs" to Translations::cs,
"da" to Translations::da,
"de" to Translations::de,
"el" to Translations::el,
"es" to Translations::es,
"es_US" to Translations::esUS,
"et" to Translations::et,
"eu" to Translations::eu,
"fa" to Translations::fa,
"fi" to Translations::fi,
"fr" to Translations::fr,
"fr_CA" to Translations::frCA,
"gl" to Translations::gl,
"gu" to Translations::gu,
"hi" to Translations::hi,
"hr" to Translations::hr,
"hu" to Translations::hu,
"hy" to Translations::hy,
"in" to Translations::`in`,
"id" to Translations::`in`,
"is" to Translations::`is`,
"it" to Translations::it,
"iw" to Translations::iw,
"he" to Translations::iw,
"ja" to Translations::ja,
"ka" to Translations::ka,
"kk" to Translations::kk,
"km" to Translations::km,
"kn" to Translations::kn,
"ko" to Translations::ko,
"ky" to Translations::ky,
"lo" to Translations::lo,
"lt" to Translations::lt,
"lv" to Translations::lv,
"mk" to Translations::mk,
"ml" to Translations::ml,
"mn" to Translations::mn,
"mr" to Translations::mr,
"ms" to Translations::ms,
"my" to Translations::my,
"nb" to Translations::nb,
"ne" to Translations::ne,
"nl" to Translations::nl,
"or" to Translations::or,
"pa" to Translations::pa,
"pl" to Translations::pl,
"pt" to Translations::pt,
"pt_BR" to Translations::ptBR,
"pt_PT" to Translations::ptPT,
"ro" to Translations::ro,
"ru" to Translations::ru,
"si" to Translations::si,
"sk" to Translations::sk,
"sl" to Translations::sl,
"sq" to Translations::sq,
"sr" to Translations::sr,
"sv" to Translations::sv,
"sw" to Translations::sw,
"ta" to Translations::ta,
"te" to Translations::te,
"th" to Translations::th,
"tl" to Translations::tl,
"tr" to Translations::tr,
"uk" to Translations::uk,
"ur" to Translations::ur,
"uz" to Translations::uz,
"vi" to Translations::vi,
"zh_CN" to Translations::zhCN,
"zh_HK" to Translations::zhHK,
"zh_TW" to Translations::zhTW,
"zu" to Translations::zu,
)
internal fun translationFor(localeTag: String) = when(localeTag) {
"" -> Translations.en()
"en_AU" -> Translations.enAU()
"en_CA" -> Translations.enCA()
"en_GB" -> Translations.enGB()
"en_IN" -> Translations.enIN()
"af" -> Translations.af()
"am" -> Translations.am()
"ar" -> Translations.ar()
"as" -> Translations.`as`()
"az" -> Translations.az()
"be" -> Translations.be()
"bg" -> Translations.bg()
"bn" -> Translations.bn()
"bs" -> Translations.bs()
"ca" -> Translations.ca()
"cs" -> Translations.cs()
"da" -> Translations.da()
"de" -> Translations.de()
"el" -> Translations.el()
"es" -> Translations.es()
"es_US" -> Translations.esUS()
"et" -> Translations.et()
"eu" -> Translations.eu()
"fa" -> Translations.fa()
"fi" -> Translations.fi()
"fr" -> Translations.fr()
"fr_CA" -> Translations.frCA()
"gl" -> Translations.gl()
"gu" -> Translations.gu()
"hi" -> Translations.hi()
"hr" -> Translations.hr()
"hu" -> Translations.hu()
"hy" -> Translations.hy()
"in" -> Translations.`in`()
"id" -> Translations.`in`()
"is" -> Translations.`is`()
"it" -> Translations.it()
"iw" -> Translations.iw()
"he" -> Translations.iw()
"ja" -> Translations.ja()
"ka" -> Translations.ka()
"kk" -> Translations.kk()
"km" -> Translations.km()
"kn" -> Translations.kn()
"ko" -> Translations.ko()
"ky" -> Translations.ky()
"lo" -> Translations.lo()
"lt" -> Translations.lt()
"lv" -> Translations.lv()
"mk" -> Translations.mk()
"ml" -> Translations.ml()
"mn" -> Translations.mn()
"mr" -> Translations.mr()
"ms" -> Translations.ms()
"my" -> Translations.my()
"nb" -> Translations.nb()
"ne" -> Translations.ne()
"nl" -> Translations.nl()
"or" -> Translations.or()
"pa" -> Translations.pa()
"pl" -> Translations.pl()
"pt" -> Translations.pt()
"pt_BR" -> Translations.ptBR()
"pt_PT" -> Translations.ptPT()
"ro" -> Translations.ro()
"ru" -> Translations.ru()
"si" -> Translations.si()
"sk" -> Translations.sk()
"sl" -> Translations.sl()
"sq" -> Translations.sq()
"sr" -> Translations.sr()
"sv" -> Translations.sv()
"sw" -> Translations.sw()
"ta" -> Translations.ta()
"te" -> Translations.te()
"th" -> Translations.th()
"tl" -> Translations.tl()
"tr" -> Translations.tr()
"uk" -> Translations.uk()
"ur" -> Translations.ur()
"uz" -> Translations.uz()
"vi" -> Translations.vi()
"zh_CN" -> Translations.zhCN()
"zh_HK" -> Translations.zhHK()
"zh_TW" -> Translations.zhTW()
"zu" -> Translations.zu()
else -> null
}
Original file line number Diff line number Diff line change
@@ -20,8 +20,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.text.intl.Locale
import androidx.compose.material3.l10n.TranslationProviderByLocaleTag
import androidx.compose.material3.l10n.en
import androidx.compose.material3.l10n.translationFor
import kotlin.jvm.JvmInline

@Immutable
@@ -159,15 +159,9 @@ private fun localeTagChain(locale: Locale) = sequence {
/**
* Finds a [Translation] for the given locale.
*/
private fun findTranslation(locale: Locale): Translation {
for (tag in localeTagChain(locale)) {
// We don't need to merge translations because each one should contain all the strings.
val translation = TranslationProviderByLocaleTag[tag]?.invoke()
if (translation != null) {
return translation
}
}
error("Root translation must be present")
private fun findTranslation(locale: Locale): Map<Strings, String> {
// We don't need to merge translations because each one should contain all the strings.
return localeTagChain(locale).firstNotNullOf { translationFor(it) }
}

/**
Loading