// fix allowed tags $CONFIG->allowedtags["a"]["onclick"] = array(); $CONFIG->allowedtags["span"]["id"] = array(); // get inputs $current_language = get_input("current_language"); $translation = get_input("translation"); $jquery = get_input("jquery", false); // Preparing jQuery result $json_result = array(); $json_result["result"] = false; if (translation_editor_is_translation_editor()) { $trans = get_installed_translations(); if (!empty($current_language) && !empty($translation) && array_key_exists($current_language, $trans)) { foreach ($translation as $plugin => $translate_input) { // merge with existing custom translations if ($custom_translation = translation_editor_read_translation($current_language, $plugin)) { $translate_input = array_merge($custom_translation, $translate_input); } $translated = translation_editor_compare_translations($current_language, $translate_input); if (!empty($translated)) { if (translation_editor_write_translation($current_language, $plugin, $translated)) { if (!$jquery) { system_message(elgg_echo("translation_editor:action:translate:success")); } else { $json_result["result"] = true; } } else { if (!$jquery) { register_error(elgg_echo("translation_editor:action:translate:error:write")); } }
function translation_editor_merge_translations($language = "", $update = false) { global $CONFIG; $result = false; if (empty($language)) { $language = get_current_language(); } if (!empty($language)) { $translations = array(); if ($core = translation_editor_read_translation($language, "core")) { $translations = $core; } if ($custom_keys = translation_editor_read_translation($language, "custom_keys")) { $translations += $custom_keys; } if ($plugins = elgg_get_plugins()) { foreach ($plugins as $plugin) { if ($plugin_translation = translation_editor_read_translation($language, $plugin->title)) { $translations += $plugin_translation; } } } if (!empty($translations)) { if (translation_editor_write_translation($language, "translation_editor_merged_" . $CONFIG->site_guid, $translations)) { $result = true; } } else { if (translation_editor_delete_translation($language, "translation_editor_merged_" . $CONFIG->site_guid)) { $result = true; } } } if ($result) { elgg_trigger_event("language:merge", "translation_editor", $language); } // reset language cache on all sites if ($update) { $ts = time(); datalist_set("te_last_update_" . $language, $ts); set_private_setting($CONFIG->site_guid, "te_last_update_" . $language, $ts); } return $result; }
/** * Merge all custom translations into a single file for performance * * @param string $language the language to merge * @param bool $update force and update to other sites * * @return bool */ function translation_editor_merge_translations($language = "", $update = false) { $result = false; $site = elgg_get_site_entity(); if (empty($language)) { $language = get_current_language(); } if (!empty($language)) { $translations = array(); // get core translations $core = translation_editor_read_translation($language, 'core'); if (!empty($core)) { $translations = $core; } // get the customo keys $custom_keys = translation_editor_read_translation($language, 'custom_keys'); if (!empty($custom_keys)) { $translations += $custom_keys; } // proccess all plugins $plugins = elgg_get_plugins(); if (!empty($plugins)) { foreach ($plugins as $plugin) { // add plugin translations $plugin_translation = translation_editor_read_translation($language, $plugin->title); if (!empty($plugin_translation)) { $translations += $plugin_translation; } } } if (!empty($translations)) { // write all to disk if (translation_editor_write_translation($language, "translation_editor_merged_{$site->getGUID()}", $translations)) { $result = true; } } else { // no custom translations, so remove the cache file if (translation_editor_delete_translation($language, "translation_editor_merged_{$site->getGUID()}")) { $result = true; } } } if ($result) { // clear system cache $cache = elgg_get_system_cache(); $cache->delete("{$language}.lang"); // let others know this happend elgg_trigger_event("language:merge", "translation_editor", $language); } // reset language cache on all sites if ($update) { $ts = time(); datalist_set("te_last_update_{$language}", $ts); set_private_setting($site->getGUID(), "te_last_update_{$language}", $ts); } return $result; }