Skip to content

Commit cadafbf

Browse files
david-allisonlukstbit
authored andcommitted
refactor(deck-picker): use backend string labels
Assisted-by: Claude Opus 4.7
1 parent 77d9b7b commit cadafbf

13 files changed

Lines changed: 59 additions & 36 deletions

File tree

AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ open class DeckPicker :
10281028
menu.findItem(R.id.action_export_collection)?.title = TR.actionsExport()
10291029
menu.findItem(R.id.action_check_database)?.title = TR.sentenceCase.checkDatabase
10301030
menu.findItem(R.id.action_check_media)?.title = TR.sentenceCase.checkMediaAction
1031+
menu.findItem(R.id.action_deck_delete)?.title = TR.sentenceCase.deleteDeck
10311032
setupMediaSyncMenuItem(menu)
10321033
// redraw menu synchronously to avoid flicker
10331034
updateMenuFromState(menu)
@@ -2148,7 +2149,7 @@ open class DeckPicker :
21482149
shortcut("C") { this.sentenceCase.checkDatabase },
21492150
shortcut("D", R.string.new_deck),
21502151
shortcut("F", R.string.new_dynamic_deck),
2151-
if (fragmented) shortcut("DEL", R.string.contextmenu_deckpicker_delete_deck) else null,
2152+
if (fragmented) shortcut("DEL") { this.sentenceCase.deleteDeck } else null,
21522153
if (fragmented) shortcut("Shift+DEL", R.string.delete_deck_without_confirmation) else null,
21532154
if (fragmented) shortcut("R", R.string.rename_deck) else null,
21542155
shortcut("P", R.string.open_settings),

AnkiDroid/src/main/java/com/ichi2/anki/StudyOptionsFragment.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ class StudyOptionsFragment :
135135
menuInflater: MenuInflater,
136136
) {
137137
menuInflater.inflate(R.menu.study_options_fragment, menu)
138+
menu.findItem(R.id.action_rebuild)?.title = TR.actionsRebuild()
139+
menu.findItem(R.id.action_custom_study)?.title = TR.sentenceCase.customStudy
140+
menu.findItem(R.id.action_unbury)?.title = TR.studyingUnbury()
138141
}
139142

