Skip to content

Instantly share code, notes, and snippets.

@markstory
Created December 15, 2017 04:16
Show Gist options
  • Save markstory/e0d716dc4fea910432f460884b9eebeb to your computer and use it in GitHub Desktop.
Save markstory/e0d716dc4fea910432f460884b9eebeb to your computer and use it in GitHub Desktop.
<?php
// In config/bootstrap.php
use Cake\I18n\I18n;
use Cake\I18n\ChainMessagesLoader;
use Cake\I18n\MessagesFileLoader;
// Turn off 'default' as a fallback
I18n::translators()->useFallback(false);
// Create a custom fallback.
I18n::config('en_fallback', function ($name, $locale) {
$loader = new MessagesFileLoader('default', 'en', 'po');
$package = $loader();
return $package;
});
// Redefine the 'default' package to have en_fallback as a fallback package.
I18n::config('default', function ($name, $locale) {
// Prefer mo files over po files if they exist.
$chain = new ChainMessagesLoader([
new MessagesFileLoader('default', $locale, 'mo'),
new MessagesFileLoader('default', $locale, 'po'),
]);
$package = $chain();
$package->setFallback('en_fallback');
return $package;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment