Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
        }
        // get plugin translation
        $plugin_translation = translation_editor_get_plugin($language, $plugin_name);
        // merge with existing custom translations
        $custom_translation = elgg_extract('custom', $plugin_translation);
        if (!empty($custom_translation)) {
            $translate_input = array_merge($custom_translation, $translate_input);
        }
        // get original plugin keys
        $original_keys = elgg_extract('en', $plugin_translation);
        // only keep keys which are present in the plugin
        $translate_input = array_intersect_key($translate_input, $original_keys);
        // check if translated
        $translated = translation_editor_compare_translations($language, $translate_input);
        if (!empty($translated)) {
            if (translation_editor_write_translation($language, $plugin_name, $translated)) {
                system_message(elgg_echo('translation_editor:action:translate:success'));
            } else {
                register_error(elgg_echo('translation_editor:action:translate:error:write'));
            }
        } else {
            translation_editor_delete_translation($language, $plugin_name);
            system_message(elgg_echo('translation_editor:action:translate:success'));
        }
    }
    // merge translations
    translation_editor_merge_translations($language, true);
}
// invalidate cache
elgg_flush_caches();
forward(REFERER);
Ejemplo n.º 3
0
/**
 * 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;
}
Ejemplo n.º 4
0
$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"));
                    }
                }
            } else {
                translation_editor_delete_translation($current_language, $plugin);
                if (!$jquery) {
                    system_message(elgg_echo("translation_editor:action:translate:no_changed_values"));
                } else {
Ejemplo n.º 5
0
 /**
  * Cleanup the custom translations for one plugin
  *
  * @param string $language  the language to cleanup for
  * @param string $plugin_id the plugin to cleanup
  *
  * @return bool
  */
 protected static function cleanupPlugin($language, $plugin_id)
 {
     if (empty($language) || empty($plugin_id)) {
         return false;
     }
     $translation = translation_editor_get_plugin($language, $plugin_id);
     if ($translation === false) {
         return false;
     }
     $custom = elgg_extract('custom', $translation);
     if (empty($custom)) {
         // no custom translation, how did you get here??
         return true;
     }
     $english = elgg_extract('en', $translation);
     $clean_custom = array_intersect_key($custom, $english);
     $removed_custom = array_diff_key($custom, $clean_custom);
     // report cleaned-up translations
     if (empty($removed_custom)) {
         // nothing removed
         return true;
     } else {
         self::writeCleanupTranslations($language, $plugin_id, $removed_custom);
     }
     // write new custom translation
     if (empty($clean_custom)) {
         // no more custom translations
         translation_editor_delete_translation($language, $plugin_id);
     } else {
         // write new custom translation
         translation_editor_write_translation($language, $plugin_id, $clean_custom);
     }
     return true;
 }