Example #1
0
 function _enableInternationalizationSupport()
 {
     if (AK_AVAILABLE_LOCALES != 'en') {
         require_once AK_LIB_DIR . DS . 'AkLocaleManager.php';
         $LocaleManager = new AkLocaleManager();
         $LocaleManager->init();
         $LocaleManager->initApplicationInternationalization($this);
         $this->__internationalization_support_enabled = true;
     }
 }
Example #2
0
 function test_framework_config_locale_update()
 {
     $langs=Ak::langs();
     $translation_key=Ak::randomString(8);
     $this->assertEqual(Ak::t($translation_key),$translation_key);
     AkLocaleManager::updateLocaleFiles();
     list($locales,$core_dictionary) = AkLocaleManager::getCoreDictionary(AK_FRAMEWORK_LANGUAGE);
     $this->assertTrue(isset($core_dictionary[$translation_key]));
     
     foreach($langs as $lang) {
         list($locales,$core_dictionary) = AkLocaleManager::getCoreDictionary($lang);
         $this->assertTrue(isset($core_dictionary[$translation_key]));
     }
 }
Example #3
0
File: Ak.php Project: joeymetal/v1
 /**
  * Translate strings to the current locale.
  *
  * When using Ak::t(), try to put entire sentences and strings
  * in one Ak::t() call.
  * This makes it easier for translators. HTML markup within
  * translation strings
  * is acceptable, if necessary. The suggested syntax for a
  * link embedded
  * within a translation string is:
  *
  * @access public
  * @static
  * @param    string    $string    A string containing the English string to
  * translate.
  * @param    array    $args    An associative array of replacements to make after
  * translation. Incidences of any key in this array
  * are replaced with the corresponding value.
  * @return string The translated string.
  */
 function t($string, $args = null, $controller = null)
 {
     static $framework_dictionary = array(), $lang, $_dev_shutdown = true;
     if (AK_AUTOMATICALLY_UPDATE_LANGUAGE_FILES && !empty($string) && is_string($string)) {
         require_once AK_LIB_DIR . DS . 'AkLocaleManager.php';
         // This adds used strings to a stack for storing new entries on the locale file after shutdown
         AkLocaleManager::getUsedLanguageEntries($string, $controller);
         if ($_dev_shutdown) {
             register_shutdown_function(array('AkLocaleManager', 'updateLocaleFiles'));
             $_dev_shutdown = false;
         }
     }
     if (!isset($lang)) {
         if (!empty($_SESSION['lang'])) {
             $lang = $_SESSION['lang'];
         } else {
             $lang = Ak::lang();
         }
         if (is_file(AK_CONFIG_DIR . DS . 'locales' . DS . $lang . '.php')) {
             require AK_CONFIG_DIR . DS . 'locales' . DS . $lang . '.php';
             $framework_dictionary = array_merge($framework_dictionary, $dictionary);
         }
         if (!defined('AK_LOCALE')) {
             define('AK_LOCALE', $lang);
         }
         if (!empty($locale) && is_array($locale)) {
             Ak::locale(null, $lang, $locale);
         }
     }
     if (!empty($string) && is_array($string)) {
         if (!empty($string[$lang])) {
             return $string[$lang];
         }
         $try_whith_lang = $args !== false && empty($string[$lang]) ? Ak::base_lang() : $lang;
         if (empty($string[$try_whith_lang]) && $args !== false) {
             foreach (Ak::langs() as $try_whith_lang) {
                 if (!empty($string[$try_whith_lang])) {
                     return $string[$try_whith_lang];
                 }
             }
         }
         return @$string[$try_whith_lang];
     }
     if (isset($controller) && !isset($framework_dictionary[$controller . '_dictionary']) && is_file(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . $lang . '.php')) {
         require AK_APP_DIR . DS . 'locales' . DS . $controller . DS . $lang . '.php';
         $framework_dictionary[$controller . '_dictionary'] = (array) $dictionary;
     }
     if (isset($controller) && isset($framework_dictionary[$controller . '_dictionary'][$string])) {
         $string = $framework_dictionary[$controller . '_dictionary'][$string];
     } else {
         $string = isset($framework_dictionary[$string]) ? $framework_dictionary[$string] : $string;
     }
     if (isset($args) && is_array($args)) {
         $string = @str_replace(array_keys($args), array_values($args), $string);
     }
     /**
      * @todo Prepare for multiple locales by inspecting AK_DEFAULT_LOCALE
      */
     return $string;
 }
