jcrodriguez-dis / moodle-mod_vpl

Virtual Programming Lab for Moodle (Module)
GNU General Public License v3.0
97 stars 84 forks source link

Fix jail not setting the right language and using posix instead #185

Open renanpp opened 3 months ago

renanpp commented 3 months ago

Fix for the jail not setting the correct language and for the vpl_get_lang function, so it can get more than one country per language, like pt_BR

jcrodriguez-dis commented 1 month ago

Dear @renanpp,

Thank you for bringing this issue to our attention.

Your proposed pull request effectively resolves some cases of the problem of accommodating multiple countries per language (e.g., pt_BR). However, it might disrupt the correct country assignment for languages associated with only one country or specific to Moodle, like wp or kinds. We will aim to find an optimal solution that combines both approaches in a future release.

Best regards, Juan Carlos

renanpp commented 4 weeks ago

Dear @jcrodriguez-dis,

Indeed my suggestion doesn't fix for all the languages, looking at the supported languages on moodle and the ones in locale.gen maybe it's possible to do something like your approach but mapping the locales with the language select by the user, something like this:

/**
 * @codeCoverageIgnore
 *
 * Get lang code @parm $bashadapt true adapt lang to bash LANG (default true)
 *
 * @return string
 */
function vpl_get_lang($bashadapt = true) {
   global $SESSION, $USER, $CFG;
   $localemapping = [
    'af' => 'af_ZA.UTF-8',
    'am' => 'am_ET UTF-8',
    'an' => 'an_ES.UTF-8 UTF-8',
    'ar' => 'ar_SA.UTF-8',
    'ar_wp' => 'ar_SA.UTF-8',
    'az' => 'az_AZ.UTF-8',
    'bar' => 'de_DE.UTF-8',
    'be' => 'be_BY.UTF-8',
    'bg' => 'bg_BG.UTF-8',
    'bn' => 'bn_IN.UTF-8',
    'ca' => 'ca_ES.UTF-8',
    'ca_valencia' => 'ca_ES.UTF-8',
    'ca_valencia_racv' => 'ca_ES.UTF-8',
    'ca_wp' => 'ca_ES.UTF-8',
    'cs' => 'cs_CZ.UTF-8',
    'cy' => 'cy_GB.UTF-8',
    'da' => 'da_DK.UTF-8',
    'da_kursus' => 'da_DK.UTF-8',
    'da_rum' => 'da_DK.UTF-8',
    'da_wp' => 'da_DK.UTF-8',
    'de' => 'de_DE.UTF-8',
    'de_ch' => 'de_CH.UTF-8',
    'de_comm' => 'de_DE.UTF-8',
    'de_du' => 'de_DE.UTF-8',
    'de_kids' => 'de_DE.UTF-8',
    'de_wp' => 'de_DE.UTF-8',
    'dsb' => 'de_DE.UTF-8',
    'el' => 'el_GR.UTF-8',
    'el_kids' => 'el_GR.UTF-8',
    'el_uni' => 'el_GR.UTF-8',
    'el_wp' => 'el_GR.UTF-8',
    'en' => 'en_US.UTF-8',
    'en_ar' => 'en_US.UTF-8',
    'en_ca' => 'en_CA.UTF-8',
    'en_kids' => 'en_US.UTF-8',
    'en_us' => 'en_US.UTF-8',
    'en_us_k12' => 'en_US.UTF-8',
    'en_us_wp' => 'en_US.UTF-8',
    'en_wp' => 'en_US.UTF-8',
    'es' => 'es_US.UTF-8',
    'es_ar' => 'es_AR.UTF-8',
    'es_co' => 'es_CO.UTF-8',
    'es_mx' => 'es_MX.UTF-8',
    'es_mx_kids' => 'es_MX.UTF-8',
    'es_ve' => 'es_VE.UTF-8',
    'es_wp' => 'en_US.UTF-8',
    'et' => 'et_EE.UTF-8',
    'eu' => 'eu_ES.UTF-8',
    'fa' => 'fa_IR.UTF-8',
    'fi' => 'fi_FI.UTF-8',
    'fi_co' => 'fi_FI.UTF-8',
    'fil' => 'fil_PH.UTF-8',
    'fr' => 'fr_FR.UTF-8',
    'fr_ca' => 'fr_CA.UTF-8',
    'fr_ca_epi' => 'fr_CA.UTF-8',
    'fr_incl' => 'fr_CA.UTF-8',
    'fr_wp' => 'fr_CA.UTF-8',
    'he' => 'he_IL.UTF-8',
    'he_kids' => 'he_IL.UTF-8',
    'he_wp' => 'he_IL.UTF-8',
    'hi' => 'hi_IN.UTF-8',
    'hi_kids' => 'hi_IN.UTF-8',
    'hi_wp' => 'hi_IN.UTF-8',
    'hr' => 'hr_HR.UTF-8',
    'hr_schools' => 'hr_HR.UTF-8',
    'hu' => 'hu_HU.UTF-8',
    'hy' => 'hy_AM.UTF-8',
    'id' => 'id_ID.UTF-8',
    'ig' => 'ig_NG.UTF-8',
    'is' => 'is_IS.UTF-8',
    'it' => 'it_IT.UTF-8',
    'it_wp' => 'it_IT.UTF-8',
    'ja' => 'ja_JP.UTF-8',
    'ja_kids' => 'ja_JP.UTF-8',
    'ja_wp' => 'ja_JP.UTF-8',
    'ka' => 'ka_GE.UTF-8',
    'kk' => 'kk_KZ.UTF-8',
    'km' => 'km_KH.UTF-8',
    'kn' => 'kn_IN.UTF-8',
    'ko' => 'ko_KR.UTF-8',
    'lg' => 'lg_UG.UTF-8',
    'lo' => 'lo_LA.UTF-8',
    'lt' => 'lt_LT.UTF-8',
    'lt_uni' => 'lt_LT.UTF-8',
    'lt_wp' => 'lt_LT.UTF-8',
    'lv' => 'lv_LV.UTF-8',
    'lv_wp' => 'lv_LV.UTF-8',
    'mk' => 'mk_MK.UTF-8',
    'ml' => 'ml_IN.UTF-8',
    'mn' => 'mn_MN.UTF-8',
    'mn_mong' => 'mn_Cyrl_MN.UTF-8',
    'mr' => 'mr_IN.UTF-8',
    'ms' => 'ms_MY.UTF-8',
    'my' => 'my_MM.UTF-8',
    'nb' => 'nb_NO.UTF-8',
    'ne' => 'ne_NP.UTF-8',
    'nl' => 'nl_NL.UTF-8',
    'nl_wp' => 'nl_NL.UTF-8',
    'nn' => 'nn_NO.UTF-8',
    'no' => 'no_NO.UTF-8',
    'no_gr' => 'no_NO.UTF-8',
    'no_wp' => 'no_NO.UTF-8',
    'om' => 'om_ET.UTF-8',
    'or' => 'or_IN.UTF-8',
    'pl' => 'pl_PL.UTF-8',
    'pt' => 'pt_PT.UTF-8',
    'pt_br' => 'pt_BR.UTF-8',
    'pt_br_kids' => 'pt_BR.UTF-8',
    'pt_br_uni' => 'pt_BR.UTF-8',
    'pt_br_wp' => 'pt_BR.UTF-8',
    'ro' => 'ro_RO.UTF-8',
    'ro_wp' => 'ro_RO.UTF-8',
    'ru' => 'ru_RU.UTF-8',
    'rw' => 'rw_RW.UTF-8',
    'si' => 'si_LK.UTF-8',
    'sk' => 'sk_SK.UTF-8',
    'sl' => 'sl_SI.UTF-8',
    'sq' => 'sq_AL.UTF-8',
    'sr_cr' => 'sr_SP.UTF-8',
    'sr_lt' => 'sh_SP.UTF-8',
    'sv' => 'sv_SE.UTF-8',
    'sv_wp' => 'sv_SE.UTF-8',
    'sw' => 'sw_KE.UTF-8',
    'ta' => 'ta_IN.UTF-8',
    'ta_lk' => 'ta_IN.UTF-8',
    'te' => 'te_IN.UTF-8',
    'th' => 'th_TH.UTF-8',
    'tl' => 'tl.UTF-8',
    'tr' => 'tr_TR.UTF-8',
    'uk' => 'uk_UA.UTF-8',
    'ur' => 'ur_IN.UTF-8',
    'uz' => 'uz_Cyrl_UZ.UTF-8',
    'vi' => 'vi_VN.UTF-8',
    'wo' => 'fr_CA.UTF-8',
    'yo' => 'yo_NG.UTF-8',
    'zh_cn' => 'zh_CN.UTF-8',
    'zh_cn_wp' => 'zh_CN.UTF-8',
    'zh_tw' => 'zh_TW.UTF-8',
    'zh_tw_wp' => 'zh_TW.UTF-8',
    'zu' => 'zu_ZA.UTF-8',
];

    //Get current language from moodle ex: en_us
    $moodle_lang = current_language();
    if(isset($moodle_lang)){
        if (isset($localemapping[$moodle_lang])) {
            $lang = $localemapping[$moodle_lang];
        }else{
            $lang = 'en_US.UTF-8';
        }
    }else{
            $lang = 'en_US.UTF-8';
    }
    return $lang;

}