mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Allowing to flush translation cache through ?flush=1
This commit is contained in:
parent
d57e864110
commit
d3b63dae0c
@ -246,6 +246,10 @@ Translation table: sapphire/lang/de.yml (extract)
|
|||||||
FileIframeField:
|
FileIframeField:
|
||||||
NOTEADDFILES: 'Sie können Dateien hinzufügen sobald Sie das erste mal gespeichert haben'
|
NOTEADDFILES: 'Sie können Dateien hinzufügen sobald Sie das erste mal gespeichert haben'
|
||||||
|
|
||||||
|
Note that translations are cached across requests.
|
||||||
|
The cache can be cleared through the `?flush=1` query parameter,
|
||||||
|
or explicitly through `Zend_Translate::getCache()->clean(Zend_Cache::CLEANING_MODE_ALL)`.
|
||||||
|
|
||||||
## Language definitions (2.x)
|
## Language definitions (2.x)
|
||||||
|
|
||||||
In SilverStripe 2.x, the tables are just PHP files with array notations,
|
In SilverStripe 2.x, the tables are just PHP files with array notations,
|
||||||
|
@ -1479,7 +1479,9 @@ class i18n extends Object implements TemplateGlobalProvider {
|
|||||||
// If language table isn't loaded for this locale, get it for each of the modules.
|
// If language table isn't loaded for this locale, get it for each of the modules.
|
||||||
// The method will automatically load fallback languages (the lang for a locale).
|
// The method will automatically load fallback languages (the lang for a locale).
|
||||||
if(!$adapter->isAvailable($locale) && !$adapter->isAvailable($lang)) {
|
if(!$adapter->isAvailable($locale) && !$adapter->isAvailable($lang)) {
|
||||||
i18n::include_by_locale($locale);
|
// TODO Remove reliance on global state, by refactoring into an i18nTranslatorManager
|
||||||
|
// which is instanciated by core with a $clean instance variable.
|
||||||
|
i18n::include_by_locale($locale, (isset($_GET['flush'])));
|
||||||
}
|
}
|
||||||
$translation = $adapter->translate($entity, $locale);
|
$translation = $adapter->translate($entity, $locale);
|
||||||
|
|
||||||
@ -1496,11 +1498,13 @@ class i18n extends Object implements TemplateGlobalProvider {
|
|||||||
* @return array Array of priority keys to instances of Zend_Translate, mapped by name.
|
* @return array Array of priority keys to instances of Zend_Translate, mapped by name.
|
||||||
*/
|
*/
|
||||||
static function get_translators() {
|
static function get_translators() {
|
||||||
if(!self::$translators) {
|
if(!Zend_Translate::getCache()) {
|
||||||
Zend_Translate::setCache(
|
Zend_Translate::setCache(
|
||||||
SS_Cache::factory('i18n', 'Output', array('lifetime' => null, 'automatic_serialization' => true))
|
SS_Cache::factory('i18n', 'Output', array('lifetime' => null, 'automatic_serialization' => true))
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!self::$translators) {
|
||||||
$defaultPriority = 10;
|
$defaultPriority = 10;
|
||||||
self::$translators[$defaultPriority] = array(
|
self::$translators[$defaultPriority] = array(
|
||||||
'core' => new Zend_Translate(array(
|
'core' => new Zend_Translate(array(
|
||||||
@ -1872,10 +1876,16 @@ class i18n extends Object implements TemplateGlobalProvider {
|
|||||||
* will load the base locale file as well (if available).
|
* will load the base locale file as well (if available).
|
||||||
*
|
*
|
||||||
* @param string $locale All resources from any module in locale $locale will be loaded
|
* @param string $locale All resources from any module in locale $locale will be loaded
|
||||||
|
* @param Boolean $clean Clean old caches?
|
||||||
*/
|
*/
|
||||||
static function include_by_locale($locale) {
|
static function include_by_locale($locale, $clean = false) {
|
||||||
$lang = i18n::get_lang_from_locale($locale);
|
$lang = i18n::get_lang_from_locale($locale);
|
||||||
|
|
||||||
|
if($clean) {
|
||||||
|
$cache = Zend_Translate::getCache();
|
||||||
|
if($cache) $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
// Automatically include fallback language (if applicable)
|
// Automatically include fallback language (if applicable)
|
||||||
// TODO Also include custom Zend_Translate routing languages
|
// TODO Also include custom Zend_Translate routing languages
|
||||||
$selectedLocales = array_unique(array($lang, $locale));
|
$selectedLocales = array_unique(array($lang, $locale));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user