Skip to content

Commit

Permalink
Merge pull request #33976 from dimagi/rc/continue-button-translation
Browse files Browse the repository at this point in the history
Continue/select button translation
  • Loading branch information
Robert-Costello committed Jan 24, 2024
2 parents 3a03969 + c88e880 commit 5ca35c6
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 5 deletions.
6 changes: 6 additions & 0 deletions corehq/apps/app_manager/app_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ def _create_module_details_app_strings(module, langs):
clean_trans(module.case_details.short.no_items_text, langs)
)

if module.get_app().supports_select_text and hasattr(module, 'case_details'):
yield (
id_strings.select_text_detail(module),
clean_trans(module.case_details.short.select_text, langs)
)

for detail_type, detail, _ in module.get_details():
for column in detail.get_columns():
yield (
Expand Down
7 changes: 7 additions & 0 deletions corehq/apps/app_manager/feature_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ def supports_empty_case_list_text(self):
and self._require_minimum_version('2.54')
)

@property
def supports_select_text(self):
"""
Ability to configure select button text through bulk translations
"""
return self._require_minimum_version('2.54')

@property
def supports_menu_instances(self):
return self._require_minimum_version('2.54')
Expand Down
5 changes: 5 additions & 0 deletions corehq/apps/app_manager/id_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ def no_items_text_detail(module):
return detail(module, 'no_items_text')


@pattern('m%d_select_text')
def select_text_detail(module):
return detail(module, 'select_text')


def fixture_detail(module):
return detail(module, 'fixture_select')

Expand Down
2 changes: 2 additions & 0 deletions corehq/apps/app_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,8 @@ class Detail(IndexedSchema, CaseListLookupMixin):
#Only applies to 'short' details
no_items_text = LabelProperty(default={'en': 'List is empty.'})

select_text = LabelProperty(default={'en': 'Continue'})

def get_instance_name(self, module):
value_is_the_default = self.instance_name == 'casedb'
if value_is_the_default:
Expand Down
2 changes: 2 additions & 0 deletions corehq/apps/app_manager/suite_xml/features/case_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def build_case_tile_detail(self):

DetailContributor.add_no_items_text_to_detail(detail, self.app, self.detail_type, self.module)

DetailContributor.add_select_text_to_detail(detail, self.app, self.detail_type, self.module)

if self.module.has_grouped_tiles():
detail.tile_group = TileGroup(
function=f"string(./index/{self.detail.case_tile_group.index_identifier})",
Expand Down
7 changes: 7 additions & 0 deletions corehq/apps/app_manager/suite_xml/sections/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ def build_detail(self, module, detail_type, detail, detail_column_infos, tabs=No
id
)) is not None:
d.actions.append(case_search_action)
# Add select text
self.add_select_text_to_detail(d, self.app, detail_type, module)

try:
if not self.app.enable_multi_sort:
Expand Down Expand Up @@ -553,6 +555,11 @@ def add_no_items_text_to_detail(detail, app, detail_type, module):
if detail_type.endswith('short') and app.supports_empty_case_list_text:
detail.no_items_text = Text(locale_id=id_strings.no_items_text_detail(module))

@staticmethod
def add_select_text_to_detail(detail, app, detail_type, module):
if detail_type.endswith('short') and app.supports_select_text:
detail.select_text = Text(locale_id=id_strings.select_text_detail(module))


class DetailsHelper(object):

