Forums / General / Translation of variables

Translation of variables

Author Message

Claudia Kosny

Sunday 27 August 2006 3:59:34 am

Hi there

I would like to use the i18n operator on string variables but have problems using ezlupdate with this.
Example:

{def $countries = ezini('CountrySettings','Countries', 'content.ini')}
<select >
 {foreach $countries as $current_country}
   <option value="{$current_country}">{$current_country|i18n('my/countries')}</option>
 {/foreach}
</select>

What I want to achieve is that the countries are translated in the current language, even though they are only in English in the ini file.

The translation itself works absolutely fine (provided I added the proper entries in the translation.ts) , the only problem is the ezlupdate program. The program exits when encountering an argument that is not enclosed by quotation marks. I can certainly understand that it is not possible to create a proper entry in the translation.ts file for an argument which is not a string. But I don't see why the program does not just skip this entry and continues scanning the rest of my templates.

I have read the bug reports regarding this problem but they were closed without giving a solution.
The suggestion by Marc Boon to use

{'%var'|i18n('context','comment',hash('%var',$var))}

does not work as this way the content of the variable is not translated, just passed through.

My current workaround is to remove the offending line in my template, run ezlupdate and then add the line again, which is certainly workable but error-prone.

So here finally my question: Could someone give me some pointers on how to change the exlupdate such that it just skips invalid arguments (with an error message)? Or, if that does not cause problems with any licenses, couldsomeone contribute such a version, preferably for both Windows and Linux?

Thanks

Claudia

Thomas Nunninger

Sunday 27 August 2006 6:04:58 am

Hi Claudia,

I'm no C programmer. But I guess the solution is in file 'fetchtr_tpl.cpp'. Around line 164 I find:

        if ( endpos < 0 )
        {
            qWarning( filename + ":error: Found non-quoted context, skipping translation" );
            exit( 1 );
//             continue;
        }

Perhaps it's enough to comment the exit and uncomment the continue... I would try if it skips variables correctly then. Also I would make a diff of the result of translation.ts before and after changing the C code to ensure that everything works as expected (of course without variables in the templates to translate).

Additionally you can change the qWarning function like:

qWarning( filename + ":error: Found non-quoted context, skipping translation" + "content: " + content );

Then you should see the skipped content strings.

If you got an other error message just search for it in the code and try to solve it in a similar way. There are only two other exit commands between line 144 and 174. Shouldn't be that hard... With printing the content variable it should be solvable.

But I don't know if you will run in some other problems of wrong strings where e.g. only one quotation marks exists (or whatever). (Perhaps there is a reason for the exit instead of continue...)

Would be nice to hear if it works.

Have a nice day

Thomas

Claudia Kosny

Sunday 27 August 2006 11:35:48 pm

Hi Thomas

Thank you for the tips. I tried it yesterday but unfortunately I seem to have some problems with qt on my computer, so I will have to try it again whenI have more time to solve this.

I'll post my results once I get it done.

Claudia

Ludovic André

Thursday 08 February 2007 7:00:52 am

Hi Claudia,

just to give a little feedback about changing the C code of ezlupdate, I did this today... I encountered the same problem as you, and yeah it's really boring to remove the things from the template, generate the file, then replace the stuff in the template.
I removed the exit(1) called when empty source, and uncommented the continue line.

It appeared to be working properly as of now...

Hope it helps!

Regards

Ludovic André