Exemplo n.º 1
0
/**
 * Cron script to list unused, but defined, language variables
 * @package chamilo.cron.lang
 */
/**
 * Includes and declarations
 */
//die();
require_once '../../inc/global.inc.php';
$path = api_get_path(SYS_LANG_PATH) . 'english';
ini_set('memory_limit', '128M');
/**
 * Main code
 */
$terms = array();
$list = SubLanguageManager::get_lang_folder_files_list($path);
$langs = scandir(api_get_path(SYS_LANG_PATH));
foreach ($langs as $lang) {
    $dir = api_get_path(SYS_LANG_PATH) . $lang;
    if (is_dir($dir) && substr($lang, 0, 1) != '.' && !empty($lang)) {
        echo "{$lang}...";
        $ok = true;
        foreach ($list as $entry) {
            $file = $dir . '/' . $entry;
            $out = array();
            if (is_file($file)) {
                //$terms = array_merge($terms,SubLanguageManager::get_all_language_variable_in_file($file,true));
                @exec('php5 -l ' . $file, $out);
                if (substr($out[0], 0, 2) != 'No') {
                    echo $out[0] . "\n";
                    $ok = false;
Exemplo n.º 2
0
// setting the name of the tool
$tool_name = get_lang('CreateSubLanguage');
// setting breadcrumbs
$interbreadcrumb[] = array('url' => Container::getRouter()->generate('administration'), 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'languages.php', 'name' => get_lang('PlatformLanguages'));
$sublanguage_folder_error = false;
if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
    $language_name = SubLanguageManager::get_name_of_language_by_id($_GET['id']);
    $sub_language_name = SubLanguageManager::get_name_of_language_by_id($_GET['sub_language_id']);
    $all_data_of_language = SubLanguageManager::get_all_information_of_language($_GET['id']);
    $all_data_of_sublanguage = SubLanguageManager::get_all_information_of_language($_GET['sub_language_id']);
    $sub_language_file = api_get_path(SYS_LANG_PATH) . $all_data_of_sublanguage['dokeos_folder'];
    if (!file_exists($sub_language_file) || !is_writable($sub_language_file)) {
        $sublanguage_folder_error = $sub_language_file . ' ' . get_lang('IsNotWritable');
    }
    if (SubLanguageManager::check_if_exist_language_by_id($_GET['id']) === true) {
        $language_id_exist = true;
    } else {
        $language_id_exist = false;
    }
} else {
    $language_name = '';
    $language_id_exist = false;
}
$intro = sprintf(get_lang('RegisterTermsOfSubLanguageForX'), strtolower($sub_language_name));
$path_folder = api_get_path(SYS_LANG_PATH) . $all_data_of_language['dokeos_folder'];
if (!is_dir($path_folder) || strlen($all_data_of_language['dokeos_folder']) == 0) {
    api_not_allowed(true);
}
Display::display_header($language_name);
echo '<div class="actions-message" >';
 * Includes and declarations
 */
die;
require_once '../../inc/global.inc.php';
require_once api_get_path(SYS_CODE_PATH) . 'admin/sub_language.class.php';
$path = api_get_path(SYS_LANG_PATH) . 'english';
ini_set('memory_limit', '128M');
/**
 * Main code
 */
$terms = array();
$list = SubLanguageManager::get_lang_folder_files_list($path);
foreach ($list as $entry) {
    $file = $path . '/' . $entry;
    if (is_file($file)) {
        $terms = array_merge($terms, SubLanguageManager::get_all_language_variable_in_file($file, true));
    }
}
// get only the array keys (the language variables defined in language files)
$defined_terms = array_flip(array_keys($terms));
$terms = null;
echo count($defined_terms) . " terms were found in language files<br />";
// now get all terms found in all PHP files of Chamilo (this takes some
// time and memory)
$used_terms = array();
$l = strlen(api_get_path(SYS_PATH));
$files = get_all_php_files(api_get_path(SYS_PATH));
// Browse files
foreach ($files as $file) {
    //echo 'Analyzing '.$file."<br />";
    $shortfile = substr($file, $l);
Exemplo n.º 4
0
 * Code
 */
if (isset($new_language) && isset($language_variable) && isset($file_id)) {
    $file_language = $language_files_to_load[$file_id] . '.inc.php';
    $id_language = intval($_REQUEST['id']);
    $sub_language_id = intval($_REQUEST['sub']);
    $all_data_of_language = SubLanguageManager::get_all_information_of_sub_language($id_language, $sub_language_id);
    $path_folder = api_get_path(SYS_LANG_PATH) . $all_data_of_language['dokeos_folder'] . '/' . $file_language;
    $all_file_of_directory = SubLanguageManager::get_all_language_variable_in_file($path_folder);
    $return_value = SubLanguageManager::add_file_in_language_directory($path_folder);
    //update variable language
    $new_language = str_replace('"', '\\"', $new_language);
    $all_file_of_directory[$language_variable] = "\"" . api_convert_encoding($new_language, api_get_system_encoding(), 'UTF-8') . "\";";
    $result_array = array();
    foreach ($all_file_of_directory as $key_value => $value_info) {
        $result_array[$key_value] = SubLanguageManager::write_data_in_file($path_folder, $value_info, $key_value);
    }
    $variables_with_problems = '';
    if (!empty($result_array)) {
        foreach ($result_array as $key => $result) {
            if ($result == false) {
                $variables_with_problems .= $key . ' <br />';
            }
        }
    }
    if (!empty($variables_with_problems)) {
        echo $path_folder . ' ' . get_lang('IsNotWritable') . '<br /> ' . api_ucwords(get_lang('ErrorsFound')) . ': <br />' . $variables_with_problems;
    } else {
        echo get_lang('Saved');
    }
}
Exemplo n.º 5
0
 /**
  * Remove directory for sub-language
  * @param String The sub-language path directory ( e.g. 'spanish_corporate'' )
  * @return boolean  True on success, false on failure
  */
 public static function remove_language_directory($sub_language_dir)
 {
     if (empty($sub_language_dir)) {
         return false;
     }
     $dir = api_get_path(SYS_LANG_PATH) . $sub_language_dir;
     if (!is_dir($dir)) {
         return true;
     }
     //even if the dir does not exist, we reach the objective of not having the directory there
     $content = SubLanguageManager::get_lang_folder_files_list($dir);
     if (count($content) > 0) {
         foreach ($content as $value_content) {
             $path_file = $dir . '/' . $value_content;
             unlink($path_file);
         }
         return @rmdir($dir);
     } else {
         return @rmdir($dir);
     }
 }
Exemplo n.º 6
0
    } else {
        if (isset($_course['language'])) {
            $language_interface = $_course['language'];
        }
    }
}
// Sometimes the variable $language_interface is changed
// temporarily for achieving translation in different language.
// We need to save the genuine value of this variable and
// to use it within the function get_lang(...).
$language_interface_initial_value = $language_interface;
/**
 * Include the trad4all language file
 */
// if the sub-language feature is on
$parent_path = SubLanguageManager::get_parent_language_path($language_interface);
if (!empty($parent_path)) {
    // include English
    include $langpath . 'english/trad4all.inc.php';
    // prepare string for current language and its parent
    $lang_file = $langpath . $language_interface . '/trad4all.inc.php';
    $parent_lang_file = $langpath . $parent_path . '/trad4all.inc.php';
    // load the parent language file first
    if (file_exists($parent_lang_file)) {
        include $parent_lang_file;
    }
    // overwrite the parent language translations if there is a child
    if (file_exists($lang_file)) {
        include $lang_file;
    }
} else {
Exemplo n.º 7
0
 $allow_delete_sub_language = null;
 $allow_add_term_sub_language = null;
 if (api_get_setting('allow_use_sub_language') == 'true') {
     $verified_if_is_sub_language = SubLanguageManager::check_if_language_is_sub_language($row['id']);
     if ($verified_if_is_sub_language === false) {
         $verified_if_is_father = SubLanguageManager::check_if_language_is_father($row['id']);
         $allow_use_sub_language = "&nbsp;<a href='sub_language_add.php?action=definenewsublanguage&id=" . $row['id'] . "'>" . Display::return_icon('new_language.png', get_lang('CreateSubLanguage'), array(), ICON_SIZE_SMALL) . "</a>";
         if ($verified_if_is_father === true) {
             //$allow_add_term_sub_language = "&nbsp;<a href='sub_language.php?action=registersublanguage&id=".$row['id']."'>".Display::return_icon('2rightarrow.gif', get_lang('AddWordForTheSubLanguage'),array('width'=>ICON_SIZE_SMALL,'height'=>ICON_SIZE_SMALL))."</a>";
             $allow_add_term_sub_language = '';
         } else {
             $allow_add_term_sub_language = '';
         }
     } else {
         $allow_use_sub_language = '';
         $all_information_of_sub_language = SubLanguageManager::get_all_information_of_language($row['id']);
         $allow_add_term_sub_language = "&nbsp;<a href='sub_language.php?action=registersublanguage&id=" . Security::remove_XSS($all_information_of_sub_language['parent_id']) . "&sub_language_id=" . Security::remove_XSS($row['id']) . "'>" . Display::return_icon('2rightarrow.gif', get_lang('AddWordForTheSubLanguage'), array('width' => ICON_SIZE_SMALL, 'height' => ICON_SIZE_SMALL)) . "</a>";
         $allow_delete_sub_language = "&nbsp;<a href='sub_language_add.php?action=deletesublanguage&id=" . Security::remove_XSS($all_information_of_sub_language['parent_id']) . "&sub_language_id=" . Security::remove_XSS($row['id']) . "'>" . Display::return_icon('delete.png', get_lang('DeleteSubLanguage'), array('width' => ICON_SIZE_SMALL, 'height' => ICON_SIZE_SMALL)) . "</a>";
     }
 } else {
     $allow_use_sub_language = '';
     $allow_add_term_sub_language = '';
 }
 if ($row['english_name'] == $row_lang['selected_value']) {
     $row_td[] = Display::return_icon('visible.png', get_lang('Visible')) . "<a href='" . api_get_self() . "?action=edit&id=" . $row['id'] . "#value'>" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>\n                     &nbsp;" . $setplatformlanguage . $allow_use_sub_language . $allow_add_term_sub_language . $allow_delete_sub_language;
 } else {
     if ($row['available'] == 1) {
         $row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_" . $row['id'] . "\" href='" . api_get_self() . "?action=makeunavailable&id=" . $row['id'] . "'>" . Display::return_icon('visible.png', get_lang('MakeUnavailable'), array('id' => 'imglinktool_' . $row['id']), ICON_SIZE_SMALL) . "</a> <a href='" . api_get_self() . "?action=edit&id=" . $row['id'] . "#value'>" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>&nbsp;" . $setplatformlanguage . $allow_use_sub_language . $allow_add_term_sub_language . $allow_delete_sub_language;
     } else {
         $row_td[] = "<a class=\"make_visible_and_invisible\" id=\"linktool_" . $row['id'] . "\" href='" . api_get_self() . "?action=makeavailable&id=" . $row['id'] . "'>" . Display::return_icon('invisible.png', get_lang('MakeAvailable'), array('id' => 'imglinktool_' . $row['id']), ICON_SIZE_SMALL) . "</a> <a href='" . api_get_self() . "?action=edit&id=" . $row['id'] . "#value'>" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>&nbsp;" . $setplatformlanguage . $allow_use_sub_language . $allow_add_term_sub_language . $allow_delete_sub_language;
     }
/**
 * Get all information of sub-language
 * @param   int     Parent language ID
 * @param   int     Child language ID
 * @return  array
 */
function allow_get_all_information_of_sub_language($parent_id, $sub_language_id)
{
    return SubLanguageManager::get_all_information_of_sub_language($parent_id, $sub_language_id);
}
Exemplo n.º 9
0
 /**
  * Returns an array of all the language variables with their corresponding
  * file of origin. This function tolerates a certain rate of error due to
  * the duplication of variables in language files.
  * @return array variable => origin file
  */
 public function get_variables_origin()
 {
     require_once '../../admin/sub_language.class.php';
     $path = api_get_path(SYS_LANG_PATH) . 'english/';
     $vars = array();
     $priority = array('trad4all', 'notification', 'accessibility');
     foreach ($priority as $file) {
         $list = SubLanguageManager::get_all_language_variable_in_file($path . $file . '.inc.php', true);
         foreach ($list as $var => $trad) {
             $vars[$var] = $file . '.inc.php';
         }
     }
     $files = scandir($path);
     foreach ($files as $file) {
         if (substr($file, 0, 1) == '.' or in_array($file, $priority)) {
             continue;
         }
         $list = SubLanguageManager::get_all_language_variable_in_file($path . $file, true);
         foreach ($list as $var => $trad) {
             $vars[$var] = $file;
         }
     }
     return $vars;
 }
/**
 * Returns a translated (localized) string, called by its identificator.
 * @param string $variable				This is the identificator (name) of the translated string to be retrieved.
 * @param string $reserved				This parameter has been reserved for future use.
 * @param string $language (optional)	Language indentificator. If it is omited, the current interface language is assumed.
 * @return string						Returns the requested string in the correspondent language.
 *
 * @author Roan Embrechts
 * @author Patrick Cool
 * @author Ivan Tcholakov, 2009-2010 (caching functionality, additional parameter $language, other adaptations).
 *
 * Notes:
 * 1. If the name of a given language variable has the prefix "lang" it may be omited, i.e. get_lang('Yes') == get_lang('Yes').
 * 2. Untranslated variables might be indicated by special opening and closing tags  -  [=  =]
 * The special tags do not show up in these two cases:
 * - when the system has been switched to "production server mode";
 * - when a special platform setting 'hide_dltt_markup' is set to "true" (the name of this setting comes from history);
 * 3. Translations are created many contributors through using a special tool: Chamilo Translation Application.
 * @link http://translate.chamilo.org/
 */
function get_lang($variable, $reserved = null, $language = null)
{
    global $language_interface, $language_interface_initial_value, $_api_is_translated, $_api_is_translated_call;
    global $used_lang_vars, $_configuration;
    // add language_measure_frequency to your main/inc/conf/configuration.php in order to generate language
    // variables frequency measurements (you can then see them trhough main/cron/lang/langstats.php)
    // The $langstats object is instanciated at the end of main/inc/global.inc.php
    if (isset($_configuration['language_measure_frequency']) && $_configuration['language_measure_frequency'] == 1) {
        require_once api_get_path(SYS_CODE_PATH) . '/cron/lang/langstats.class.php';
        global $langstats;
        $langstats->add_use($variable, '');
    }
    if (!isset($used_lang_vars)) {
        $used_lang_vars = array();
    }
    // Caching results from some API functions, for speed.
    static $initialized, $encoding, $is_utf8_encoding, $langpath, $test_server_mode, $show_special_markup;
    if (!isset($initialized)) {
        $encoding = api_get_system_encoding();
        $is_utf8_encoding = api_is_utf8($encoding);
        $langpath = api_get_path(SYS_LANG_PATH);
        $test_server_mode = api_get_setting('server_type') == 'test';
        $show_special_markup = api_get_setting('hide_dltt_markup') != 'true' || $test_server_mode;
        $initialized = true;
    }
    // Combining both ways for requesting specific language.
    if (empty($language)) {
        $language = $language_interface;
    }
    $lang_postfix = isset($is_interface_language) && $is_interface_language ? '' : '(' . $language . ')';
    $is_interface_language = $language == $language_interface_initial_value;
    // This is a cache for already translated language variables. By using it, we avoid repetitive translations, gaining speed.
    static $cache;
    // Looking up into the cache for existing translation.
    if (isset($cache[$language][$variable]) && !$_api_is_translated_call) {
        // There is a previously saved translation, returning it.
        //return $cache[$language][$variable];
        $ret = $cache[$language][$variable];
        $used_lang_vars[$variable . $lang_postfix] = $ret;
        return $ret;
    }
    $_api_is_translated = false;
    // There is no cached translation, we have to retrieve it:
    // - from a global variable (the faster way) - on production server mode;
    // - from a local variable after reloading the language files - on test server mode or when requested language is different than the genuine interface language.
    $read_global_variables = $is_interface_language && !$test_server_mode && !$_api_is_translated_call;
    // Reloading the language files when it is necessary.
    if (!$read_global_variables) {
        global $language_files;
        if (isset($language_files)) {
            $parent_language = null;
            if (api_get_setting('allow_use_sub_language') == 'true') {
                require_once api_get_path(SYS_CODE_PATH) . 'admin/sub_language.class.php';
                $parent_language = SubLanguageManager::get_parent_language_path($language);
            }
            if (!is_array($language_files)) {
                if (isset($parent_language)) {
                    @(include "{$langpath}{$parent_language}/{$language_files}.inc.php");
                }
                @(include "{$langpath}{$language}/{$language_files}.inc.php");
            } else {
                foreach ($language_files as &$language_file) {
                    if (isset($parent_language)) {
                        @(include "{$langpath}{$parent_language}/{$language_file}.inc.php");
                    }
                    @(include "{$langpath}{$language}/{$language_file}.inc.php");
                }
            }
        }
    }
    // Translation mode for production servers.
    if (!$test_server_mode) {
        if ($read_global_variables) {
            if (isset($GLOBALS[$variable])) {
                $langvar = $GLOBALS[$variable];
                $_api_is_translated = true;
            } elseif (isset($GLOBALS["lang{$variable}"])) {
                $langvar = $GLOBALS["lang{$variable}"];
                $_api_is_translated = true;
            } else {
                $langvar = $show_special_markup ? SPECIAL_OPENING_TAG . $variable . SPECIAL_CLOSING_TAG : $variable;
            }
        } else {
            if (isset(${$variable})) {
                $langvar = ${$variable};
                $_api_is_translated = true;
            } elseif (isset(${"lang{$variable}"})) {
                $langvar = ${"lang{$variable}"};
                $_api_is_translated = true;
            } else {
                $langvar = $show_special_markup ? SPECIAL_OPENING_TAG . $variable . SPECIAL_CLOSING_TAG : $variable;
            }
        }
        if (empty($langvar) || !is_string($langvar)) {
            $_api_is_translated = false;
            $langvar = $show_special_markup ? SPECIAL_OPENING_TAG . $variable . SPECIAL_CLOSING_TAG : $variable;
        }
        //return $cache[$language][$variable] = $is_utf8_encoding ? $langvar : api_utf8_decode($langvar, $encoding);
        $ret = $cache[$language][$variable] = $is_utf8_encoding ? $langvar : api_utf8_decode($langvar, $encoding);
        $used_lang_vars[$variable . $lang_postfix] = $ret;
        return $ret;
    }
    // Translation mode for test/development servers.
    if (!is_string($variable)) {
        //return $cache[$language][$variable] = SPECIAL_OPENING_TAG.'get_lang(?)'.SPECIAL_CLOSING_TAG;
        $ret = $cache[$language][$variable] = SPECIAL_OPENING_TAG . 'get_lang(?)' . SPECIAL_CLOSING_TAG;
        $used_lang_vars[$variable . $lang_postfix] = $ret;
        return $ret;
    }
    if (isset(${$variable})) {
        $langvar = ${$variable};
        $_api_is_translated = true;
    } elseif (isset(${"lang{$variable}"})) {
        $langvar = ${"lang{$variable}"};
        $_api_is_translated = true;
    } else {
        $langvar = $show_special_markup ? SPECIAL_OPENING_TAG . $variable . SPECIAL_CLOSING_TAG : $variable;
    }
    if (empty($langvar) || !is_string($langvar)) {
        $_api_is_translated = false;
        $langvar = $show_special_markup ? SPECIAL_OPENING_TAG . $variable . SPECIAL_CLOSING_TAG : $variable;
    }
    //return $cache[$language][$variable] = $is_utf8_encoding ? $langvar : api_utf8_decode($langvar, $encoding);
    $ret = $cache[$language][$variable] = $is_utf8_encoding ? $langvar : api_utf8_decode($langvar, $encoding);
    $used_lang_vars[$variable . $lang_postfix] = $ret;
    return $ret;
}