Skip to content

Commit f0cfdf0

Browse files
committed
generator: make the other gender translation the default
fixes #1105 If there is no context, or the requested context does not exist, there should always be a fallback translation string to avoid untranslated text. The `other` gender should be this default one.
1 parent 7fc3f64 commit f0cfdf0

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

packages/evolution-generator/src/scripts/generate_labels.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@ def add_translations_from_excel(
303303
else None
304304
)
305305

306-
# Expand gender context for fr_label and fr_label_one
306+
# Expand gender context for labels, by language
307307
gender_fr = expand_gender(fr_label)
308308
gender_fr_one = expand_gender(fr_label_one)
309309
gender_en = expand_gender(en_label)
310310
gender_en_one = expand_gender(en_label_one)
311311

312-
# Delete the YAML file for the section before adding translations, but only once per (language, section) for the whole script
312+
# Add section to processed section set if not already processed
313313
if section not in processed_sections:
314314
processed_sections.add(section) # Mark section as processed
315315

@@ -331,10 +331,11 @@ def add_translations_from_excel(
331331
rowNumber=rowNumber,
332332
translations=translations_dict["fr"],
333333
)
334+
# The "other" translation will be the default one
334335
add_translation(
335336
language="fr",
336337
section=section,
337-
path=path + "_other",
338+
path=path,
338339
value=gender_fr["other"],
339340
rowNumber=rowNumber,
340341
translations=translations_dict["fr"],
@@ -370,7 +371,7 @@ def add_translations_from_excel(
370371
add_translation(
371372
language="fr",
372373
section=section,
373-
path=path + "_other_one",
374+
path=path + "_one",
374375
value=gender_fr_one["other"],
375376
rowNumber=rowNumber,
376377
translations=translations_dict["fr"],
@@ -406,7 +407,7 @@ def add_translations_from_excel(
406407
add_translation(
407408
language="en",
408409
section=section,
409-
path=path + "_other",
410+
path=path,
410411
value=gender_en["other"],
411412
rowNumber=rowNumber,
412413
translations=translations_dict["en"],
@@ -442,7 +443,7 @@ def add_translations_from_excel(
442443
add_translation(
443444
language="en",
444445
section=section,
445-
path=path + "_other_one",
446+
path=path + "_one",
446447
value=gender_en_one["other"],
447448
rowNumber=rowNumber,
448449
translations=translations_dict["en"],

packages/evolution-generator/src/scripts/generate_widgets.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,9 @@ def generate_label(section, path, row, key_name="label"):
539539
if has_label_one or has_persons_count_label:
540540
initial_assignations += f"{INDENT}{INDENT}const countPersons = odSurveyHelpers.countPersons({{ interview }});\n"
541541
if has_gender_context_label:
542-
initial_assignations += (
543-
f"{INDENT}{INDENT}const personGender = activePerson?.gender\n"
542+
additional_t_context += (
543+
f"{INDENT}{INDENT}{INDENT}context: activePerson?.gender,\n"
544544
)
545-
additional_t_context += f"{INDENT}{INDENT}{INDENT}context: personGender === 'male' || personGender === 'female' ? personGender : 'other',\n"
546545
if has_persons_count_label or has_label_one:
547546
additional_t_context += f"{INDENT}{INDENT}{INDENT}count: countPersons,\n"
548547
widget_label = (

packages/evolution-generator/src/tests/test_generate_widgets.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ def test_generate_label_with_gender_label():
226226
assert "const activePerson =" in result
227227
assert "const nickname =" not in result
228228
assert "const countPersons =" not in result
229-
assert "const personGender =" in result
230-
assert "context: personGender =" in result
229+
assert "context: activePerson?.gender" in result
231230

232231

233232
def test_generate_label_with_one_person():
@@ -262,11 +261,10 @@ def test_generate_label_with_all_contexts():
262261
assert "const activePerson =" in result
263262
assert "const nickname =" in result
264263
assert "const countPersons =" in result
265-
assert "const personGender =" in result
266264
assert "nickname," in result
267265
assert "nickname," in result
268266
assert "count: countPersons" in result
269-
assert "context: personGender =" in result
267+
assert "context: activePerson?.gender" in result
270268

271269

272270
# TODO: Test generate_help_popup

0 commit comments

Comments
 (0)