Skip to content

Commit

Permalink
refactor: Migrate i18n to use Moko Resources (#110)
Browse files Browse the repository at this point in the history
* fix(deps): "String index out of range" compile error

REF: icerockdev/moko-resources#732

* refactor(i18n): Simplify gradle

* refactor: Migrate i18n files to moko-resources

Also split plurals to their own files

* fix: Only use firebase on releases

* revert: Revert "fix: Only use firebase on releases"

This reverts commit e4f40b4.

* ci: Just build standard release

* refactor: Fully migrate to Moko Resources for i18n
  • Loading branch information
null2264 authored Jun 24, 2024
1 parent dc0a3c3 commit 875100d
Show file tree
Hide file tree
Showing 398 changed files with 9,371 additions and 7,388 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/build_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ jobs:
cp .github/runner-files/ci-gradle.properties ~/.gradle/gradle.properties
- name: Build and run tests
if: startsWith(env.VERSION_TAG, 'r') != true && startsWith(env.VERSION_TAG, 'v') != true
run: ./gradlew assembleDevDebug testDevDebugUnitTest assembleStandardRelease
run: ./gradlew assembleStandardRelease testStandardReleaseUnitTest

- name: Publish test report
uses: mikepenz/action-junit-report@v4
Expand All @@ -44,15 +43,6 @@ jobs:
detailed_summary: true
report_paths: '**/build/test-results/test*/TEST-*.xml'

- name: Run tests against release variant
if: startsWith(env.VERSION_TAG, 'r') != true && startsWith(env.VERSION_TAG, 'v') != true
run: ./gradlew testStandardReleaseUnitTest

- name: Upload debug APK to artifact
uses: actions/upload-artifact@v4
with:
path: app/build/outputs/apk/dev/debug/app*-arm64-v8a-*.apk

- name: Upload R8 APK to artifact
uses: actions/upload-artifact@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
*.iml
*/build
*/*/build
.kotlin/
6 changes: 4 additions & 2 deletions app/src/main/java/eu/kanade/tachiyomi/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import yokai.core.di.PreferenceModule
import yokai.core.migration.Migrator
import yokai.core.migration.migrations.migrations
import yokai.domain.base.BasePreferences
import yokai.i18n.MR
import yokai.util.lang.getString
import java.security.Security

open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factory {
Expand Down Expand Up @@ -130,9 +132,9 @@ open class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.F
disableIncognitoReceiver.register()
val nContext = localeContext
val notification = nContext.notification(Notifications.CHANNEL_INCOGNITO_MODE) {
val incogText = nContext.getString(R.string.incognito_mode)
val incogText = nContext.getString(MR.strings.incognito_mode)
setContentTitle(incogText)
setContentText(nContext.getString(R.string.turn_off_, incogText))
setContentText(nContext.getString(MR.strings.turn_off_, incogText))
setSmallIcon(R.drawable.ic_incognito_24dp)
setOngoing(true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import coil3.size.Precision
import coil3.size.Scale
import coil3.transform.RoundedCornersTransformation
import eu.kanade.tachiyomi.R
import yokai.i18n.MR
import yokai.util.lang.getString
import eu.kanade.tachiyomi.appwidget.components.CoverHeight
import eu.kanade.tachiyomi.appwidget.components.CoverWidth
import eu.kanade.tachiyomi.appwidget.components.LockedWidget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.appwidget.components

import android.content.Intent
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.glance.GlanceModifier
Expand All @@ -16,12 +17,14 @@ import androidx.glance.text.TextAlign
import androidx.glance.text.TextStyle
import androidx.glance.unit.ColorProvider
import eu.kanade.tachiyomi.R
import yokai.i18n.MR
import eu.kanade.tachiyomi.appwidget.ContainerModifier
import eu.kanade.tachiyomi.appwidget.util.stringResource
import eu.kanade.tachiyomi.ui.main.MainActivity

@Composable
fun LockedWidget() {
val context = LocalContext.current
val intent = Intent(LocalContext.current, Class.forName(MainActivity.MAIN_ACTIVITY)).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
Expand All @@ -33,9 +36,9 @@ fun LockedWidget() {
contentAlignment = Alignment.Center,
) {
Text(
text = stringResource(R.string.appwidget_unavailable_locked),
text = stringResource(MR.strings.appwidget_unavailable_locked),
style = TextStyle(
color = ColorProvider(R.color.appwidget_on_secondary_container),
color = ColorProvider(Color(context.getColor(R.color.appwidget_on_secondary_container))),
fontSize = 12.sp,
textAlign = TextAlign.Center,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import androidx.glance.layout.ContentScale
import androidx.glance.layout.fillMaxSize
import androidx.glance.layout.size
import eu.kanade.tachiyomi.R
import yokai.i18n.MR
import yokai.util.lang.getString
import eu.kanade.tachiyomi.appwidget.util.appWidgetInnerRadius

val CoverWidth = 58.dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import androidx.glance.layout.fillMaxWidth
import androidx.glance.layout.padding
import androidx.glance.text.Text
import eu.kanade.tachiyomi.R
import yokai.i18n.MR
import yokai.util.lang.getString
import eu.kanade.tachiyomi.appwidget.ContainerModifier
import eu.kanade.tachiyomi.appwidget.util.calculateRowAndColumnCount
import eu.kanade.tachiyomi.appwidget.util.stringResource
Expand All @@ -37,7 +39,7 @@ fun UpdatesWidget(data: List<Pair<Long, Bitmap?>>?) {
if (data == null) {
CircularProgressIndicator()
} else if (data.isEmpty()) {
Text(text = stringResource(R.string.no_recent_read_updated_manga))
Text(text = stringResource(MR.strings.no_recent_read_updated_manga))
} else {
(0 until rowCount).forEach { i ->
val coverRow = (0 until columnCount).mapNotNull { j ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import androidx.compose.ui.unit.DpSize
import androidx.glance.GlanceModifier
import androidx.glance.LocalContext
import androidx.glance.appwidget.cornerRadius
import dev.icerock.moko.resources.StringResource
import eu.kanade.tachiyomi.R
import yokai.util.lang.getString

fun GlanceModifier.appWidgetBackgroundRadius(): GlanceModifier {
return this.cornerRadius(R.dimen.appwidget_background_radius)
Expand All @@ -16,6 +18,11 @@ fun GlanceModifier.appWidgetInnerRadius(): GlanceModifier {
return this.cornerRadius(R.dimen.appwidget_inner_radius)
}

@Composable
fun stringResource(id: StringResource): String {
return LocalContext.current.getString(id)
}

@Composable
fun stringResource(@StringRes id: Int): String {
return LocalContext.current.getString(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package eu.kanade.tachiyomi.core.storage
import android.content.Context
import android.os.Environment
import androidx.core.net.toUri
import eu.kanade.tachiyomi.R
import yokai.i18n.MR
import yokai.util.lang.getString
import java.io.File

class AndroidStorageFolderProvider(
Expand All @@ -13,7 +14,7 @@ class AndroidStorageFolderProvider(
override fun directory(): File {
return File(
Environment.getExternalStorageDirectory().absolutePath + File.separator +
context.getString(R.string.app_normalized_name),
context.getString(MR.strings.app_normalized_name),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package eu.kanade.tachiyomi.data.backup

import android.content.Context
import android.net.Uri
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.util.BackupUtil
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import yokai.i18n.MR
import yokai.util.lang.getString

class BackupFileValidator(
private val sourceManager: SourceManager = Injekt.get(),
Expand All @@ -28,7 +29,7 @@ class BackupFileValidator(
}

if (backup.backupManga.isEmpty()) {
throw IllegalStateException(context.getString(R.string.backup_has_no_manga))
throw IllegalStateException(context.getString(MR.strings.backup_has_no_manga))
}

val sources = backup.backupSources.map { it.sourceId to it.name }.toMap()
Expand Down
24 changes: 13 additions & 11 deletions app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupNotifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.notificationBuilder
import eu.kanade.tachiyomi.util.system.notificationManager
import uy.kohesive.injekt.injectLazy
import yokai.i18n.MR
import yokai.util.lang.getString
import java.io.File
import java.util.concurrent.*

Expand All @@ -38,7 +40,7 @@ class BackupNotifier(private val context: Context) {

fun showBackupProgress() {
val builder = with(progressNotificationBuilder) {
setContentTitle(context.getString(R.string.creating_backup))
setContentTitle(context.getString(MR.strings.creating_backup))

setProgress(0, 0, true)
setOnlyAlertOnce(true)
Expand All @@ -51,7 +53,7 @@ class BackupNotifier(private val context: Context) {
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS)

with(completeNotificationBuilder) {
setContentTitle(context.getString(R.string.backup_failed))
setContentTitle(context.getString(MR.strings.backup_failed))
setContentText(error)

show(Notifications.ID_BACKUP_COMPLETE)
Expand All @@ -62,15 +64,15 @@ class BackupNotifier(private val context: Context) {
context.notificationManager.cancel(Notifications.ID_BACKUP_PROGRESS)

with(completeNotificationBuilder) {
setContentTitle(context.getString(R.string.backup_created))
setContentTitle(context.getString(MR.strings.backup_created))
setContentText(unifile.filePath ?: unifile.name)

// Clear old actions if they exist
clearActions()

addAction(
R.drawable.ic_share_24dp,
context.getString(R.string.share),
context.getString(MR.strings.share),
NotificationReceiver.shareBackupPendingBroadcast(context, unifile.uri, Notifications.ID_BACKUP_COMPLETE),
)

Expand All @@ -80,7 +82,7 @@ class BackupNotifier(private val context: Context) {

fun showRestoreProgress(content: String = "", progress: Int = 0, maxAmount: Int = 100): NotificationCompat.Builder {
val builder = with(progressNotificationBuilder) {
setContentTitle(context.getString(R.string.restoring_backup))
setContentTitle(context.getString(MR.strings.restoring_backup))

if (!preferences.hideNotificationContent().get()) {
setContentText(content)
Expand All @@ -94,7 +96,7 @@ class BackupNotifier(private val context: Context) {

addAction(
R.drawable.ic_close_24dp,
context.getString(R.string.stop),
context.getString(MR.strings.stop),
NotificationReceiver.cancelRestorePendingBroadcast(context, Notifications.ID_RESTORE_PROGRESS),
)
}
Expand All @@ -110,7 +112,7 @@ class BackupNotifier(private val context: Context) {
context.notificationManager.cancel(Notifications.ID_RESTORE_PROGRESS)

with(completeNotificationBuilder) {
setContentTitle(context.getString(R.string.restore_error))
setContentTitle(context.getString(MR.strings.restore_error))
setContentText(error)

show(Notifications.ID_RESTORE_COMPLETE)
Expand All @@ -121,16 +123,16 @@ class BackupNotifier(private val context: Context) {
context.notificationManager.cancel(Notifications.ID_RESTORE_PROGRESS)

val timeString = context.getString(
R.string.restore_duration,
MR.strings.restore_duration,
TimeUnit.MILLISECONDS.toMinutes(time),
TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(
TimeUnit.MILLISECONDS.toMinutes(time),
),
)

with(completeNotificationBuilder) {
setContentTitle(context.getString(R.string.restore_completed))
setContentText(context.resources.getQuantityString(R.plurals.restore_completed_message, errorCount, timeString, errorCount))
setContentTitle(context.getString(MR.strings.restore_completed))
setContentText(context.getString(MR.plurals.restore_completed_message, errorCount, timeString, errorCount))

// Clear old actions if they exist
clearActions()
Expand All @@ -141,7 +143,7 @@ class BackupNotifier(private val context: Context) {

addAction(
R.drawable.ic_eye_24dp,
context.getString(R.string.open_log),
context.getString(MR.strings.open_log),
NotificationReceiver.openErrorOrSkippedLogPendingActivity(context, uri),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.net.Uri
import co.touchlab.kermit.Logger
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.backup.BackupFileValidator
import eu.kanade.tachiyomi.data.backup.create.creators.CategoriesBackupCreator
import eu.kanade.tachiyomi.data.backup.create.creators.MangaBackupCreator
Expand All @@ -22,6 +21,8 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import yokai.domain.storage.StorageManager
import yokai.i18n.MR
import yokai.util.lang.getString
import java.io.FileOutputStream

class BackupCreator(
Expand Down Expand Up @@ -95,7 +96,7 @@ class BackupCreator(

val byteArray = parser.encodeToByteArray(Backup.serializer(), backup!!)
if (byteArray.isEmpty()) {
throw IllegalStateException(context.getString(R.string.empty_backup_error))
throw IllegalStateException(context.getString(MR.strings.empty_backup_error))
}

file.openOutputStream().also {
Expand Down
Loading

0 comments on commit 875100d

Please sign in to comment.