diff options
author | Brion Vibber <brion@pobox.com> | 2010-03-10 09:55:14 -0800 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-03-10 09:55:14 -0800 |
commit | ddb656fcd2a3233b26e28987d2f3425944908d30 (patch) | |
tree | ee78cf1bbf7ab8b9713708420c7197634f7ca92a /lib/util.php | |
parent | 49f1b1e8b290de22381a0e25b2b612bd6ddaf79d (diff) | |
parent | 58fcb5ac6f91d30a25a4fa03ba87855923c35828 (diff) |
Merge branch 'testing' into 0.9.x
Conflicts:
actions/apistatusnetconfig.php
Diffstat (limited to 'lib/util.php')
-rw-r--r-- | lib/util.php | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/lib/util.php b/lib/util.php index c5dacb699..a30d69100 100644 --- a/lib/util.php +++ b/lib/util.php @@ -52,17 +52,43 @@ function common_init_language() { mb_internal_encoding('UTF-8'); - // gettext seems very picky... We first need to setlocale() - // to a locale which _does_ exist on the system, and _then_ - // we can set in another locale that may not be set up - // (say, ga_ES for Galego/Galician) it seems to take it. - common_init_locale("en_US"); - // Note that this setlocale() call may "fail" but this is harmless; // gettext will still select the right language. $language = common_language(); $locale_set = common_init_locale($language); + if (!$locale_set) { + // The requested locale doesn't exist on the system. + // + // gettext seems very picky... We first need to setlocale() + // to a locale which _does_ exist on the system, and _then_ + // we can set in another locale that may not be set up + // (say, ga_ES for Galego/Galician) it seems to take it. + // + // For some reason C and POSIX which are guaranteed to work + // don't do the job. en_US.UTF-8 should be there most of the + // time, but not guaranteed. + $ok = common_init_locale("en_US"); + if (!$ok) { + // Try to find a complete, working locale... + // @fixme shelling out feels awfully inefficient + // but I don't think there's a more standard way. + $all = `locale -a`; + foreach (explode("\n", $all) as $locale) { + if (preg_match('/\.utf[-_]?8$/i', $locale)) { + $ok = setlocale(LC_ALL, $locale); + if ($ok) { + break; + } + } + } + if (!$ok) { + common_log(LOG_ERR, "Unable to find a UTF-8 locale on this system; UI translations may not work."); + } + } + $locale_set = common_init_locale($language); + } + setlocale(LC_CTYPE, 'C'); // So we do not have to make people install the gettext locales $path = common_config('site','locale_path'); @@ -133,6 +159,11 @@ function common_munge_password($password, $id) function common_check_user($nickname, $password) { + // empty nickname always unacceptable + if (empty($nickname)) { + return false; + } + $authenticatedUser = false; if (Event::handle('StartCheckPassword', array($nickname, $password, &$authenticatedUser))) { |