protected static function enable_custom_translations()
 {
     $locale = i18n::get_locale();
     $lang = i18n::get_lang_from_locale($locale);
     $profileDir = self::getProfileDir();
     $translators = array_reverse(i18n::get_translators(), true);
     // Make sure to include base translations
     i18n::include_by_locale($lang);
     foreach ($translators as $priority => $translators) {
         foreach ($translators as $name => $translator) {
             /* @var $adapter Zend_Translate_Adapter */
             $adapter = $translator->getAdapter();
             // Load translations from profile
             $filename = $adapter->getFilenameForLocale($lang);
             $filepath = Director::baseFolder() . "/mysite/lang/" . $profileDir . '/' . $filename;
             if ($filename && !file_exists($filepath)) {
                 continue;
             }
             $adapter->addTranslation(array('content' => $filepath, 'locale' => $lang));
         }
     }
 }
Пример #2
0
 public function testRegisterTranslator()
 {
     $translator = new Zend_Translate(array('adapter' => 'i18nTest_CustomTranslatorAdapter', 'disableNotices' => true));
     i18n::register_translator($translator, 'custom', 10);
     $translators = i18n::get_translators();
     $this->assertArrayHasKey('custom', $translators[10]);
     $this->assertInstanceOf('Zend_Translate', $translators[10]['custom']);
     $this->assertInstanceOf('i18nTest_CustomTranslatorAdapter', $translators[10]['custom']->getAdapter());
     i18n::unregister_translator('custom');
     $translators = i18n::get_translators();
     $this->assertArrayNotHasKey('custom', $translators[10]);
 }
    $country->write();
}
// write country ZW
if (!SilvercartCountry::get()->filter("ISO2", "ZW")->exists()) {
    $country = new SilvercartCountry();
    $country->ISO2 = "ZW";
    $country->ISO3 = "ZWE";
    $country->FIPS = "ZI";
    $country->ISON = "716";
    $country->Title = _t("SilvercartCountry.TITLE_ZW");
    $country->Continent = "AF";
    $country->Currency = "ZWL";
    $country->Locale = Translatable::get_current_locale();
    $country->write();
}
$translatorsByPrio = i18n::get_translators();
foreach ($translatorsByPrio as $priority => $translators) {
    foreach ($translators as $name => $translator) {
        $adapter = $translator->getAdapter();
        $languages = $adapter->getList();
        foreach ($languages as $language) {
            $locale = i18n::get_locale_from_lang($language);
            if ($country->hasLanguage($locale)) {
                continue;
            }
            $data = $adapter->getMessages($language);
            foreach (SilvercartCountry::get() as $country) {
                $key = 'TITLE_' . strtoupper($country->ISO2);
                if (array_key_exists('SilvercartCountry.' . $key, $data)) {
                    $translation = new SilvercartCountryLanguage();
                    $translation->Locale = $locale;