/** * 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_actions_hook($hook, $type, $return, $params) { $allowed_actions = array("admin/plugins/activate", "admin/plugins/deactivate", "admin/plugins/activate_all", "admin/plugins/deactivate_all", "admin/plugins/set_priority", "upgrading"); if (!empty($type) && in_array($type, $allowed_actions)) { // make sure we have all translations translation_editor_reload_all_translations(); if ($languages = get_installed_translations()) { foreach ($languages as $key => $desc) { remove_private_setting(elgg_get_site_entity()->getGUID(), "te_last_update_" . $key); } } } }
function translation_editor_compare_translations($current_language, $translated) { global $CONFIG; $result = false; if (!empty($current_language) && !empty($translated)) { $result = array(); $backup_full = $CONFIG->translations; $CONFIG->translations = array(); translation_editor_reload_all_translations(); foreach ($translated as $key => $value) { $original = clean_line_breaks(trim(html_entity_decode($CONFIG->translations[$current_language][$key], ENT_NOQUOTES, "UTF-8"))); $new = clean_line_breaks(trim(html_entity_decode($value, ENT_NOQUOTES, "UTF-8"))); if ($original != $new && strlen($new) > 0) { $result[$key] = $new; } } $CONFIG->translations = $backup_full; } return $result; }
<?php /** * Add translations for the current plugin */ global $CONFIG; // make sure all languages are loaded translation_editor_reload_all_translations(); // Fixes for KSES filtering // fix to allow javascript in href $CONFIG->allowedprotocols[] = 'javascript'; // fix allowed tags $CONFIG->allowedtags['a']['onclick'] = array(); $CONFIG->allowedtags['span']['id'] = array(); $translation = get_input('translation'); if (!translation_editor_is_translation_editor()) { register_error(elgg_echo('translation_editor:action:translate:error:not_authorized')); forward(); } if (!is_array($translation)) { register_error(elgg_echo('translation_editor:action:translate:error:input')); forward(REFERER); } $trans = get_installed_translations(); foreach ($translation as $language => $plugins) { if (!array_key_exists($language, $trans)) { continue; } if (!is_array($plugins)) { continue; }
/** * Reset the site timestamp that tracks the merged translation status. * * This will recreate the translation editor cache * * @param int $site_guid which site to invalidate (defaults to current site) * * @return void */ function translation_editor_invalidate_site_cache($site_guid = 0) { $site_guid = sanitize_int($site_guid, false); // make sure we have all translations translation_editor_reload_all_translations(); $languages = get_installed_translations(); if (empty($languages) || !is_array($languages)) { return; } $site = elgg_get_site_entity($site_guid); if (empty($site)) { return; } foreach ($languages as $key => $desc) { remove_private_setting($site->getGUID(), "te_last_update_{$key}"); } }