How do you check and see if a propel object has an i18n record?
-
05-07-2019 - |
Question
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)
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?
something like this:
if($currentLesson->cultureExists($lessonCulture) $currentLesson = $currentLesson->getCurrentLessonsI18n($lessonCulture);
or
sfConfig::setPropelDefaultCulture("en_US");
Solution
You will have to overwrite symfony itself to make it default to another language. Theres a good working solution here http://www.codemassacre.com/2008/03/10/symfony-default-language-fallback/
OTHER TIPS
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)
.