3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 377 Views |
-
translatable : fallback on specific language if not translated

29 November 2011 at 2:03am
HI
in a bilingual site, I have a few pages that will be changed all the time and will never be translated.
is it possible to display the original content if page is not translated ?
or, to put it in different words, how can you access english content from a [translatable] french page ?same question for a data object...
thanks for your help
-
Re: translatable : fallback on specific language if not translated

29 November 2011 at 11:52pm
I don't think that is possible out of the box... Pages for which no translation exists, will not be displayed on the translated site, so you always need to create a translation.
I'm thinking maybe it would be possible to create some functionality in the page controller that would check if the current language is the master language, and if not, get the values for some specific field from the masterpage. You might use a boolean to enable/disable this behaviour on a per-page basis...
This way things like headers, footers and other stuff would still be French, while specific fields (like Content) would be English? The same would work for DataObjects...
Martine
-
Re: translatable : fallback on specific language if not translated

30 November 2011 at 10:28pm
yes exactly what I need.
not sure how to make that controller though.
pretty muchif
Content_locale empty
then
content_ensame for specific fields and dataObjects
will try but could use some help
-
Re: translatable : fallback on specific language if not translated

1 December 2011 at 1:42am
I just put something together, that might start as a beginning. What this does is create a custom getter for Content in the Page_Controller that in turn calls some general function useMaster($fieldName). This function does the following:
- check if the field is empty
- if so, check if we're using translatable
- if so, check if the current page is in fact a translation
- if all true, get the master page and return its contentsThis is all very scetchy, it might lead to something better, probably need a decorator, I don't know... Curious what you make of it...
class Page_Controller extends ContentController {
...
public function Content() {
return $this->UseMaster('Content');
}function useMaster($fieldName) {
if (empty($this->$fieldName)) {
if (Object::has_extension($this->ClassName, 'Translatable')) {
$GroupID = $this->getTranslationGroup();
if ($GroupID && $this->ID != $GroupID) {
$Master = DataObject::get_by_id('SiteTree', $GroupID);
if (!empty($Master->ID) && $Master->CanView()) {
return $Master->$fieldName;
}
}
}
}
return $this->$fieldName;
}Martine
| 377 Views | ||
|
Page:
1
|
Go to Top |

