Migrate to multiplatform string resources (#10147)

* Migrate to multiplatform string resources

* Move plurals translations into separate files

* Fix lint check on generated files
This commit is contained in:
arkon
2023-11-18 13:54:56 -05:00
committed by GitHub
parent c39ae21f4a
commit 46e734fc8e
340 changed files with 5741 additions and 6292 deletions
@@ -1,7 +1,9 @@
package eu.kanade.tachiyomi.util.lang
import android.content.Context
import eu.kanade.tachiyomi.R
import tachiyomi.core.i18n.localize
import tachiyomi.core.i18n.localizePlural
import tachiyomi.i18n.MR
import java.text.DateFormat
import java.time.Instant
import java.time.LocalDateTime
@@ -61,9 +63,9 @@ fun Date.toRelativeString(
val days = difference.floorDiv(MILLISECONDS_IN_DAY).toInt()
return when {
difference < 0 -> dateFormat.format(this)
difference < MILLISECONDS_IN_DAY -> context.getString(R.string.relative_time_today)
difference < MILLISECONDS_IN_DAY.times(7) -> context.resources.getQuantityString(
R.plurals.relative_time,
difference < MILLISECONDS_IN_DAY -> context.localize(MR.strings.relative_time_today)
difference < MILLISECONDS_IN_DAY.times(7) -> context.localizePlural(
MR.plurals.relative_time,
days,
days,
)
@@ -10,8 +10,9 @@ import androidx.biometric.auth.AuthPromptCallback
import androidx.biometric.auth.startClass2BiometricOrCredentialAuthentication
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import eu.kanade.tachiyomi.R
import kotlinx.coroutines.suspendCancellableCoroutine
import tachiyomi.core.i18n.localize
import tachiyomi.i18n.MR
import kotlin.coroutines.resume
object AuthenticatorUtil {
@@ -48,7 +49,7 @@ object AuthenticatorUtil {
suspend fun FragmentActivity.authenticate(
title: String,
subtitle: String? = getString(R.string.confirm_lock_change),
subtitle: String? = localize(MR.strings.confirm_lock_change),
): Boolean = suspendCancellableCoroutine { cont ->
if (!isAuthenticationSupported()) {
cont.resume(true)
@@ -24,7 +24,9 @@ import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.util.lang.truncateCenter
import logcat.LogPriority
import rikka.sui.Sui
import tachiyomi.core.i18n.localize
import tachiyomi.core.util.system.logcat
import tachiyomi.i18n.MR
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.io.File
@@ -45,11 +47,11 @@ fun Context.copyToClipboard(label: String, content: String) {
// Android 13 and higher shows a visual confirmation of copied contents
// https://developer.android.com/about/versions/13/features/copy-paste
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
toast(getString(R.string.copied_to_clipboard, content.truncateCenter(50)))
toast(localize(MR.strings.copied_to_clipboard, content.truncateCenter(50)))
}
} catch (e: Throwable) {
logcat(LogPriority.ERROR, e)
toast(R.string.clipboard_copy_error)
toast(MR.strings.clipboard_copy_error)
}
}
@@ -6,7 +6,8 @@ import android.content.Intent
import android.net.Uri
import android.os.Build
import androidx.core.content.IntentCompat
import eu.kanade.tachiyomi.R
import tachiyomi.core.i18n.localize
import tachiyomi.i18n.MR
import java.io.Serializable
fun Uri.toShareIntent(context: Context, type: String = "image/*", message: String? = null): Intent {
@@ -27,7 +28,7 @@ fun Uri.toShareIntent(context: Context, type: String = "image/*", message: Strin
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
}
return Intent.createChooser(shareIntent, context.getString(R.string.action_share)).apply {
return Intent.createChooser(shareIntent, context.localize(MR.strings.action_share)).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
}
@@ -2,8 +2,9 @@ package eu.kanade.tachiyomi.util.system
import android.content.Context
import androidx.core.os.LocaleListCompat
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.browse.source.SourcesScreenModel
import tachiyomi.core.i18n.localize
import tachiyomi.i18n.MR
import java.util.Locale
/**
@@ -29,10 +30,10 @@ object LocaleHelper {
*/
fun getSourceDisplayName(lang: String?, context: Context): String {
return when (lang) {
SourcesScreenModel.LAST_USED_KEY -> context.getString(R.string.last_used_source)
SourcesScreenModel.PINNED_KEY -> context.getString(R.string.pinned_sources)
"other" -> context.getString(R.string.other_source)
"all" -> context.getString(R.string.multi_lang)
SourcesScreenModel.LAST_USED_KEY -> context.localize(MR.strings.last_used_source)
SourcesScreenModel.PINNED_KEY -> context.localize(MR.strings.pinned_sources)
"other" -> context.localize(MR.strings.other_source)
"all" -> context.localize(MR.strings.multi_lang)
else -> getDisplayName(lang)
}
}