Skip to content

Commit

Permalink
Merge pull request #2843 from dimagi/2795-custom-translations-for-rep…
Browse files Browse the repository at this point in the history
…eat-group

Added support for translations to fetch from server for repeat group …
  • Loading branch information
devanshhooda authored Sep 30, 2024
2 parents 5a0578a + 6b935e7 commit 68d2504
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/assets/locales/android_translatable_strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,8 @@ repeat.dialog.go.back=Go Back
repeat.dialog.leave=Do Not Add
repeat.dialog.exit=Do Not Add. I'm Finished.
repeat.dialog.add=Add Group
repeat.dialog.add.another=Add another "${0}" group?
repeat.dialog.add.new=Add a new "${0}" group?
repeat.dialog.add.another=Add another ${0}?
repeat.dialog.add.new=Add a new ${0}?
lookup.table.missing.error=Unable to find lookup table "${0}". Make sure it exists and this user has access to it.

ethiopian_months=Mäskäräm,T’ïk’ïmt,Hïdar,Tahsas,T’ïr,Yäkatit,Mägabit,Miyaziya,Gïnbot,Säne,Hämle,Nähäse,P’agume
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.commcare.androidTests

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand Down Expand Up @@ -44,15 +45,16 @@ class DialogTests: BaseTest() {
onView(withId(R.id.nav_btn_next))
.perform(click())

withText("Add a new \"Error on add\" group?").isDisplayed()
onView(withId(R.id.choice_dialog_panel_2)).check(matches(withText("Add a new Error on add?")))

InstrumentationUtility.rotateLeft()
//TODO Expect dialog to not persist due to a activity lifecycle bug in our dialog framework.
withText("Add a new \"Error on add\" group?").doesNotExist()
withText(R.id.choice_dialog_panel_2).doesNotExist()

InstrumentationUtility.rotatePortrait()
onView(withId(R.id.nav_btn_next))
.perform(click())
onView(withText("ADD GROUP"))
onView(withId(R.id.choice_dialog_panel_2))
.perform(click())

checkDialogExistence_withRotation("Error Occurred")
Expand Down
18 changes: 10 additions & 8 deletions app/src/org/commcare/activities/FormEntryActivityUIController.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.javarosa.core.model.data.InvalidData;
import org.javarosa.core.services.Logger;
import org.javarosa.core.services.locale.Localization;
import org.javarosa.form.api.FormEntryCaption;
import org.javarosa.form.api.FormEntryController;
import org.javarosa.form.api.FormEntryPrompt;
import org.javarosa.xpath.XPathException;
Expand Down Expand Up @@ -493,24 +494,25 @@ private void createRepeatDialog() {
final boolean backExitsForm = !details.relevantBeforeCurrentScreen;
final boolean nextExitsForm = details.relevantAfterCurrentScreen == 0;

final FormEntryCaption repeatCaptionPrompt = FormEntryActivity.mFormController.getCaptionPrompt();

// Assign title and text strings based on the current state
String backText = Localization.get("repeat.dialog.go.back");
String addAnotherText = Localization.get("repeat.dialog.add");
String title, skipText;

boolean hasRepetitions = FormEntryActivity.mFormController.getLastRepeatCount() > 0;
final String addAnotherText = repeatCaptionPrompt.getRepeatText(hasRepetitions ? "add" : "add-empty");

String skipText;

if (!nextExitsForm) {
skipText = Localization.get("repeat.dialog.leave");
} else {
skipText = Localization.get("repeat.dialog.exit");
}
if (FormEntryActivity.mFormController.getLastRepeatCount() > 0) {
title = Localization.get("repeat.dialog.add.another", FormEntryActivity.mFormController.getLastGroupText());
} else {
title = Localization.get("repeat.dialog.add.new", FormEntryActivity.mFormController.getLastGroupText());
}

// Create the choice dialog
ContextThemeWrapper wrapper = new ContextThemeWrapper(activity, R.style.DialogBaseTheme);
final PaneledChoiceDialog dialog = new HorizontalPaneledChoiceDialog(wrapper, title);
final PaneledChoiceDialog dialog = new HorizontalPaneledChoiceDialog(wrapper, addAnotherText);

// Panel 1: Back option
View.OnClickListener backListener = v -> {
Expand Down

0 comments on commit 68d2504

Please sign in to comment.