This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » General discussion » Automatic internationalization of forms
Automatic internationalization of forms [message #97293] Wed, 14 April 2010 00:06 Go to next message
beeeee  is currently offline beeeee
Messages: 3
Registered: April 2010
Junior Member
Hi there,

I started my first symfony project and would like to add I18N. I set up the routes, the __() helper works correctly. So far so good...

In Day 19 of the tutorial I18N of forms is explained like this:
Forms
The form classes contain many strings that need to be translated, 
like labels, error messages, and help messages. All these strings 
are automatically internationalized by symfony, so you only need to provide 
translations in the XLIFF files.


Well, I added a new translation in the XLIFF file to replace one of the labels, which are generated using doctrine:generate-module:
<trans-unit id="2">
  <source>Created at</source>
  <target>German: Erzeugt am</target>
</trans-unit>


Unfortunately this won't work. Strings via the __() helper are translated correctly, but not the labels generated by the framework. Did I interpret the tutorial wrong?

Thanks for your help!

symfony: 1.4.4
php: 5.3.1 using Apachefriends XAMPP Environment

[Updated on: Wed, 14 April 2010 00:09]

Re: Automatic internationalization of forms [message #97365 is a reply to message #97293 ] Wed, 14 April 2010 18:21 Go to previous messageGo to next message
hopscotch1978  is currently offline hopscotch1978
Messages: 258
Registered: January 2010
Location: Spain
Faithful Member
Good question, I'm going to run into this problem shortly if it's not working properly so I'm interested in the answer.

This may be off, but maybe try including the i18N helper in your form class:

sfContext::getInstance()->getConfiguration()->loadHelpers('I18N');


If you do find a solution that works, please post here.

[Updated on: Wed, 14 April 2010 18:21]

Re: Automatic internationalization of forms [message #97367 is a reply to message #97293 ] Wed, 14 April 2010 18:25 Go to previous messageGo to next message
hopscotch1978  is currently offline hopscotch1978
Messages: 258
Registered: January 2010
Location: Spain
Faithful Member
Hmm.... on closer inspection, I found this:

"Unfortunately, the i18n:extract task does not yet parse form classes for untranslated strings."

http://www.symfony-project.org/jobeet/1_4/Doctrine/en/19

If that's true, it's a real bummer...

If anyone has a good workaround, would be very interested in hearing.
Re: Automatic internationalization of forms [message #97377 is a reply to message #97293 ] Wed, 14 April 2010 18:54 Go to previous messageGo to next message
hopscotch1978  is currently offline hopscotch1978
Messages: 258
Registered: January 2010
Location: Spain
Faithful Member
Uhh......... Ok, figured it out.

It's the "extract" task that doesn't work for form classes.

The strings must be added manually into the XLIFF in question. Just tested it, works fine.

In the end, that's exactly what the symfony documentation says Smile
Re: Automatic internationalization of forms [message #97386 is a reply to message #97377 ] Wed, 14 April 2010 19:49 Go to previous messageGo to next message
beeeee  is currently offline beeeee
Messages: 3
Registered: April 2010
Junior Member
Thanks for your answers. I think I have to be more specific...

On generating a module using doctrine:generate-module symfony creates some files, e.g. indexSuccess.php. Mine looks like this:

<h1>Jobs List</h1>

<table>
  <thead>
    <tr>
      <th>Id</th>
      <th>Job</th>
      <th>Created at</th>
      <th>Updated at</th>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($jobs as $job): ?>
    <tr>
      <td><a href="<?php echo url_for('job/show?id='.$jobeet_job->getId()) ?>"><?php echo $jobeet_job->getId() ?></a></td>
...


I thought, the labels in the <th>...</th> will be internationalized, as soon as I add a translation in the XLIFF file.
<trans-unit id="2">
  <source>Created at</source>
  <target>German: Erzeugt am</target>
</trans-unit>


Won't work...
Re: Automatic internationalization of forms [message #97388 is a reply to message #97386 ] Wed, 14 April 2010 19:57 Go to previous messageGo to next message
hopscotch1978  is currently offline hopscotch1978
Messages: 258
Registered: January 2010
Location: Spain
Faithful Member
For that to happen, you have to write them out like this in your template:

<th><?php echo $form['created_at']->renderLabel() ?></th>


... where $form is the $form class you're using.

[Updated on: Wed, 14 April 2010 19:58]

Re: Automatic internationalization of forms [message #97389 is a reply to message #97388 ] Wed, 14 April 2010 20:17 Go to previous message
beeeee  is currently offline beeeee
Messages: 3
Registered: April 2010
Junior Member
Okay, I guess I should better use the __() helper... Very Happy Again, thanks for you help!
Previous Topic:Newbie Form help
Next Topic:Connecting one page by foreign key
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software