From 2c03f125a9778323c3155b17219f3c6c4ad19fe5 Mon Sep 17 00:00:00 2001 From: Aryan Date: Sun, 12 Apr 2026 17:51:23 +0530 Subject: [PATCH] Converted hardcoded pluralization strings to Android plural resources. (#176) --- .../java/com/aryan/reader/LibraryScreen.kt | 3 +- .../java/com/aryan/reader/MainViewModel.kt | 2 +- .../com/aryan/reader/SharedComposables.kt | 7 +++-- app/src/main/res/values/plurals.xml | 29 +++++++++++++++++++ app/src/main/res/values/strings.xml | 12 ++------ 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/aryan/reader/LibraryScreen.kt b/app/src/main/java/com/aryan/reader/LibraryScreen.kt index 0171375..03e9935 100644 --- a/app/src/main/java/com/aryan/reader/LibraryScreen.kt +++ b/app/src/main/java/com/aryan/reader/LibraryScreen.kt @@ -1515,11 +1515,10 @@ private fun RemoveFromShelfConfirmationDialog( onConfirm: () -> Unit, onDismiss: () -> Unit ) { - val bookStr = pluralStringResource(id = R.plurals.book_word, count) AlertDialog( onDismissRequest = onDismiss, title = { Text(stringResource(R.string.dialog_remove_from_shelf)) }, - text = { Text(stringResource(R.string.dialog_remove_from_shelf_desc, count, bookStr, shelfName)) }, + text = { Text(pluralStringResource(R.plurals.dialog_remove_from_shelf_desc, count, count, shelfName)) }, confirmButton = { TextButton(onClick = onConfirm) { Text(stringResource(R.string.action_remove)) } }, diff --git a/app/src/main/java/com/aryan/reader/MainViewModel.kt b/app/src/main/java/com/aryan/reader/MainViewModel.kt index 7f1a84a..1e9b50b 100644 --- a/app/src/main/java/com/aryan/reader/MainViewModel.kt +++ b/app/src/main/java/com/aryan/reader/MainViewModel.kt @@ -4330,7 +4330,7 @@ open class MainViewModel(application: Application) : AndroidViewModel(applicatio _internalState.update { it.copy( isLoading = false, - bannerMessage = BannerMessage(appContext.getString(R.string.banner_books_removed_library, totalRemoved)) + bannerMessage = BannerMessage(appContext.resources.getQuantityString(R.plurals.banner_books_removed_library, totalRemoved, totalRemoved)) ) } } diff --git a/app/src/main/java/com/aryan/reader/SharedComposables.kt b/app/src/main/java/com/aryan/reader/SharedComposables.kt index 15279a0..0b38143 100644 --- a/app/src/main/java/com/aryan/reader/SharedComposables.kt +++ b/app/src/main/java/com/aryan/reader/SharedComposables.kt @@ -90,6 +90,7 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.platform.UriHandler import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.SpanStyle @@ -295,16 +296,16 @@ fun DeleteConfirmationDialog( isPermanentDelete: Boolean = false, containsFolderItems: Boolean = false ) { - val title = if (isPermanentDelete) stringResource(R.string.dialog_delete_permanently) else stringResource(R.string.dialog_remove_from_recents) + val title = if (isPermanentDelete) pluralStringResource(R.plurals.dialog_delete_permanently, count) else stringResource(R.string.dialog_remove_from_recents) val text = if (isPermanentDelete) { if (containsFolderItems) { stringResource(R.string.dialog_warning_folder_sync_delete) } else { - stringResource(R.string.dialog_permanently_delete_desc, count) + pluralStringResource(R.plurals.dialog_permanently_delete_desc, count, count) } } else { - stringResource(R.string.dialog_remove_recents_desc, count) + pluralStringResource(R.plurals.dialog_remove_recents_desc, count, count) } val confirmText = if (isPermanentDelete) stringResource(R.string.action_delete) else stringResource(R.string.action_remove) diff --git a/app/src/main/res/values/plurals.xml b/app/src/main/res/values/plurals.xml index 8228062..af8b3c3 100644 --- a/app/src/main/res/values/plurals.xml +++ b/app/src/main/res/values/plurals.xml @@ -23,4 +23,33 @@ %1$d result found %1$d results found + + + Delete File Permanently + Delete Files Permanently + + + + + Do you want to permanently delete %1$d selected file from your device? This action cannot be undone. + Do you want to permanently delete %1$d selected files from your device? This action cannot be undone. + + + + + Do you want to remove %1$d selected file from the recent files list? It will reappear if you open it again from the library. + Do you want to remove %1$d selected files from the recent files list? It will reappear if you open it again from the library. + + + + + Are you sure you want to remove %1$d book from the \'%2$s\' shelf? The book will remain in your library and appear under Unshelved. + Are you sure you want to remove %1$d books from the \'%2$s\' shelf? The books will remain in your library and appear under Unshelved. + + + + + %1$d book removed from library. + %1$d books removed from library. + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2255322..98f85cd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -36,13 +36,9 @@ Pin/Unpin Info Select All - Delete File(s) Permanently Remove from Recents Warning: Some selected items are synced from a local folder. Proceeding will delete the actual files from your device storage.\n\nThis action cannot be undone. - - Do you want to permanently delete %1$d selected file(s) from your device? This action cannot be undone. - - Do you want to remove %1$d selected file(s) from the recent files list? It will reappear if you open it again from the library. + File Information Book Name Copy Name @@ -153,8 +149,7 @@ Are you sure you want to delete the \'%1$s\' shelf? All books will be moved to Unshelved. Remove from Shelf? - - Are you sure you want to remove %1$d %2$s from the \'%3$s\' shelf? The book(s) will remain in your library and appear under Unshelved. + Delete %1$s? @@ -508,8 +503,7 @@ Deleting from all devices… Deletion complete. Cloud sync failed, deleted locally. - - %1$d book(s) removed from library. + Reflow cache & generated text views cleared.