diff options
author | Dries Buytaert <dries@buytaert.net> | 2004-08-11 11:26:20 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2004-08-11 11:26:20 +0000 |
commit | 1831e1b690f02d7f551d38ef88a0ba200f786497 (patch) | |
tree | cc3805acedb24888afbd7cd76129e690c0c81d0e /includes/common.inc | |
parent | 8517e17e70db3d80410a9020d378587f93e74d14 (diff) | |
download | brdo-1831e1b690f02d7f551d38ef88a0ba200f786497.tar.gz brdo-1831e1b690f02d7f551d38ef88a0ba200f786497.tar.bz2 |
- New locale module thanks to Gerhard, Goba, Marco, Kristjan and others.
The new locale module provides every functionality on the web interface, so you don't need to edit the configuration files or add columns, when you add a new language. This module is an integration of the old locale and localegettext modules, plus a bunch of logic to parse Gettext Portable Object files (opposed to Machine Object files, as supported by localegettext).
Note: I made some minor changes to the context-sensitive help texts and to some of the status messages.
Diffstat (limited to 'includes/common.inc')
-rw-r--r-- | includes/common.inc | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/includes/common.inc b/includes/common.inc index 209769c8f..d5eb1d1f3 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -505,8 +505,15 @@ function message_na() { /** * Initialize the localization system. */ -function locale_init() { - global $languages, $user; +function locale_initialize() { + global $user; + if (function_exists('locale')) { + $languages = locale_supported_languages(); + $languages = $languages['name']; + } + else { + $languages = array(); + } if ($user->uid && $languages[$user->language]) { return $user->language; } @@ -540,9 +547,10 @@ function locale_init() { * The translated string. */ function t($string, $args = 0) { - global $languages; - - $string = ($languages && module_exist('locale') ? locale($string) : $string); + global $locale; + if (function_exists('locale') && $locale != 'en') { + $string = locale($string); + } if (!$args) { return $string; @@ -841,7 +849,23 @@ function format_rss_item($title, $link, $description, $args = array()) { * A translated string. */ function format_plural($count, $singular, $plural) { - return t($count == 1 ? $singular : $plural, array('%count' => $count)); + if ($count == 1) return t($singular); + + // get the plural index through the gettext formula + $index = (function_exists('locale')) ? locale_get_plural($count) : -1; + if ($index < 0) { // backward compatibility + return t($plural, array("%count" => $count)); + } + else { + switch ($index) { + case "0": + return t($singular); + case "1": + return t($plural, array("%count" => $count)); + default: + return t(strtr($plural, array("%count" => '%count['. $index .']')), array('%count['. $index .']' => $count)); + } + } } /** @@ -1814,7 +1838,7 @@ if ($_REQUEST && !user_access('bypass input data check')) { } // initialize localization system: -$locale = locale_init(); +$locale = locale_initialize(); // initialize theme: $theme = init_theme(); |