This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

i18n: translation does not work on web

Discussion relating to version 1.2.x stable

i18n: translation does not work on web

by toledot » Sun Nov 22, 2009 10:14 pm

I have done the implementation step by step according the guidance in the tutorial, but the i18n does not work. Can anyone help me?
toledot
Junior Member
 
Posts: 4
Joined: Wed Nov 19, 2008 6:49 pm

Re: i18n: translation does not work on web

by Levelx » Tue Nov 24, 2009 1:34 am

Please give more specific information!

Are you talking about I18n in database or about I18n of the template strings?

Show your translation file and show the piece of code, where you call the __() function. Or show your schema.yml. How did you name your XML files etc.
Levelx
Faithful Member
 
Posts: 359
Joined: Thu Apr 30, 2009 4:22 pm
Location: Germany

Re: i18n: translation does not work on web

by toledot » Tue Nov 24, 2009 12:01 pm

hi, Thanks for your answer, here are some specific information about my sample application "simple blog system"
1) I talked about I18n of the template strings
2) translation file
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xliff PUBLIC "-//XLIFF//DTD XLIFF//EN" "http://www.oasis-open.org/committees/xliff/documents/xliff.dtd">
<xliff version="1.0">
  <file source-language="EN" target-language="de" datatype="plaintext" original="messages" date="2009-11-24T10:46:11Z" product-name="messages">
    <header/>
    <body>
      <trans-unit id="1">
        <source>List of posts</source>
        <target>Liste von Artikeln<target/>
      </trans-unit>
      <trans-unit id="2">
        <source>List of comments</source>
        <target>Liste von Kommentaren<target/>
      </trans-unit>
      <trans-unit id="3">
        <source>My first symfony project</source>
        <target>Mein erstes Symfony Projekt<target/>
      </trans-unit>
      <trans-unit id="4">
        <source>Post List</source>
        <target>Artikellist<target/>
      </trans-unit>
      <trans-unit id="5">
        <source>Title</source>
        <target>Titel<target/>
      </trans-unit>
      <trans-unit id="6">
        <source>Created at</source>
        <target>erzeugt am<target/>
      </trans-unit>
      <trans-unit id="7">
        <source>add a new comment</source>
        <target>fuege ein neue Kommentar hinzu<target/>
      </trans-unit>
      <trans-unit id="8">
        <source>welcome to my homepage</source>
        <target>Willkomm zum meinen Homepage<target/>
      </trans-unit>
      <trans-unit id="9">
        <source>Id</source>
        <target>ID<target/>
      </trans-unit>
      <trans-unit id="10">
        <source>Author</source>
        <target>der Author<target/>
      </trans-unit>
      <trans-unit id="11">
        <source>Email</source>
        <target>Email<target/>
      </trans-unit>
      <trans-unit id="12">
        <source>Body</source>
        <target>Body<target/>
      </trans-unit>
    </body>
  </file>
</xliff>

3) call the __() function
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <?php include_http_metas() ?>
    <?php include_metas() ?>
    <?php include_title() ?>
    <?php use_helper('I18N') ?>

    <link rel="shortcut icon" href="/favicon.ico" />
  </head>
  <body>
   <div id="container" style="width:700px;margin:0 auto;border:1px solid grey;padding:10px">
     <div id="navigation" style="display:inline;float:right">
       <ul>
         <li><?php echo link_to(__('List of posts'), 'post/index') ?></li>
         <li><a href="<?php echo url_for('post/index') ?>"><?php echo __('List of posts') ?> </a></li>
         <li><?php echo link_to(__('List of comments'), 'comment/index') ?></li>
       </ul>
     </div>
     <div id="title">
       <h1><?php echo link_to(__('My first symfony project'), '@homepage') ?></h1>
     </div>
   
     <div id="content" style="clear:right">
       <?php echo $sf_data->getRaw('sf_content') ?>
     </div>
   </div>
   
   <div id="footer">
     <div align=right>
       <?php echo link_to('English', '@default?' . http_build_query(array('sf_culture' => 'en', 'module' => $sf_request->getParameter('module'), 'action' => $sf_request->getParameter('action'))),'id=linkFooter', null, '&') ?> |
       <?php echo link_to('DE', '@default?' . http_build_query(array('sf_culture' => 'de', 'module' => $sf_request->getParameter('module'), 'action' => $sf_request->getParameter('action'))), 'id=linkFooter', null, '&') ?> |
          </div>
        </div><!-- end footer -->
   </div><!-- end container -->

  </body>
</html>

4) schema.yml
Code: Select all
propel:
  blog_post:
    id:            ~
    title:         { type: varchar(255), required: ture }
    excerpt:      { type: longvarchar }
    body:          { type: longvarchar }
    created_at:    ~
  blog_comment:
    id:            ~
    blog_post_id:  ~
    author:        { type: varchar(255) }
    email:         { type: varchar(255) }
    body:          { type: longvarchar }
    created_at:    ~
   

5) settings.yml for I18N
Code: Select all
.settings:
i18n:                   on       # Enable interface translation. Set to off if your application should not be translated.
standard_helpers:       [Partial, Cache, I18N]
charset:                utf-8
default_culture:        en        # Default user culture

6) factories.yml
Code: Select all
  i18n:
    class: sfI18N
    param:
#      default_culture:      en_US
      source:               XLIFF


7) How did you call your XML files etc: I do not understand this question, perhaps my problem is exactly here.
toledot
Junior Member
 
Posts: 4
Joined: Wed Nov 19, 2008 6:49 pm

Re: i18n: translation does not work on web

by Levelx » Sun Nov 29, 2009 9:35 pm

Did you solve your problems while the forum was down?

Your posted parts of code seem ok.
The changes in the factories.yml seem to be optional, because in my working models this changes are not made.
The call of the <?php use_helper('I18N') ?> in your template are not neccessary as long as you include the I18N helper in the settings as standard helpers.


In which folder did you locate your xlm files and how did you name them? Maybe you have a problem there.
I use:
Code: Select all
.../application/i18n/messages.en.xlm


but
Code: Select all
.../application/i18n/en/messages.xlm

will also work, but I like to have the language in the file name.
Levelx
Faithful Member
 
Posts: 359
Joined: Thu Apr 30, 2009 4:22 pm
Location: Germany

Re: i18n: translation does not work on web

by kitowiec » Tue Mar 15, 2011 12:23 pm

The task
Code: Select all
symfony i18n:extrac

is working incorrectly. It generates end tag <target/>, but it should generate </target>. It solved my problem.
kitowiec
Junior Member
 
Posts: 1
Joined: Tue Mar 15, 2011 12:18 pm

Re: i18n: translation does not work on web

by amady » Fri Oct 21, 2011 1:44 pm

When you want to test if the set sourceLanguage + target language in your yii config works, look at eg. the pager of a CListView. Don't look at eg. the default front page or login page as the strings there don't make use of Yii::t. cialis online

A tip that helped me is as tasay wrote, to take a look in the framework/messages directory and pick a locale there, rather than looking on a full list of all possible locale strings. For example for Swedish there exist sv_SE and sv_FI (SE = Sweden, FI = Finland), but in framework/messages there exist only a sv.php file. So if I use "sv" as my target language, I get the core/zii translations for free rather than having to translate that as well.
amady
Junior Member
 
Posts: 1
Joined: Fri Oct 21, 2011 1:42 pm