Example #1
0
function translation_editor_plugins_boot_event()
{
    global $CONFIG;
    run_function_once("translation_editor_version_053");
    // add the custom_keys_locations to language paths
    $custom_keys_path = $CONFIG->dataroot . "translation_editor" . DIRECTORY_SEPARATOR . "custom_keys" . DIRECTORY_SEPARATOR;
    if (is_dir($custom_keys_path)) {
        $CONFIG->language_paths[$custom_keys_path] = true;
    }
    // force creation of static to prevent reload of unwanted translations
    reload_all_translations();
    translation_editor_load_custom_languages();
    if (elgg_get_context() != "translation_editor") {
        // remove disabled languages
        translation_editor_unregister_translations();
    }
    // load custom translations
    $user_language = get_current_language();
    $elgg_default_language = "en";
    $load_languages = array($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);
        }
    }
}
Example #2
0
/**
 * 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);
        }
    }
}
<?php

/**
 * Provide a way of setting your language prefs
 *
 * @package Elgg
 * @subpackage Core
 */
$user = elgg_get_page_owner_entity();
if (!$user instanceof ElggUser) {
    return;
}
translation_editor_unregister_translations();
$translations = get_installed_translations();
$value = $user->language;
if (empty($value)) {
    $value = elgg_get_config('language');
}
if (count($translations) > 1) {
    // there are languages to choose from
    $title = elgg_echo('user:set:language');
    $body = elgg_echo('user:language:label');
    $body .= elgg_view('input/select', ['name' => 'language', 'value' => $value, 'options_values' => $translations, 'class' => 'mlm']);
    echo elgg_view_module('info', $title, $body);
} else {
    // only one language available, so set that language
    echo elgg_view('input/hidden', ['name' => 'language', 'value' => $value]);
}