1
votes

I'm trying to develop a database driven translation site in cakePHP.

When I'm setting the Model locale or Config.language to a language such as de-de like below:

Configure::write("Config.language", "de-de");

it loads the correct translations of de_DE from the i18n table.

My problem is, if the translation does not exist for another row, it doesn't return anything. Is there anything you have to setup so if it doesn't find anything, it returns the 'default' language translation or the data directly from the Model??

I think it's too much work to stay checking all the time if data is returned and if not changing the locale/language settings all time to the default language you want..

Or maybe I'm doing this wrong?


Code:

data in i18n table:

id  locale  model   foreign_key field       content
2   de_DE   Suite   4           description description in en_US for vilhena
3   en_US   Suite   3           description description in en_Us for del Monte
4   en_US   Suite   2           description description in en_Us for Pinto
5   en_US   Suite   1           description description in en_Us for Hompesch


Configure::write("Config.language", "de-de");
$this->Suite->find("all");

returns

Array
(
    [0] => Array
        (
            [Suite] => Array
                (
                    [id] => 4
                    [name] => Vilhena
                    [enabled] => 1
                    [description] => description in en_US for vilhena
                    [locale] => de_de
                )

        )

)
1
Yeah, the default behavior is that it shows the untranslated string if no translation is found. Maybe if you showed an example where it's not working correctly?JJJ
@Juhana - thx for the interest! i've updated my question with the data in the i18n table, the code i'm using & the result i'm gettinghex4

1 Answers

0
votes

must be Configure::write("Config.language", "de-DE");