i18next / i18nextify

enables localization of any page with zero effort.
MIT License
61 stars 21 forks source link

How to translate Dojo's inner attribute value #83

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi, I'm trying to translate a row like this:

button#btn.mblSimpleDialogButton(data-dojo-type="dojox/mobile/Button" data-dojo-props="label: 'Close'")

How would you translate only the 'Close' word?

jamuhl commented 6 years ago

Will that be <button>Close</button> in html? That should work out of the box.

ghost commented 6 years ago

It's rendered as:

<button id="btn" data-dojo-type="dojox/mobile/Button" data-dojo-props="label: 'Close'" class="mblButton mblSimpleDialogButton unselectable" localized="" tabindex="0" widgetid="btn" style="user-select: none;">Close</button>

I discovered the translation works only if I remove the attribute data-dojo-props, placing the text outside the attribute section:

button#btn.mblSimpleDialogButton(data-dojo-type="dojox/mobile/Button") Close

Of course, if I can I will change my code like that. I don't know if Dojo has any caveats on declaring widgets in this way.

jamuhl commented 6 years ago

You can also try adding data-dojo-props to the translateAttributes array on init: https://github.com/i18next/i18nextify#initialize-with-options that way those will get translated too

ghost commented 6 years ago

Yes, but it will translate the whole attribute and it's not very handy because the attribute might contain a lot of other properties, i.e.:

data-dojo-props="iconClass:'dijitEditorIcon dijitEditorIconCut', showLabel: false, label:'Cut'"

and I cannot ask to the translator to maintain all the other fields... and it would be a pain if I need to change any of them.

ghost commented 6 years ago

Anyway, for my current needs, it was enough to fix the syntax as described in the previous post.