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
Comment #2
gueguerreiroThis 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.
Comment #4
nikolai fischer commentedThanks 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.
Comment #5
gueguerreiroThank 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
changeIndicatori.e:and
Or 2. Having 3 translations, where the base one is:
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.changeIndicatorthrough 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.
Comment #6
nikolai fischer commentedI 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?
Comment #7
gueguerreiroThat sounds good. I like it a lot more c:
We'll just have to make sure that on the v-if conditions:
and
We're not relying on a translated string for comparison. So we can just add an extra variable for the label, imo.
Comment #8
nikolai fischer commentedThat'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%".