如何检查推进物是否有i18n记录?

时间:2021-10-14 21:20:20

I'm using symfony and propel, and I'm trying to invoke a specific culture on an object and output some fields of that object to the screen in that specific culture. However, if the object's mapped database record doesn't have those fields in that specific culture, I would like it to default to the base culture (in this case, en_US)

我正在使用symfony和propel,我正在尝试在对象上调用特定的文化,并将该对象的某些字段输出到该特定文化中的屏幕。但是,如果对象的映射数据库记录在该特定文化中没有这些字段,我希望它默认为基本文化(在本例中为en_US)

I'm doing it like this:

我是这样做的:

$currentLesson = $currentLesson->getCurrentLessonsI18n($lessonCulture);

But when I output such as this

但是当我输出这样的时候

$currentLesson->getTitle();

It outputs an empty string if there is no culture record for it. My question is, is there a way to make an object default to a specific culuture if the one I specify isn't available, or is there a method to see if a specific object has a culture i18n record?

如果没有文化记录,它会输出一个空字符串。我的问题是,如果我指定的对象不可用,或者是否有方法来查看特定对象是否具有culture i18n记录,是否有办法使对象默认为特定文件?

something like this:

像这样的东西:

if($currentLesson->cultureExists($lessonCulture) $currentLesson = $currentLesson->getCurrentLessonsI18n($lessonCulture);

or

sfConfig::setPropelDefaultCulture("en_US");

2 个解决方案

#1


1  

You will have to overwrite symfony itself to make it default to another language. Theres a good working solution here http://www.code*.com/2008/03/10/symfony-default-language-fallback/

您将不得不覆盖symfony本身以使其默认为另一种语言。这里有一个很好的解决方案http://www.code*.com/2008/03/10/symfony-default-language-fallback/

#2


0  

The i18n record you get back from getTranslation($language) can be tested with isNew(), that will tell you if Propel has just made it up (true) or if it came from the database (false).

您从getTranslation($ language)返回的i18n记录可以使用isNew()进行测试,它会告诉您Propel是刚刚启动(true)还是来自数据库(false)。

#1


1  

You will have to overwrite symfony itself to make it default to another language. Theres a good working solution here http://www.code*.com/2008/03/10/symfony-default-language-fallback/

您将不得不覆盖symfony本身以使其默认为另一种语言。这里有一个很好的解决方案http://www.code*.com/2008/03/10/symfony-default-language-fallback/

#2


0  

The i18n record you get back from getTranslation($language) can be tested with isNew(), that will tell you if Propel has just made it up (true) or if it came from the database (false).

您从getTranslation($ language)返回的i18n记录可以使用isNew()进行测试,它会告诉您Propel是刚刚启动(true)还是来自数据库(false)。