aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/session.php
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2008-08-31 21:47:26 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2008-08-31 21:47:26 +0000
commit54af1cb64a83b1ed41cac22b248428431ecfe523 (patch)
tree1ddc909a4d8205ec5e1c6ea1553ffa9d7323bc10 /phpBB/includes/session.php
parent5903066d45815804a7329d193bf27f6f03eaffc9 (diff)
downloadforums-54af1cb64a83b1ed41cac22b248428431ecfe523.tar
forums-54af1cb64a83b1ed41cac22b248428431ecfe523.tar.gz
forums-54af1cb64a83b1ed41cac22b248428431ecfe523.tar.bz2
forums-54af1cb64a83b1ed41cac22b248428431ecfe523.tar.xz
forums-54af1cb64a83b1ed41cac22b248428431ecfe523.zip
nullar/singular/plural substitution support. At the moment only the added language entry supports this... we may change other language entries later to support this new "approach". Idea from SHS` and Ashe originally.
More to come... (yes, 3.0.x branch, no mistake) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8800 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/session.php')
-rw-r--r--phpBB/includes/session.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php
index f7a734abda..4e96e10ede 100644
--- a/phpBB/includes/session.php
+++ b/phpBB/includes/session.php
@@ -1792,6 +1792,72 @@ class user extends session
}
/**
+ * More advanced language substitution
+ * Function to mimic sprintf() with the possibility of using phpBB's language system to substitute nullar/singular/plural forms.
+ * Params are the language key and the parameters to be substituted.
+ * This function/functionality is inspired by SHS` and Ashe.
+ *
+ * Example call: <samp>$user->lang('NUM_POSTS_IN_QUEUE', 1);</samp>
+ */
+ function lang()
+ {
+ $args = func_get_args();
+ $key = $args[0];
+
+ // Return if language string does not exist
+ if (!isset($this->lang[$key]) || (!is_string($this->lang[$key]) && !is_array($this->lang[$key])))
+ {
+ return $key;
+ }
+
+ // If the language entry is a string, we simply mimic sprintf() behaviour
+ if (is_string($this->lang[$key]))
+ {
+ if (sizeof($args) == 1)
+ {
+ return $this->lang[$key];
+ }
+
+ // Replace key with language entry and simply pass along...
+ $args[0] = $this->lang[$key];
+ return call_user_func_array('sprintf', $args);
+ }
+
+ // It is an array... now handle different nullar/singular/plural forms
+ $key_found = false;
+
+ // We now get the first number passed and will select the key based upon this number
+ for ($i = 1, $num_args = sizeof($args); $i < $num_args; $i++)
+ {
+ if (is_int($args[$i]))
+ {
+ $numbers = array_keys($this->lang[$key]);
+
+ foreach ($numbers as $num)
+ {
+ if ($num > $args[$i])
+ {
+ break;
+ }
+
+ $key_found = $num;
+ }
+ }
+ }
+
+ // Ok, let's check if the key was found, else use the last entry (because it is mostly the plural form)
+ if ($key_found === false)
+ {
+ $numbers = array_keys($this->lang[$key]);
+ $key_found = end($numbers);
+ }
+
+ // Use the language string we determined and pass it to sprintf()
+ $args[0] = $this->lang[$key][$key_found];
+ return call_user_func_array('sprintf', $args);
+ }
+
+ /**
* Add Language Items - use_db and use_help are assigned where needed (only use them to force inclusion)
*
* @param mixed $lang_set specifies the language entries to include