Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to other language than default language possible? #41

Open
derralf opened this issue Sep 2, 2016 · 1 comment
Open

Fallback to other language than default language possible? #41

derralf opened this issue Sep 2, 2016 · 1 comment

Comments

@derralf
Copy link

derralf commented Sep 2, 2016

Hi,
is it possible to fallback to another language than the default/master language (with $strict = false)?

Lets say i have 3 languages: german, english, russian.
Default language is german (most content ist german, client is german).

Now when some contents are translated to english (but not to russian), it would be nice to display english (more international) contents to russian visitors (instead of german though it's the master language).

@bummzack
Copy link
Owner

bummzack commented Sep 3, 2016

Currently, that's not possible. Ideally, your project-setup has the master-language as preferred fallback. Eg. English as master-language.

You could create a separate extension with that functionality though…

class FallbackTranslationExtension extends DataExtension 
{
    public function FT($fieldName)
    {
        $value = $this->owner->getLocalizedValue($fieldName, true);
        if ($value) {
            return $value;
        }

        // Using `en_US` as fallback locale here
        $fallback = TranslatableDataObject::localized_field($fieldName, 'en_US');
        return $this->owner->dbObject($fallback);
    }
}

Then use $FT('MyField') in templates…

I'm not sure how common your use-case is… maybe it would be worthwhile to add the functionality to the module. Ideally, this would be configurable via config, so that you can specify a fallback order for every language? The problem I see with that, is that it's only applied to DataObjects and doesn't affect the translation of pages, which could be confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants