Skip to content

Commit

Permalink
refactor(fields/date.twig): split translation in several variables
Browse files Browse the repository at this point in the history
  • Loading branch information
J9rem committed Mar 14, 2024
1 parent 8688941 commit d7382ef
Showing 1 changed file with 46 additions and 30 deletions.
76 changes: 46 additions & 30 deletions tools/bazar/templates/fields/date.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,46 +38,62 @@
lastOfMonth: 'EVENT_LAST_Y_OF_MONTH'
} %}
<span class="BAZ_texte">
<small><i>{{ _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 #}
<small><i>{{ _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 -%}
Expand Down

0 comments on commit d7382ef

Please sign in to comment.