Example #4
0
    function suggestLocales()
    {
        require_once(AK_LIB_DIR.DS.'AkLocaleManager.php');

        $LocaleManager = new AkLocaleManager();

        $langs = array('en');
        if(AK_OS === 'WINDOWS'){
            $langs[] = @$_ENV['LANG'];
        }
        $langs = array_merge($langs, $LocaleManager->getBrowserLanguages());

        return array_unique(array_map('strtolower',array_diff($langs,array(''))));
    }
Example #5
0
 /**
  * @todo Refactor this method
  */
 function updateLocaleFiles()
 {
     $new_core_entries = array();
     $new_controller_entries = array();
     $new_controller_files = array();
     $used_entries = AkLocaleManager::getUsedLanguageEntries();
     require AK_CONFIG_DIR . DS . 'locales' . DS . AK_FRAMEWORK_LANGUAGE . '.php';
     $core_dictionary = $dictionary;
     $controllers_dictionaries = array();
     foreach ($used_entries as $k => $v) {
         // This is a controller file
         if (is_array($v)) {
             if (!isset($controllers_dictionaries[$k])) {
                 $controller = $k;
                 $module_lang_file = AK_APP_DIR . DS . 'locales' . DS . $controller . DS . AK_FRAMEWORK_LANGUAGE . '.php';
                 if (is_file($module_lang_file)) {
                     require $module_lang_file;
                     $controllers_dictionaries[$controller] = array_merge((array) $dictionary, (array) $v);
                     $existing_controllers_dictionaries[$controller] = (array) $dictionary;
                 } else {
                     $controllers_dictionaries[$controller] = (array) $v;
                     $new_controller_files[$controller] = $module_lang_file;
                 }
             }
         } else {
             if (!isset($core_dictionary[$k])) {
                 $new_core_entries[$k] = $k;
             }
         }
     }
     $dictionary_file = '';
     foreach ($new_controller_files as $controller => $file_name) {
         $dictionary_file = "<?php\n\n// File created on: " . date("Y-m-d G:i:s", Ak::time()) . "\n\n\$dictionary = array();\n\n";
         foreach ($controllers_dictionaries[$controller] as $k => $entry) {
             $entry = str_replace("'", "\\'", $entry);
             $dictionary_file .= "\n\$dictionary['{$entry}'] = '{$entry}';";
         }
         unset($controllers_dictionaries[$controller]);
         $dictionary_file .= "\n\n\n?>";
         Ak::file_put_contents($file_name, $dictionary_file);
     }
     // Module files
     foreach ((array) $controllers_dictionaries as $controller => $controller_entries) {
         $dictionary_file = '';
         foreach ($controller_entries as $entry) {
             if ($entry == '' || isset($existing_controllers_dictionaries[$controller][$entry])) {
                 continue;
             }
             $entry = str_replace("'", "\\'", $entry);
             $dictionary_file .= "\n\$dictionary['{$entry}'] = '{$entry}';";
         }
         if ($dictionary_file != '') {
             $original_file = Ak::file_get_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . AK_FRAMEWORK_LANGUAGE . '.php');
             $original_file = rtrim($original_file, "?> \n\r");
             $new_entries = "\n\n// " . date("Y-m-d G:i:s", Ak::time()) . "\n\n" . $dictionary_file . "\n\n\n?>\n";
             $dictionary_file = $original_file . $new_entries;
             Ak::file_put_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . AK_FRAMEWORK_LANGUAGE . '.php', $dictionary_file);
             foreach (Ak::langs() as $lang) {
                 if ($lang != AK_FRAMEWORK_LANGUAGE) {
                     $lang_file = @Ak::file_get_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . $lang . '.php');
                     if (empty($lang_file)) {
                         $dictionary_file = $original_file;
                     } else {
                         $lang_file = rtrim($lang_file, "?> \n\r");
                         $dictionary_file = $lang_file;
                     }
                     Ak::file_put_contents(AK_APP_DIR . DS . 'locales' . DS . $controller . DS . $lang . '.php', $dictionary_file . $new_entries);
                 }
             }
         }
     }
     // Core locale files
     $dictionary_file = '';
     foreach ($new_core_entries as $core_entry) {
         if ($core_entry == '') {
             continue;
         }
         $core_entry = str_replace("'", "\\'", $core_entry);
         $dictionary_file .= "\n\$dictionary['{$core_entry}'] = '{$core_entry}';";
     }
     if ($dictionary_file != '') {
         $original_file = Ak::file_get_contents(AK_CONFIG_DIR . DS . 'locales' . DS . AK_FRAMEWORK_LANGUAGE . '.php');
         $original_file = rtrim($original_file, "?> \n\r");
         $new_entries = "\n\n// " . date("Y-m-d G:i:s", Ak::time()) . "\n\n" . $dictionary_file . "\n\n\n?>\n";
         $dictionary_file = $original_file . $new_entries;
         Ak::file_put_contents(AK_CONFIG_DIR . DS . 'locales' . DS . AK_FRAMEWORK_LANGUAGE . '.php', $dictionary_file);
         foreach (Ak::langs() as $lang) {
             if ($lang != AK_FRAMEWORK_LANGUAGE) {
                 $lang_file = Ak::file_get_contents(AK_CONFIG_DIR . DS . 'locales' . DS . $lang . '.php');
                 if (empty($lang_file)) {
                     $dictionary_file = str_replace("\$locale['description'] = 'English';", "\$locale['description'] = '{$lang}';", $original_file);
                 } else {
                     $lang_file = rtrim($lang_file, "?> \n\r");
                     $dictionary_file = $lang_file;
                 }
                 Ak::file_put_contents(AK_CONFIG_DIR . DS . 'locales' . DS . $lang . '.php', $dictionary_file . $new_entries);
             }
         }
     }
 }
