Reply To: Problem with Spanish translation

Bring Your Business to LifeSupportPopular WidgetProblem with Spanish translationReply To: Problem with Spanish translation

#50052
jrf
Participant

Actually, I’ve figured it out by now….

 

The main problem is that you don’t have an update() function in your widget class.

This basically means you don’t validate *any* of the input a user gives in the widget options and whatever is received is saved to the widget $instance regardless.

Quite apart from the fact that this is unsafe and bad practice, it also means that the (English) default text phrases will be saved with the instance instead of being filtered out.

There are three ways to get around this problem:

1) Have the translation files installed with the plugin so the default strings will be available in the preferred language from the start – at least for the languages for which a translation is currently available (eh.. I get the feeling I’m repeating myself from my earlier post….)

2) The user can edit (rename) the text strings which will then be saved to the widget $instance.
However, this functionality is not very obvious in the options panel (the ‘move’ cursor is more prominent and you only see that you can actually rename the phrases in the same bit if you hover over the actual text). It doesn’t help that there is no help text or hint in the section title either.

3) [BEST SOLUTION BY FAR!] Add the update() function to the widget class and properly validate every input for expected values and acceptable values.
If the input is the same as the default value, do *not ever* save it with the $instance! For the display function: use what’s in the $instance and for any options not set, use the default values.

As the text string defaults are translation ready, installing a translation file later on will then no longer be a problem either.

 

Hope this helps.