Exemple #1
0
}
$plugin = get_input("plugin");
$languages = array_keys($CONFIG->translations);
if (!($disabled_languages = translation_editor_get_disabled_languages())) {
    $disabled_languages = array();
}
if (!empty($CONFIG->language)) {
    $site_language = $CONFIG->language;
} else {
    $site_language = "en";
}
$body .= elgg_view("translation_editor/language_selector", array("current_language" => $current_language, "plugin" => $plugin, "languages" => $languages, "disabled_languages" => $disabled_languages, "site_language" => $site_language));
if (empty($plugin)) {
    // show plugin list
    elgg_push_breadcrumb(elgg_echo($current_language));
    $plugins = translation_editor_get_plugins($current_language);
    $body .= elgg_view("translation_editor/search", array("current_language" => $current_language, "query" => get_input("q")));
    $body .= elgg_view("translation_editor/plugin_list", array("plugins" => $plugins, "current_language" => $current_language));
} else {
    // show plugin keys
    elgg_push_breadcrumb(elgg_echo($current_language), "translation_editor/" . $current_language);
    elgg_push_breadcrumb($plugin);
    $translation = translation_editor_get_plugin($current_language, $plugin);
    if ($plugin == "custom_keys" && elgg_is_admin_logged_in()) {
        $body .= elgg_view("translation_editor/add_custom_key");
    }
    $body .= elgg_view("translation_editor/plugin_edit", array("plugin" => $plugin, "current_language" => $current_language, "translation" => $translation));
}
// Build page
$page_data = elgg_view_layout('one_column', array('title' => $title_text, 'content' => $body));
echo elgg_view_page($title_text, $page_data);
Exemple #2
0
function translation_editor_search_translation($query, $language = "en")
{
    $result = false;
    $plugins = translation_editor_get_plugins($language);
    $found = array();
    foreach ($plugins as $plugin => $data) {
        if ($translations = translation_editor_get_plugin($language, $plugin)) {
            foreach ($translations["en"] as $key => $value) {
                if (stristr($key, $query) || stristr($value, $query) || array_key_exists($key, $translations["current_language"]) && stristr($translations["current_language"][$key], $query)) {
                    if (!array_key_exists($plugin, $found)) {
                        $found[$plugin] = array("en" => array(), "current_language" => array());
                    }
                    $found[$plugin]["en"][$key] = $value;
                    if (array_key_exists($key, $translations["current_language"])) {
                        $found[$plugin]["current_language"][$key] = $translations["current_language"][$key];
                    }
                }
            }
            if (!empty($found)) {
                $result = $found;
            }
        }
    }
    return $result;
}
/**
 * Search for a translation
 *
 * @param string $query    the text to search for
 * @param string $language the language to search in (defaults to English)
 *
 * @return array|bool
 */
function translation_editor_search_translation($query, $language = 'en')
{
    $plugins = translation_editor_get_plugins($language);
    if (empty($plugins)) {
        return false;
    }
    $found = [];
    foreach ($plugins as $plugin => $data) {
        $translations = translation_editor_get_plugin($language, $plugin);
        if (empty($translations) || empty(elgg_extract('total', $translations))) {
            continue;
        }
        foreach ($translations['en'] as $key => $value) {
            if (stristr($key, $query) || stristr($value, $query) || array_key_exists($key, $translations['current_language']) && stristr($translations['current_language'][$key], $query)) {
                if (!array_key_exists($plugin, $found)) {
                    $found[$plugin] = ['en' => [], 'current_language' => []];
                }
                $found[$plugin]['en'][$key] = $value;
                if (array_key_exists($key, $translations['current_language'])) {
                    $found[$plugin]['current_language'][$key] = $translations['current_language'][$key];
                }
            }
        }
    }
    if (empty($found)) {
        return false;
    }
    return $found;
}