From d7382ef1db7aed1d59351828429b24260a25000d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Dufraisse?= Date: Thu, 14 Mar 2024 15:27:51 +0100 Subject: [PATCH] refactor(fields/date.twig): split translation in several variables --- tools/bazar/templates/fields/date.twig | 76 ++++++++++++++++---------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/tools/bazar/templates/fields/date.twig b/tools/bazar/templates/fields/date.twig index 05e1c84b4..36a7551b0 100644 --- a/tools/bazar/templates/fields/date.twig +++ b/tools/bazar/templates/fields/date.twig @@ -38,46 +38,62 @@ lastOfMonth: 'EVENT_LAST_Y_OF_MONTH' } %} - {{ _t('EVENT_IS_RECURRENT',{ - repetition: data.repetition == 'y' - ? _t( + {# create variables used to translate part of repetition text #} + {% set repetitionTextNthOfMonthForYear = _t('EVENT_REPETITION_NTH_OF_MONTH',{ + nth: data.nth ?? '?', + month: _t(monthT[data.month] ?? '???')|lower + }) + %} + {% set repetitionTextInMonthForYear = _t('EVENT_REPETITION_IN_MONTH',{ + month:_t(monthT[data.month] ?? '???')|lower }) + ~ _t(inMonthT[data.whenInMonth] ?? '???')|replace({ + Y:_t(dayT[data.days|first] ?? '??') + })|lower + %} + {% set repetitionTextForYear = _t( data.step == 1 ? 'EVENT_REPETITION_FOR_YEAR' : 'EVENT_REPETITION_FOR_YEARS', { x:data.step ?? '?', - monthRepetition: - data.whenInMonth == 'nthOfMonth' - ? _t('EVENT_REPETITION_NTH_OF_MONTH',{ - nth: data.nth ?? '?', - month: _t(monthT[data.month] ?? '???')|lower - }) - : _t('EVENT_REPETITION_IN_MONTH',{month:_t(monthT[data.month] ?? '???')|lower }) - ~ _t(inMonthT[data.whenInMonth] ?? '???')|replace({ - Y:_t(dayT[data.days|first] ?? '??') - })|lower + monthRepetition: data.whenInMonth == 'nthOfMonth' + ? repetitionTextNthOfMonthForYear + : repetitionTextInMonthForYear } - ) - : (data.repetition == 'm' - ? _t('EVENT_REPETITION_FOR_MONTHS',{ - x:data.step ?? '?', - monthRepetition: - data.whenInMonth == 'nthOfMonth' - ? _t('EVENT_REPETITION_NTH_OF_MONTH_ALONE',{ - nth: data.nth ?? '?' - }) - : _t(inMonthT[data.whenInMonth] ?? '???')|replace({ - Y:_t(dayT[data.days|first] ?? '??') - })|lower - })|lower - : ( data.repetition == 'w' - ? _t('EVENT_REPETITION_FOR_WEEKS',{ + ) + %} + {% set repetitionTextForMonth = _t('EVENT_REPETITION_FOR_MONTHS',{ + x:data.step ?? '?', + monthRepetition: + data.whenInMonth == 'nthOfMonth' + ? _t('EVENT_REPETITION_NTH_OF_MONTH_ALONE',{ + nth: data.nth ?? '?' + }) + : _t(inMonthT[data.whenInMonth] ?? '???')|replace({ + Y:_t(dayT[data.days|first] ?? '??') + })|lower + })|lower + %} + {% set repetitionTextForWeeks = _t('EVENT_REPETITION_FOR_WEEKS',{ x:data.step ?? '?', days: data.days|map(v=>_t(dayT[v] ?? '??'))|join(',') })|lower - : _t('EVENT_REPETITION_FOR_DAYS',{ + %} + {% set repetitionTextForDays = _t('EVENT_REPETITION_FOR_DAYS',{ x:data.step ?? '?', })|lower + %} + {# assembly all this variables according to type of repetition #} + {% set repetitionText = data.repetition == 'y' + ? repetitionTextForYear + : (data.repetition == 'm' + ? repetitionTextForMonth + : ( data.repetition == 'w' + ? repetitionTextForWeeks + : repetitionTextForDays ) - ), + ) %} + {# use the translation #} + {{ _t('EVENT_IS_RECURRENT',{ + repetition: repetitionText, nb: data.nbmax ?? '?' }) }}{% if data.limitdate %}, {{ _t('EVENT_LIMIT_DATE',{date:data.limitdate}) }}{% endif %} {%- if data.except is not empty -%}