Esempio n. 1
0
function translation_editor_version_053()
{
    if ($languages = get_installed_translations()) {
        foreach ($languages as $lang => $name) {
            translation_editor_merge_translations($lang);
        }
    }
}
Esempio n. 2
0
 /**
  * Cleanup all custom translations from keys not present in the original plugin
  *
  * @param string $event  the name of the event
  * @param string $type   the type of the event
  * @param mixed  $object supplied params
  *
  * @return void
  */
 public static function cleanupCustomTranslations($event, $type, $object)
 {
     $base_dir = elgg_get_data_path() . 'translation_editor' . DIRECTORY_SEPARATOR;
     if (!is_dir($base_dir)) {
         // no custom translations
         return;
     }
     $dh = opendir($base_dir);
     if (empty($dh)) {
         // something went wrong
         return;
     }
     while (($language = readdir($dh)) !== false) {
         if (in_array($language, ['.', '..'])) {
             continue;
         }
         $language_dir = $base_dir . $language . DIRECTORY_SEPARATOR;
         if (!is_dir($language_dir)) {
             continue;
         }
         $ldh = opendir($language_dir);
         if (empty($ldh)) {
             continue;
         }
         while (($plugin_file = readdir($ldh)) !== false) {
             $file_path = $language_dir . $plugin_file;
             if (!is_file($file_path)) {
                 continue;
             }
             $plugin_id = basename($file_path, '.json');
             self::cleanupPlugin($language, $plugin_id);
         }
         // merge new translations for this language
         translation_editor_merge_translations($language, true);
         // close $ldh
         closedir($ldh);
     }
     // close $dh
     closedir($dh);
 }
Esempio n. 3
0
function translation_editor_load_translations($current_language = "")
{
    global $CONFIG;
    if (empty($current_language)) {
        $current_language = get_current_language();
    }
    // check if update is needed
    $main_ts = datalist_get("te_last_update_" . $current_language);
    $site_ts = get_private_setting($CONFIG->site_guid, "te_last_update_" . $current_language);
    if (!empty($main_ts)) {
        if (empty($site_ts) || $main_ts > $site_ts) {
            if (translation_editor_merge_translations($current_language)) {
                set_private_setting($CONFIG->site_guid, "te_last_update_" . $current_language, time());
            }
        }
    } else {
        translation_editor_merge_translations($current_language, true);
    }
    // load translations
    if ($translations = translation_editor_read_translation($current_language, "translation_editor_merged_" . $CONFIG->site_guid)) {
        add_translation($current_language, $translations);
    }
}
Esempio n. 4
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);
                } 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 {
                    $json_result["result"] = true;
                }
            }
        }
        // merge translations
        translation_editor_merge_translations($current_language, true);
    } else {
        if (!$jquery) {
            register_error(elgg_echo("translation_editor:action:translate:error:input"));
        }
    }
} else {
    if (!$jquery) {
        register_error(elgg_echo("translation_editor:action:translate:error:not_authorized"));
    }
}
if (!$jquery) {
    forward(REFERER);
} else {
    // Send JSON data
    $json_string = json_encode($json_result);
Esempio n. 6
0
/**
 * Load all the custom translations into the running translations
 *
 * @param string $current_language the language to load (defaults to the language of the current user)
 *
 * @return void
 */
function translation_editor_load_translations($current_language = "")
{
    $site = elgg_get_site_entity();
    if (empty($current_language)) {
        $current_language = get_current_language();
    }
    // check if update is needed
    $main_ts = (int) datalist_get("te_last_update_{$current_language}");
    $site_ts = (int) get_private_setting($site->getGUID(), "te_last_update_{$current_language}");
    if (!empty($main_ts)) {
        if (empty($site_ts) || $main_ts > $site_ts) {
            if (translation_editor_merge_translations($current_language)) {
                set_private_setting($site->getGUID(), "te_last_update_{$current_language}", time());
            }
        }
    } else {
        translation_editor_merge_translations($current_language, true);
    }
    // load translations
    $translations = translation_editor_read_translation($current_language, "translation_editor_merged_{$site->getGUID()}");
    if (!empty($translations)) {
        add_translation($current_language, $translations);
    }
}