Problem/Motivation

On the dashboard page, there are labels (E.g "Sales yesterday") that are not translatable.

Proposed resolution

Put those strings through Drupal.t() so they can be translated through the BO.

Since the markup variable already uses a template string, we just have to use interpolation and call the function directly.

The only ones that'll be an issue would be the Sales {{ sales.today.changeIndicator }} by 7% and similar, since they're not using real variables at the time the markup variable is set. I'm not sure how or if these can be translated, with the way they're currently being done.

Remaining tasks

Make strings translatable.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

gueguerreiro created an issue. See original summary.

gueguerreiro’s picture

Assigned: gueguerreiro » Unassigned
Status: Active » Needs review
StatusFileSize
new5.55 KB

This patch makes all dashboard labels translatable except:

Sales {{ sales.today.changeIndicator }} by 7%
Sales {{ sales.yesterday.changeIndicator }} by 7%
Sales {{ sales.week.changeIndicator }} by 7%

Because I can't figure out how to pass the processed variables to the Drupal.t() function.

nikolai fischer’s picture

Thanks for your work - i already commitet your code.

I'm not sure how to deal with the translations of the labels. The first thought that came to my mind is to split the strings and translate them one by another.

gueguerreiro’s picture

Status: Needs review » Needs work

Thank you, I appreciate it :) Thank you for your quick replies, they are also very much appreciated.

By splitting, do you mean:

1. Having two different translations, with an hardcoded changeIndicator i.e:

Drupal.t("Sales increased by @percentage", {'@percentage': '7%'})

and

Drupal.t("Sales decreased by @percentage", {'@percentage': '7%'})

Or 2. Having 3 translations, where the base one is:

Drupal.t("Sales @indicator by @percentage", {'indicator': sales.week.changeIndicator, '@percentage': '7%'})

And then the indicators will be translated separately.

The first one would work better, in my eyes. It would probably just require some changes in code structure, and I don't know enough about Vue to know how it'd work.

The second one is fine, but I still can't figure out how to get the sales.week.changeIndicator through to Drupal.t()'s function. The variable won't exist by the time the translation function is ran. It seems to only get added later once Vue is up and running, which is after the function was already called. But again, I don't know enough about Vue to know if there's a way around it that I'm missing.

Setting it to Needs Work so we can use this issue to figure out this one case now.

nikolai fischer’s picture

I first thought of the second one.

But there is a third solution: we can get the already translated string from the rest api. This would make it easier to handle the full string translation.

I my opinion this feels a little bit like a better solution. What do you think?

gueguerreiro’s picture

That sounds good. I like it a lot more c:

We'll just have to make sure that on the v-if conditions:

v-if="sales.today.changeIndicator === 'increased'"

and

v-if="sales.today.changeIndicator === 'decreased'"

We're not relying on a translated string for comparison. So we can just add an extra variable for the label, imo.

nikolai fischer’s picture

That's an important point.

I suggest to let the rest resource return 2 values for each case: One for the raw value and the second for the stranslated string. I'm gogin to provide a patch for this solution along with a patch that calculates the correct varriance which is now fixed to "7%".