Created
December 15, 2017 04:16
-
-
Save markstory/e0d716dc4fea910432f460884b9eebeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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