Expand Down
1 change: 1 addition & 0 deletions corehq/apps/app_manager/suite_xml/xml_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ class Detail(OrderedXmlObject, IdNode):
fields = NodeListField('field', Field)
actions = NodeListField('action', Action)
details = NodeListField('detail', "self")
select_text = NodeField('select_text/text', Text)
_variables = NodeField('variables', DetailVariableList)
relevant = StringField('@relevant')
tile_group = NodeField('group', TileGroup)
Expand Down
6 changes: 5 additions & 1 deletion corehq/apps/app_manager/tests/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ def form_opens_case(form, case_type=None, is_subcase=False, parent_tag=None, is_
if not parent_tag:
parent_tag = form.actions.load_update_cases[-1].case_tag

action.case_indices = [CaseIndex(tag=parent_tag, relationship='extension' if is_extension else 'child')]
action.case_indices = [CaseIndex(
tag=parent_tag,
relationship='extension' if is_extension else 'child'
)]

form.actions.open_cases.append(action)

Expand Down Expand Up @@ -234,6 +237,7 @@ def case_claim_app_factory(cls):
case_module.search_config.description = {
'en': 'More information',
}

case_module.search_config.properties = [CaseSearchProperty(
name='name',
label={'en': 'Name of Mother'}
Expand Down
18 changes: 18 additions & 0 deletions corehq/apps/app_manager/tests/test_app_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,21 @@ def test_form_submit_label(self):
self.assertEqual(default_strings['forms.m0f0.submit_label'], form.submit_label['en'])
self.assertEqual(default_strings['forms.m0f0.submit_notification_label'],
form.submit_notification_label['en'])

def test_select_text_app_strings(self):
factory = AppFactory(build_version='2.54.0')
factory.app.langs = ['en', 'fra']
factory.app.build_profiles = OrderedDict({
'en': BuildProfile(langs=['en'], name='en-profile'),
'fra': BuildProfile(langs=['fra'], name='fra-profile'),
})
module, form = factory.new_basic_module('my_module', 'cases')
module.case_details.short.select_text = {'en': 'Continue with case', 'fra': 'Continuer avec le cas'}

app = Application.wrap(factory.app.to_json())

en_app_strings = self._generate_app_strings(app, 'default', build_profile_id='en')
self.assertEqual(en_app_strings['m0_select_text'], 'Continue with case')

es_app_strings = self._generate_app_strings(app, 'fra', build_profile_id='fra')
self.assertEqual(es_app_strings['m0_select_text'], 'Continuer avec le cas')
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ hqDefine("cloudcare/js/formplayer/menus/collections", function () {
'groupHeaderRows',
'queryResponse',
'endpointActions',
'selectText',
],

commandProperties: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ hqDefine("cloudcare/js/formplayer/menus/views", function () {
self.styles = options.styles;
self.hasNoItems = options.collection.length === 0 || options.triggerEmptyCaseList;
self.noItemsText = options.triggerEmptyCaseList ? sidebarNoItemsText : this.options.collection.noItemsText;
self.selectText = options.collection.selectText;
self.headers = options.triggerEmptyCaseList ? [] : this.options.headers;
self.redoLast = options.redoLast;
if (sessionStorage.selectedValues !== undefined) {
Expand Down Expand Up @@ -979,6 +980,7 @@ hqDefine("cloudcare/js/formplayer/menus/views", function () {
return _.extend(paginateItems, {
title: title.trim(),
description: description === undefined ? "" : markdown.render(description.trim()),
selectText: this.selectText === undefined ? "" : this.selectText,
headers: this.headers,
widthHints: this.options.widthHints,
actions: this.options.actions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% load i18n %}
<button type="button" class="btn btn-success btn-lg formplayer-request multi-select-continue-btn" disabled="true">
{% trans "Continue" %}
<% if (selectText && selectText.length > 0) { %>
<%- selectText %>
<% } else { %>
{% trans "Continue" %}
<% } %>
<span id="multi-select-btn-text" class="badge">
<%- selectedCaseIds.length %>
</span>
Expand Down
11 changes: 11 additions & 0 deletions corehq/apps/translations/app_translations/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def get_case_search_rows(langs, module, domain):
def get_module_detail_rows(langs, module):
rows = []
rows += _get_module_detail_no_items_text(langs, module)
rows += _get_module_detail_select_text(langs, module)
for list_or_detail, detail in [
("list", module.case_details.short),
("detail", module.case_details.long)
Expand All @@ -263,6 +264,16 @@ def _get_module_detail_no_items_text(langs, module):
]


def _get_module_detail_select_text(langs, module):
app = module.get_app()
short_detail = module.case_details.short
if not (app.supports_select_text):
return []
return [
("select_text", "list") + tuple(short_detail.select_text.get(lang, '') for lang in langs)
]


def get_module_detail_tabs_rows(langs, detail, list_or_detail):
return [
("Tab {}".format(index), list_or_detail) + tuple(tab.header.get(lang, "") for lang in langs)
Expand Down
7 changes: 7 additions & 0 deletions corehq/apps/translations/app_translations/upload_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, app, sheet_name, unique_id=None, lang=None):
self.search_again_label = None
self.title_label = None
self.description = None
self.select_text = None
self.tab_headers = None
self.no_items_text = None

Expand Down Expand Up @@ -100,6 +101,9 @@ def update(self, rows):
if self.description:
self._update_translation(self.description, self.module.search_config.description)

if self.select_text:
self._update_translation(self.select_text, self.module.case_details.short.select_text)

if self.no_items_text:
self._update_translation(self.no_items_text, self.module.case_details.short.no_items_text)

Expand Down Expand Up @@ -208,6 +212,7 @@ def _get_condensed_rows(self, rows):
self.search_again_label = None
self.title_label = None
self.description = None
self.select_text = None
self.no_items_text = None
self.tab_headers = [None for i in self.module.case_details.long.tabs]
index_of_last_enum_in_condensed = -1
Expand Down Expand Up @@ -268,6 +273,8 @@ def _get_condensed_rows(self, rows):
self.title_label = row
elif row['case_property'] == 'description':
self.description = row
elif row['case_property'] == 'select_text':
self.select_text = row

# It's the empty case list text. Don't add it to condensed rows
elif row['case_property'] == 'no_items_text':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"admin_password": null,
"build_spec": {
"doc_type": "BuildSpec",
"version": "2.13.0",
"version": "2.54.0",
"build_number": null,
"latest": true
},
Expand Down Expand Up @@ -2105,6 +2105,7 @@
"lookup_field_header": {},
"custom_variables": null,
"pull_down_tile": null,
"select_text": {"en": "Continue with Case(s)"},
"columns": [
{
"doc_type": "DetailColumn",
Expand Down
23 changes: 21 additions & 2 deletions corehq/apps/translations/tests/test_bulk_app_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
('menu1',
(('case_list_menu_item_label', 'list', 'Steth List'),
('no_items_text', 'list', 'Empty List'),
('select_text', 'list', 'Continue'),
('name', 'list', 'Name'),
('name', 'detail', 'Name'))),
('menu1_form1',
Expand All @@ -98,13 +99,18 @@
'and "bad" &lt; xml.', '', '', ''),
('submit_label', 'Submit', '', '', ''),
('submit_notification_label', '', '', '', ''))),
('menu2', (('no_items_text', 'list', 'List is empty.'), ('name', 'list', 'Name'), ('name', 'detail', 'Name'))),
('menu2',
(('no_items_text', 'list', 'List is empty.'),
('select_text', 'list', 'Continue'),
('name', 'list', 'Name'),
('name', 'detail', 'Name'))),
('menu2_form1',
(('name_of_series-label', 'Name of series', '', '', ''),
('submit_label', 'Submit', '', '', ''),
('submit_notification_label', '', '', '', ''))),
('menu3',
(('no_items_text', 'list', 'List is empty.'),
('select_text', 'list', 'Continue'),
('name', 'list', 'Name'),
('Tab 0', 'detail', 'Name'),
('Tab 1', 'detail', 'Graph'),
Expand All @@ -123,6 +129,7 @@
('submit_notification_label', '', '', '', ''))),
('menu4',
(('no_items_text', 'list', 'List is empty.'),
('select_text', 'list', 'Continue'),
('x', 'list', 'X'),
('y', 'list', 'Y'),
('x (ID Mapping Text)', 'detail', 'X Name'),
Expand All @@ -137,7 +144,11 @@
('submit_label', 'Submit', '', '', ''),
('submit_notification_label', '', '', '', ''))),
('menu5', ()),
('menu6', (('no_items_text', 'list', 'List is empty.'), ('name', 'list', 'Name'), ('name', 'detail', 'Name'))),
('menu6',
(('no_items_text', 'list', 'List is empty.'),
('select_text', 'list', 'Continue with Case(s)'),
('name', 'list', 'Name'),
('name', 'detail', 'Name'))),
('menu6_form1',
(('this_form_does_nothing-label', 'This form does nothing.', '', '', ''),
('submit_label', 'Submit', '', '', ''),
Expand Down Expand Up @@ -361,6 +372,7 @@ class BulkAppTranslationBasicTest(BulkAppTranslationTestBaseWithApp):
("search_again_label", "list", "Find Another Mother", "Mère! Encore!"),
("title_label", "list", "Find a Mom", "Maman!"),
("description", "list", "More information", "Plus d'information"),
("select_text", "list", "Continue with case", "Continuer avec le cas"),
("no_items_text", "list", "Empty List", "Lista Vacía"),
("name", "list", "Name", "Nom"),
("Tab 0", "detail", "Name", "Nom"),
Expand Down Expand Up @@ -418,6 +430,7 @@ class BulkAppTranslationBasicTest(BulkAppTranslationTestBaseWithApp):
("menu1", "search_again_label", "list", "", "Find Another Mother", "", "", "", ""),
("menu1", "title_label", "list", "Find a Mom", "Maman!", "", "", "", ""),
("menu1", "description", "list", "More information", "Plus d'information", "", "", "", ""),
("menu1", "select_text", "list", "Continue with case", "Continuer avec le cas", "", "", "", ""),
("menu1", "no_items_text", "list", "Empty List", "Lista Vacía", "", "", "", ""),
("menu1", "name", "list", "", "Name", "", "", "", ""),
("menu1", "Tab 0", "detail", "", "Name", "", "", "", ""),
Expand Down Expand Up @@ -1141,6 +1154,7 @@ def test_module_case_search_rows(self):
def test_module_detail_rows(self):
self.assertListEqual(get_module_detail_rows(self.app.langs, self.app.modules[0]), [
('no_items_text', 'list', 'Empty List'),
('select_text', 'list', 'Continue'),
('name', 'list', 'Name'),
('name', 'detail', 'Name'),
])
Expand Down Expand Up @@ -1226,6 +1240,7 @@ def test_bulk_app_single_sheet_rows(self):
['menu1', '', '', '', 'Stethoscope', 'jr://file/commcare/image/module0.png', None, '',
'58ce5c9cf6eda401526973773ef216e7980bc6cc'],
['menu1', 'case_list_menu_item_label', 'list', '', 'Steth List', '', '', '', ''],
['menu1', 'select_text', 'list', '', 'Continue', '', '', '', ''],
['menu1', 'name', 'list', '', 'Name', '', '', '', ''],
['menu1', 'name', 'detail', '', 'Name', '', '', '', ''],

Expand All @@ -1241,6 +1256,7 @@ def test_bulk_app_single_sheet_rows(self):
['menu1_form1', '', '', 'submit_notification_label', '', '', '', '', ''],

['menu2', '', '', '', 'Register Series', '', '', '', 'b9c25abe21054632a3623199debd7cfa'],
['menu2', 'select_text', 'list', '', 'Continue', '', '', '', ''],
['menu2', 'name', 'list', '', 'Name', '', '', '', ''],
['menu2', 'name', 'detail', '', 'Name', '', '', '', ''],

Expand All @@ -1250,6 +1266,7 @@ def test_bulk_app_single_sheet_rows(self):
['menu2_form1', '', '', 'submit_notification_label', '', '', '', '', ''],

['menu3', '', '', '', 'Followup Series', '', '', '', '217e1c8de3dd46f98c7d2806bc19b580'],
['menu3', 'select_text', 'list', '', 'Continue', '', '', '', ''],
['menu3', 'name', 'list', '', 'Name', '', '', '', ''],
['menu3', 'Tab 0', 'detail', '', 'Name', '', '', '', ''],
['menu3', 'Tab 1', 'detail', '', 'Graph', '', '', '', ''],
Expand All @@ -1269,6 +1286,7 @@ def test_bulk_app_single_sheet_rows(self):
['menu3_form1', '', '', 'submit_notification_label', '', '', '', '', ''],

['menu4', '', '', '', 'Remove Point', '', '', '', '17195132472446ed94bd91ba19a2b379'],
['menu4', 'select_text', 'list', '', 'Continue', '', '', '', ''],
['menu4', 'x', 'list', '', 'X', '', '', '', ''],
['menu4', 'y', 'list', '', 'Y', '', '', '', ''],
['menu4', 'x (ID Mapping Text)', 'detail', '', 'X Name', '', '', '', ''],
Expand All @@ -1287,6 +1305,7 @@ def test_bulk_app_single_sheet_rows(self):
['menu5', '', '', '', 'Empty Reports Module', '', '', '', '703eb807ae584d1ba8bf9457d7ac7590'],

['menu6', '', '', '', 'Advanced Module', None, None, '', '7f75ed4c15be44509591f41b3d80746e'],
['menu6', 'select_text', 'list', '', 'Continue with Case(s)', '', '', '', ''],
['menu6', 'name', 'list', '', 'Name', '', '', '', ''],
['menu6', 'name', 'detail', '', 'Name', '', '', '', ''],

Expand Down

0 comments on commit 5ca35c6

Please sign in to comment.