140143
override fun onResume() {

AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckPickerContextMenu.kt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import androidx.annotation.VisibleForTesting
2222
import androidx.appcompat.app.AlertDialog
2323
import androidx.fragment.app.FragmentActivity
2424
import androidx.fragment.app.FragmentManager
25+
import com.ichi2.anki.CollectionManager.TR
2526
import com.ichi2.anki.CollectionManager.withCol
2627
import com.ichi2.anki.R
2728
import com.ichi2.anki.analytics.AnalyticsDialogFragment
2829
import com.ichi2.anki.compat.requireSerializableCompat
2930
import com.ichi2.anki.contextmenu.DeckPickerMenuContentProvider
3031
import com.ichi2.anki.dialogs.DeckPickerContextMenu.DeckPickerContextMenuOption
3132
import com.ichi2.anki.libanki.DeckId
33+
import com.ichi2.anki.ui.internationalization.sentenceCase
3234
import com.ichi2.anki.utils.ext.requireLong
3335
import com.ichi2.anki.utils.ext.setFragmentResultListener
3436
import com.ichi2.utils.title
@@ -80,21 +82,23 @@ class DeckPickerContextMenu : AnalyticsDialogFragment() {
8082
;
8183

8284
fun label(context: Context): String =
83-
when (this) {
84-
RENAME_DECK -> context.getString(R.string.rename_deck)
85-
DECK_OPTIONS -> context.getString(R.string.menu__deck_options)
86-
CUSTOM_STUDY -> context.getString(R.string.custom_study)
87-
DELETE_DECK -> context.getString(R.string.contextmenu_deckpicker_delete_deck)
88-
EXPORT_DECK -> context.getString(R.string.export_deck)
89-
UNBURY -> context.getString(R.string.unbury)
90-
CUSTOM_STUDY_REBUILD -> context.getString(R.string.rebuild_cram_label)
91-
CUSTOM_STUDY_EMPTY -> context.getString(R.string.empty_cram_label)
92-
CREATE_SUBDECK -> context.getString(R.string.create_subdeck)
93-
CREATE_SHORTCUT -> context.getString(R.string.create_shortcut)
94-
BROWSE_CARDS -> context.getString(R.string.browse_cards)
95-
EDIT_DESCRIPTION -> context.getString(R.string.edit_deck_description)
96-
ADD_CARD -> context.getString(R.string.menu_add)
97-
SCHEDULE_REMINDERS -> context.getString(R.string.schedule_reminders_do_not_translate)
85+
with(context) {
86+
when (this@DeckPickerContextMenuOption) {
87+
RENAME_DECK -> TR.sentenceCase.renameDeck
88+
DECK_OPTIONS -> TR.sentenceCase.deckOptions
89+
CUSTOM_STUDY -> TR.sentenceCase.customStudy
90+
DELETE_DECK -> TR.sentenceCase.deleteDeck
91+
EXPORT_DECK -> getString(R.string.export_deck)
92+
UNBURY -> TR.studyingUnbury()
93+
CUSTOM_STUDY_REBUILD -> TR.actionsRebuild()
94+
CUSTOM_STUDY_EMPTY -> getString(R.string.empty_cram_label)
95+
CREATE_SUBDECK -> getString(R.string.create_subdeck)
96+
CREATE_SHORTCUT -> getString(R.string.create_shortcut)
97+
BROWSE_CARDS -> getString(R.string.browse_cards)
98+
EDIT_DESCRIPTION -> getString(R.string.edit_deck_description)
99+
ADD_CARD -> TR.actionsAdd()
100+
SCHEDULE_REMINDERS -> getString(R.string.schedule_reminders_do_not_translate)
101+
}
98102
}
99103
}
100104

AnkiDroid/src/main/java/com/ichi2/anki/ui/internationalization/SentenceCase.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ object SentenceCase {
9494
context(_: Fragment)
9595
val checkMediaAction get() = TR.mediaCheckCheckMediaAction().toSentenceCase(R.string.sentence_check_media)
9696

97+
context(_: Context)
98+
val customStudy get() = TR.actionsCustomStudy().toSentenceCase(R.string.sentence_custom_study)
99+
97100
context(_: Fragment)
98101
val customStudy get() = TR.actionsCustomStudy().toSentenceCase(R.string.sentence_custom_study)
99102

@@ -139,6 +142,15 @@ object SentenceCase {
139142

140143
context(_: Context)
141144
val backTemplate get() = TR.cardTemplatesBackTemplate().toSentenceCase(R.string.sentence_back_template)
145+
146+
context(_: Context)
147+
val renameDeck get() = TR.actionsRenameDeck().toSentenceCase(R.string.sentence_rename_deck)
148+
149+
context(_: Context)
150+
val deckOptions get() = TR.deckConfigTitle().toSentenceCase(R.string.sentence_deck_options)
151+
152+
context(_: Context)
153+
val deleteDeck get() = TR.decksDeleteDeck().toSentenceCase(R.string.sentence_delete_deck)
142154
}
143155

144156
/**

AnkiDroid/src/main/res/menu-xlarge/deck_picker.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<item
2323
android:id="@+id/action_deck_delete"
2424
android:icon="@drawable/ic_delete_white"
25-
android:title="@string/contextmenu_deckpicker_delete_deck"
25+
tools:title="Delete deck"
2626
app:showAsAction="always"/>
2727
<item
2828
android:id="@+id/action_undo"

AnkiDroid/src/main/res/menu/study_options_fragment.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<menu xmlns:android="http://schemas.android.com/apk/res/android"
2-
xmlns:ankidroid="http://schemas.android.com/apk/res-auto">
2+
xmlns:ankidroid="http://schemas.android.com/apk/res-auto"
3+
xmlns:tools="http://schemas.android.com/tools">
34
<item
45
android:id="@+id/action_schedule_reminders"
56
android:title="@string/schedule_reminders_do_not_translate"
@@ -8,7 +9,7 @@
89
ankidroid:showAsAction="always"/>
910
<item
1011
android:id="@+id/action_rebuild"
11-
android:title="@string/rebuild_cram_label"
12+
tools:title="Rebuild"
1213
android:visibility = "gone"
1314
android:icon="@drawable/ic_refresh_white"
1415
ankidroid:showAsAction="ifRoom"/>
@@ -20,7 +21,7 @@
2021
ankidroid:showAsAction="ifRoom"/>
2122
<item
2223
android:id="@+id/action_custom_study"
23-
android:title="@string/custom_study"
24+
tools:title="Custom study"
2425
android:icon="@drawable/ic_build_white"
2526
ankidroid:showAsAction="ifRoom"/>
2627
<!-- the title for the following option will be set dynamically -->
@@ -31,6 +32,6 @@
3132
ankidroid:showAsAction="always"/>
3233
<item
3334
android:id="@+id/action_unbury"
34-
android:title="@string/unbury"
35+
tools:title="Unbury"
3536
android:visibility = "gone"/>
3637
</menu>

AnkiDroid/src/main/res/values/01-core.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
<!-- flashcard_portrait.xml -->
7474
<string name="undo_action_whiteboard_last_stroke" comment="One of the display patterns of 'Undo' item on the action menu in the Study Screen. It is shown as the title of the item when the whiteboard (handwriting) feature is enabled and visible and has any strokes (handwritten lines)" maxLength="28">Undo stroke</string>
7575
<string name="move_all_to_deck">Move all to deck</string>
76-
<string name="unbury" maxLength="28">Unbury</string>
7776
<string name="rename_deck" maxLength="28">Rename deck</string>
7877
<string name="create_shortcut">Create shortcut</string>
7978
<string name="browse_cards">Browse cards</string>
@@ -109,7 +108,6 @@
109108
of the permissions/app info screen will differ between devices. -->
110109
<string name="startup_no_storage_permission">Please grant AnkiDroid the ‘Storage’ permission to continue</string>
111110
<string name="rebuild_filtered_deck">Rebuilding filtered deck…</string>
112-
<string name="rebuild_cram_label" maxLength="28">Rebuild</string>
113111
<string name="empty_cram_label" maxLength="28">Empty</string>
114112
<string name="create_subdeck">Create subdeck</string>
115113
<string name="empty_filtered_deck">Emptying filtered deck…</string>

AnkiDroid/src/main/res/values/02-strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@
187187
<string name="menu__deck_options" maxLength="28">Deck options</string>
188188
<string name="menu__study_options" comment="Menu item that opens options for a Filtered deck (aka Cram deck, aka Custom study)">Study options</string>
189189
<string name="select_tts" maxLength="28">Set TTS language</string>
190-
<string name="custom_study" maxLength="28">Custom study</string>
191190
<string name="dyn_deck_desc">This is a special deck for studying outside of the normal schedule. Cards will be automatically returned to their original decks after you review them. Deleting this deck from the deck list will return all remaining cards to their original deck.</string>
192191
<string name="tag_editor_add_feedback">Touch “%2$s” to confirm adding “%1$s”</string>
193192
<string name="tag_editor_add_feedback_existing">Existing tag “%1$s” selected</string>

AnkiDroid/src/main/res/values/03-dialogs.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
~ this program. If not, see <http://www.gnu.org/licenses/>.
2020
--><resources xmlns:tools="http://schemas.android.com/tools">
2121
<string name="check_db_warning">This may take a long time. Proceed?</string>
22-
<string name="contextmenu_deckpicker_delete_deck" maxLength="28">Delete deck</string>
2322
<string name="delete_deck_title">Delete deck?</string>
2423
<plurals name="delete_deck_message">
2524
<item quantity="one">Delete all cards in %1$s? It contains %2$d card</item>

AnkiDroid/src/main/res/values/sentence-case.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,7 @@ undoActionUndone()
6464
<string name="sentence_check_media">Check media</string>
6565
<string name="sentence_front_template">Front template</string>
6666
<string name="sentence_back_template">Back template</string>
67+
<string name="sentence_rename_deck">Rename deck</string>
68+
<string name="sentence_deck_options">Deck options</string>
69+
<string name="sentence_delete_deck">Delete deck</string>
6770
</resources>

0 commit comments

Comments
 (0)