/** * This function is executed during the 'plugins_boot' event, before most plugins are initialized * * @return void */ function translation_editor_plugins_boot_event() { // add the custom_keys_locations to language paths $custom_keys_path = elgg_get_data_path() . 'translation_editor' . DIRECTORY_SEPARATOR . 'custom_keys' . DIRECTORY_SEPARATOR; if (is_dir($custom_keys_path)) { register_translations($custom_keys_path); } // force creation of static to prevent reload of unwanted translations reload_all_translations(); if (elgg_in_context('translation_editor') || elgg_in_context('settings') || elgg_in_context('admin')) { translation_editor_reload_all_translations(); } translation_editor_load_custom_languages(); if (!elgg_in_context('translation_editor')) { // remove disabled languages translation_editor_unregister_translations(); } // load custom translations $user_language = get_current_language(); $elgg_default_language = 'en'; $load_languages = [$user_language, $elgg_default_language]; $load_languages = array_unique($load_languages); $disabled_languages = translation_editor_get_disabled_languages(); foreach ($load_languages as $language) { if (empty($disabled_languages) || !in_array($language, $disabled_languages)) { // add custom translations translation_editor_load_translations($language); } } }
function translation_editor_plugins_boot_event() { global $CONFIG; run_function_once("translation_editor_version_053"); // add the custom_keys_locations to language paths $custom_keys_path = $CONFIG->dataroot . "translation_editor" . DIRECTORY_SEPARATOR . "custom_keys" . DIRECTORY_SEPARATOR; if (is_dir($custom_keys_path)) { $CONFIG->language_paths[$custom_keys_path] = true; } // force creation of static to prevent reload of unwanted translations reload_all_translations(); translation_editor_load_custom_languages(); if (elgg_get_context() != "translation_editor") { // remove disabled languages translation_editor_unregister_translations(); } // load custom translations $user_language = get_current_language(); $elgg_default_language = "en"; $load_languages = array($user_language, $elgg_default_language); $load_languages = array_unique($load_languages); $disabled_languages = translation_editor_get_disabled_languages(); foreach ($load_languages as $language) { if (empty($disabled_languages) || !in_array($language, $disabled_languages)) { // add custom translations translation_editor_load_translations($language); } } }
function language_selector_plugins_boot() { global $CONFIG; if (!elgg_is_logged_in()) { if (!empty($_COOKIE['client_language'])) { // switched with language selector $new_lang = $_COOKIE['client_language']; } else { $browserlang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); if (!empty($browserlang)) { // autodetect language if (elgg_get_plugin_setting("autodetect", "language_selector") == "yes") { $new_lang = $browserlang; } } } if (!empty($new_lang) && $new_lang !== $CONFIG->language) { // set new language $CONFIG->language = $new_lang; // language has been change; reload language keys if (elgg_is_active_plugin("translation_editor")) { translation_editor_load_translations(); } else { reload_all_translations(); } } } elgg_extend_view("css/elgg", "language_selector/css/site"); }
/** * Sets the language for the logged out user * * @return void */ function language_selector_set_logged_out_user_language() { global $CONFIG; if (elgg_is_logged_in()) { return; } if (!empty($_COOKIE['client_language'])) { // switched with language selector $new_lang = $_COOKIE['client_language']; } else { $browserlang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); if (!empty($browserlang)) { // autodetect language if (elgg_get_plugin_setting("autodetect", "language_selector") == "yes") { $new_lang = $browserlang; } } } if (!empty($new_lang) && $new_lang !== $CONFIG->language) { $allowed = language_selector_get_allowed_translations(); if (in_array($new_lang, $allowed)) { // set new language $CONFIG->language = $new_lang; // language has been change; reload language keys if (elgg_is_active_plugin("translation_editor")) { translation_editor_load_translations(); } else { reload_all_translations(); } } } }
/** * Return the translation keys missing from a given language, * or those that are identical to the english version. * * @param string $language The language * * @return mixed */ function get_missing_language_keys($language) { global $CONFIG; // Ensure that all possible translations are loaded reload_all_translations(); $missing = array(); foreach ($CONFIG->translations['en'] as $k => $v) { if (!isset($CONFIG->translations[$language][$k]) || $CONFIG->translations[$language][$k] == $CONFIG->translations['en'][$k]) { $missing[] = $k; } } if (count($missing)) { return $missing; } return false; }
/** * Initializes the simplecache lastcache variable and creates system cache files * when appropriate. * * @access private */ function _elgg_cache_init() { global $CONFIG; if (!defined('UPGRADING') && empty($CONFIG->lastcache)) { $CONFIG->lastcache = (int) datalist_get('simplecache_lastupdate'); } // cache system data if enabled and not loaded if ($CONFIG->system_cache_enabled && !$CONFIG->system_cache_loaded) { elgg_save_system_cache('view_locations', serialize($CONFIG->views->locations)); elgg_save_system_cache('view_types', serialize($CONFIG->view_types)); } if ($CONFIG->system_cache_enabled && !$CONFIG->i18n_loaded_from_cache) { reload_all_translations(); foreach ($CONFIG->translations as $lang => $map) { elgg_save_system_cache("{$lang}.lang", serialize($map)); } } }
/** * @access private */ function _elgg_cache_init() { global $CONFIG; $viewtype = elgg_get_viewtype(); // Regenerate the simple cache if expired. // Don't do it on upgrade because upgrade does it itself. // @todo - move into function and perhaps run off init system event if (!defined('UPGRADING')) { $lastupdate = datalist_get("simplecache_lastupdate_{$viewtype}"); $lastcached = datalist_get("simplecache_lastcached_{$viewtype}"); if ($lastupdate == 0 || $lastcached < $lastupdate) { elgg_regenerate_simplecache($viewtype); $lastcached = datalist_get("simplecache_lastcached_{$viewtype}"); } $CONFIG->lastcache = $lastcached; } // cache system data if enabled and not loaded if ($CONFIG->system_cache_enabled && !$CONFIG->system_cache_loaded) { elgg_save_system_cache('view_locations', serialize($CONFIG->views->locations)); elgg_save_system_cache('view_types', serialize($CONFIG->view_types)); } if ($CONFIG->system_cache_enabled && !$CONFIG->i18n_loaded_from_cache) { reload_all_translations(); foreach ($CONFIG->translations as $lang => $map) { elgg_save_system_cache("{$lang}.php", serialize($map)); } } }
/** * @uses $vars['language'] */ $language = elgg_extract('language', $vars); if (empty($language)) { // try to detect it preg_match("/\\/js\\/languages\\/(.*?).js+/", current_page_url(), $matches); if (!empty($matches) && isset($matches[1])) { $language = $matches[1]; } } if (empty($language)) { // fallback to 'en' $language = 'en'; } $all_translations = $GLOBALS['_ELGG']->translations; $translations = $all_translations['en']; if ($language != 'en' && !isset($all_translations[$language])) { // try to reload missing translations reload_all_translations(); $all_translations = $GLOBALS['_ELGG']->translations; } if ($language != 'en' && isset($all_translations[$language])) { $translations = array_merge($translations, $all_translations[$language]); } ?> define(<?php echo json_encode($translations); ?> );