Example #6
0
 static function setDictionary($dictionary, $language, $namespace = false, $comment = null)
 {
     $path = AkConfig::getDir('app') . DS . 'locales' . DS . ($namespace ? trim(Ak::sanitize_include($namespace, 'high'), DS) . DS : '') . basename($language) . '.php';
     AkLocaleManager::getDictionary($language, $namespace, true, $dictionary);
     AkFileSystem::file_put_contents($path, "<?php\n/** {$comment} */\n\n\$dictionary=" . var_export((array) $dictionary, true) . ";\n");
     return $path;
 }
Example #7
0
 function __enableInternationalizationSupport()
 {
     require_once AK_LIB_DIR . DS . 'AkLocaleManager.php';
     $LocaleManager = new AkLocaleManager();
     $LocaleManager->init();
     $LocaleManager->initApplicationInternationalization($this->Request);
     $this->__internationalization_support_enabled = true;
 }
Example #8
0
    function expireFragment($key, $options = array())
    {
        if (!$this->cacheConfigured()) return;

        if (is_array($key) && isset($key['lang']) && $key['lang'] == '*') {
            $langs = AkLocaleManager::getPublicLocales();
            $res = true;
            foreach ($langs as $lang) {
                $key['lang'] = $lang;
                $res = $this->expireFragment($key, $options);
            }
            return $res;
        }
        $key = $this->fragmentCachekey($key, $options);

        return $this->_cache_store->remove($key, isset($options['host'])?
        $options['host']:$this->_buildCacheGroup());
    }
Example #9
0
File: Ak.php Project: joeymetal/v1
 /**
 * Untranslate strings from a locale to english.
 *
 * @access public
 * @static
 * @param    string    $string    The string to be untranslated.
 * @param    string    $current_language    A string containing the current language.
 * @return string The untranslated string.
 */
 public static function untranslate($string, $current_language, $namespace = false)
 {
     $dictionary = AkLocaleManager::getDictionary($current_language, $namespace);
     $untranslated_string = array_search($string, $dictionary);
     return $untranslated_string ? $untranslated_string : $string;
 }
Example #10
0
 protected function _enableInternationalizationSupport()
 {
     if (AK_AVAILABLE_LOCALES != 'en') {
         $LocaleManager = new AkLocaleManager();
         $LocaleManager->init();
         $LocaleManager->initApplicationInternationalization($this);
         $this->__internationalization_support_enabled = true;
     }
 }
Example #11
0
 function setDictionary($dictionary,$language,$namespace=false,$comment=null)
 {
     $path = AK_APP_DIR.DS.'locales'.DS.($namespace?trim(Ak::sanitize_include($namespace,'high'),DS).DS:'').basename($language).'.php';
     AkLocaleManager::getDictionary($language,$namespace,true,$dictionary);
     return Ak::file_put_contents($path,"<?php\n/** $comment */\n\n\$dictionary=".var_export((array)$dictionary,true).";\n");
 }
Example #12
0
 public function suggestLocales()
 {
     $LocaleManager = new AkLocaleManager();
     $langs = array('en');
     if (AK_WIN) {
         $langs[] = @$_ENV['LANG'];
     }
     $langs = array_merge($langs, $LocaleManager->getBrowserLanguages());
     return array_unique(array_map('strtolower', array_diff($langs, array(''))));
 }