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); } } }
/** * 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 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(); } } } }
/** * Returns translation data for a specific plugin * * @param string $current_language * @param string $plugin * * @return array || false */ function translation_editor_get_plugin($current_language, $plugin) { global $CONFIG; $result = false; if (!empty($current_language) && !empty($plugin)) { translation_editor_reload_all_translations(); translation_editor_load_translations($current_language); $result = array(); $result["total"] = 0; $backup_full = $CONFIG->translations; $CONFIG->translations = array(); $base_path = $CONFIG->path; if ($plugin == "core") { // Core translation $plugin_language = $base_path . "languages" . DIRECTORY_SEPARATOR . "en.php"; } elseif ($plugin == "custom_keys") { $plugin_language = $CONFIG->dataroot . "translation_editor" . DIRECTORY_SEPARATOR . "custom_keys" . DIRECTORY_SEPARATOR . "en.php"; } else { // Plugin translations $plugin_language = $base_path . "mod" . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR . "languages" . DIRECTORY_SEPARATOR . "en.php"; } // Fetch translations if (file_exists($plugin_language)) { include $plugin_language; unset($CONFIG->translations["en"][""]); $plugin_keys = $CONFIG->translations["en"]; $key_count = count($plugin_keys); if (array_key_exists($current_language, $backup_full)) { $exists_count = $key_count - count(array_diff_key($plugin_keys, $backup_full[$current_language])); } else { $exists_count = 0; } if ($custom_content = translation_editor_read_translation($current_language, $plugin)) { $custom = $custom_content; } else { $custom = array(); } $result["total"] = $key_count; $result["exists"] = $exists_count; $result["en"] = $plugin_keys; $result["current_language"] = array_intersect_key($backup_full[$current_language], $plugin_keys); $result["custom"] = $custom; } $CONFIG->translations = $backup_full; } return $result; }
/** * Returns translation data for a specific plugin * * @param string $current_language which language to return * @param string $plugin for which plugin do you want the translations * * @return fasle|array */ function translation_editor_get_plugin($current_language, $plugin) { if (empty($current_language) || empty($plugin)) { return false; } global $_ELGG; if ($plugin == 'core') { // Core translation $plugin_language = dirname(elgg_get_engine_path()) . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR . 'en.php'; } elseif ($plugin == 'custom_keys') { $plugin_language = elgg_get_data_path() . 'translation_editor' . DIRECTORY_SEPARATOR . 'custom_keys' . DIRECTORY_SEPARATOR . 'en.php'; } else { // plugin translations $plugin_object = elgg_get_plugin_from_id($plugin); if (!$plugin_object instanceof ElggPlugin) { return false; } $plugin_language = $plugin_object->getPath() . 'languages' . DIRECTORY_SEPARATOR . 'en.php'; } translation_editor_reload_all_translations(); translation_editor_load_translations($current_language); $result = ['total' => 0]; $backup_full = $_ELGG->translations; $_ELGG->translations = []; // Fetch translations if (file_exists($plugin_language)) { $plugin_language_array = (include $plugin_language); if (is_array($plugin_language_array)) { add_translation('en', $plugin_language_array); } unset($_ELGG->translations['en']['']); $plugin_keys = $_ELGG->translations['en']; $key_count = count($plugin_keys); if (array_key_exists($current_language, $backup_full)) { $exists_count = $key_count - count(array_diff_key($plugin_keys, $backup_full[$current_language])); } else { $exists_count = 0; } $custom_content = translation_editor_read_translation($current_language, $plugin); if (!empty($custom_content)) { $custom = $custom_content; } else { $custom = []; } $result['total'] = $key_count; $result['exists'] = $exists_count; $result['en'] = $plugin_keys; $result['current_language'] = array_intersect_key($backup_full[$current_language], $plugin_keys); $result['custom'] = $custom; } $_ELGG->translations = $backup_full; return $result; }