Skip to content

Instantly share code, notes, and snippets.

@bummzack
Created December 23, 2015 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bummzack/72bbf4bda56cba0e04d1 to your computer and use it in GitHub Desktop.
Save bummzack/72bbf4bda56cba0e04d1 to your computer and use it in GitHub Desktop.
SilverStripe Controller that sets the default locale on all controllers upon init. Helps resolve translation issues.
class ControllerExtension extends Extension
{
public function onBeforeInit()
{
// Ensure the locale is set properly on all requests (otherwise AJAX requests might return templates rendered
// with wrong locales).
i18n::set_default_locale(Config::inst()->get('i18n', 'default_locale'));
}
}
@bummzack
Copy link
Author

Apply in your config file:

Controller:
  extensions:
    - ControllerExtension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment