Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 55... Línea 55...
55
        } else {
55
        } else {
56
            $stringtofetch = 'locale';
56
            $stringtofetch = 'locale';
57
        }
57
        }
Línea 58... Línea 58...
58
 
58
 
59
        // Store current locale.
59
        // Store current locale.
Línea 60... Línea 60...
60
        $currentlocale = $this->set_locale(LC_ALL, 0);
60
        $currentlocale = $this->get_locale();
Línea 61... Línea 61...
61
 
61
 
62
        $locale = get_string_manager()->get_string($stringtofetch, 'langconfig', $a = null, $langpackcode);
62
        $locale = get_string_manager()->get_string($stringtofetch, 'langconfig', $a = null, $langpackcode);
Línea 77... Línea 77...
77
     * @param int $category Specifying the category of the functions affected by the locale setting.
77
     * @param int $category Specifying the category of the functions affected by the locale setting.
78
     * @param string $locale E.g.: en_AU.utf8, en_GB.utf8, es_ES.utf8, fr_FR.utf8, de_DE.utf8.
78
     * @param string $locale E.g.: en_AU.utf8, en_GB.utf8, es_ES.utf8, fr_FR.utf8, de_DE.utf8.
79
     * @return string|false Returns the new current locale, or FALSE on error.
79
     * @return string|false Returns the new current locale, or FALSE on error.
80
     */
80
     */
81
    protected function set_locale(int $category = LC_ALL, string $locale = '0') {
81
    protected function set_locale(int $category = LC_ALL, string $locale = '0') {
82
        if (strlen($locale) <= 255 || PHP_OS_FAMILY === 'BSD' || PHP_OS_FAMILY === 'Darwin') {
-
 
83
            // We can set the whole locale all together.
-
 
84
            return setlocale($category, $locale);
82
        return \core\locale::set_locale($category, $locale);
85
        }
83
    }
Línea 86... Línea -...
86
 
-
 
-
 
84
 
87
        // Too long locale with linux or windows, let's split it into known and supported categories.
85
    /**
88
        $split = explode(';', $locale);
86
     * Get the current locale.
89
        foreach ($split as $element) {
-
 
90
            [$category, $value] = explode('=', $element);
-
 
91
            if (defined($category)) { // Only if the category exists, there are OS differences.
87
     *
92
                setlocale(constant($category), $value);
88
     * @param int $category
93
            }
89
     * @return string|false
-
 
90
     */
94
        }
91
    protected function get_locale(int $category = LC_ALL): string|false {
95
        return setlocale(LC_ALL, 0); // Finally, return the complete configured locale.
92
        return \core\locale::get_locale($category);
96
    }
93
    }