Thank you all, I have successfully implemented translations.

The implementation to help other facing the same situation:

1. Create the i18n tables from the sql file /config/sql/i18n.sql
2. Create the news_articles table
       id (int8) prim key, auto incr.
       .... other fields like created_at, updates_at ....

3. Create a demo article in news_articles
id      created_at
1       2007-06-01 14:55:41

4. Add some demo data to i18n
----
id      content
1       Title in english
2       Titre en français
3       Content in english
4       Contenu en français
----

5. Add some demo data to i18n_content
----
id      locale  i18n_content_id model   row_id  field
1       en      1       NewsArticle     1       title
2       fr      2       NewsArticle     1       title
3       en      3       NewsArticle     1       content
4       fr      4       NewsArticle     1       content
-----

6. Build the model for news_article (/models/news_article.php)
----
class NewsArticle extends AppModel{
        var $name = 'NewsArticle';
        var $actsAs = array('Translate' => array('title','content'));
}
----
(title,content are the fields to translate. Add more for every field)

7. Basic news_articles controller with index action (/controllers/
news_articles_controller.php)
----
class NewsArticlesController extends AppController{
        var $name = 'NewsArticles';

        function index(){
                //set the required language identifier here, 'en' or 'fr' in 
this
example
                $this->NewsArticle->locale = 'fr';

                $this->set('news_articles', $this->NewsArticle->findAll());
        }
}
---
Changing $this->NewsArticle->locale to 'en' would fetch english
content.

It would probably be best to set this locale via a beforefilter in
this controller or the appcontroller for real use.

8. Basic view, nothing fancy (/views/news_articles/index.ctp):
----
<table>
        <tr>
                <th>ID:</th>
                <th>Title / Content:</th>
        </tr>

        <?php foreach($news_articles as $article): ?>
        <tr>
                <td>
                        <?php echo $article['NewsArticle']['id']; ?>
                </td>
                <td>
                <?php echo $article['NewsArticle']['title']; ?>
                <br /><i><?php echo $article['NewsArticle']['content']; ?></i>
                </td>
        </tr>
        <?php endforeach; ?>

</table>


The following issues need to be resolved for my project;
- The ability to fetch default data when the data is not available in
the database in the requested language. For example a news article is
not available in French so the English version would be fetched by the
model given English is the default language of the site.
- Some sort of indicator stating the requested language is not
available so a version in the default language is given.

Maybe this sort of functionality is already in Cake 1.2. If someone
knows something about this issue then this would be very helpful also.

Thanks,




On Jun 1, 1:33 pm, jitka <[EMAIL PROTECTED]> wrote:
> > Do I understand it right that the table i18n & i18n_content stores
> > translations for each table that uses it?
>
> Yes.
>
> > If that's right the structure for news would be:
>
> > Table: news
> > id: int(8)
> > title: varchar(255)
> > content: text
> > ...other fields
>
> No. Structure for table 'news' will be
> id: int(8)
> ...other fields
>
> because all translated fields (title and content in your case) are
> only virtual, managed by TranslateBehavior in i18n tables.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to