summaryrefslogtreecommitdiff
path: root/lib/util.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-04-30 13:15:53 -0700
committerBrion Vibber <brion@pobox.com>2010-04-30 13:16:13 -0700
commitcae1329f3bca1f5f1fbfdb1d96b38cbb790fbe00 (patch)
tree21ae74d08b6496c7d7fafbe95a9b147a9ac56cc0 /lib/util.php
parent5c05cd2b1a93d360bde7cb7dfc9ba39e5a5a7624 (diff)
parentf8883367184e4fd31dc819d5e1257d0eee11eb10 (diff)
Merge branch '0.9.x' into 1.0.x
Conflicts: lib/util.php
Diffstat (limited to 'lib/util.php')
-rw-r--r--lib/util.php35
1 files changed, 32 insertions, 3 deletions
diff --git a/lib/util.php b/lib/util.php
index 1f3aaf711..e7ea9df61 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -41,11 +41,13 @@ function common_init_locale($language=null)
}
putenv('LANGUAGE='.$language);
putenv('LANG='.$language);
- return setlocale(LC_ALL, $language . ".utf8",
+ $ok = setlocale(LC_ALL, $language . ".utf8",
$language . ".UTF8",
$language . ".utf-8",
$language . ".UTF-8",
$language);
+
+ return $ok;
}
function common_init_language()
@@ -89,6 +91,32 @@ function common_init_language()
$locale_set = common_init_locale($language);
}
+ common_init_gettext();
+}
+
+/**
+ * @access private
+ */
+function common_init_gettext()
+{
+ setlocale(LC_CTYPE, 'C');
+ // So we do not have to make people install the gettext locales
+ $path = common_config('site','locale_path');
+ bindtextdomain("statusnet", $path);
+ bind_textdomain_codeset("statusnet", "UTF-8");
+ textdomain("statusnet");
+}
+
+/**
+ * Switch locale during runtime, and poke gettext until it cries uncle.
+ * Otherwise, sometimes it doesn't actually switch away from the old language.
+ *
+ * @param string $language code for locale ('en', 'fr', 'pt_BR' etc)
+ */
+function common_switch_locale($language=null)
+{
+ 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');
@@ -97,6 +125,7 @@ function common_init_language()
textdomain("statusnet");
}
+
function common_timezone()
{
if (common_logged_in()) {
@@ -826,7 +855,7 @@ function common_linkify($url) {
return XMLStringer::estring('a', $attrs, $url);
}
-function common_shorten_links($text)
+function common_shorten_links($text, $always = false)
{
common_debug("common_shorten_links() called");
@@ -836,7 +865,7 @@ function common_shorten_links($text)
common_debug("maxLength = $maxLength");
- if (mb_strlen($text) > $maxLength) {
+ if ($always || mb_strlen($text) > $maxLength) {
common_debug("Forcing shortening");
return common_replace_urls_callback($text, array('File_redirection', 'forceShort'));
} else {