Permalink
Browse files

added getLang() to the CacheLiteFunction Decorator

git-svn-id: http://svn.php.net/repository/pear/packages/Translation2/trunk@246461 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 2419d87 commit aa6f714fce2125395545142dad51c1de0336559b @quipo quipo committed Nov 19, 2007
Showing with 44 additions and 5 deletions.
  1. +39 −0 Decorator/CacheLiteFunction.php
  2. +5 −5 package.xml
@@ -199,6 +199,45 @@ function setCacheOption($name, $value)
$this->cacheLiteFunction->setOption($name, $value);
}
+ // }}}
+ // {{{ getLang()
+
+ /**
+ * get lang info
+ *
+ * Get some extra information about the language (its full name,
+ * the localized error text, ...)
+ *
+ * @param string $langID language ID
+ * @param string $format ['name', 'meta', 'error_text', 'array']
+ *
+ * @return mixed [string | array], depending on $format
+ */
+ function getLang($langID = null, $format = 'name')
+ {
+ $langs = $this->getLangs();
+
+ if (is_null($langID)) {
+ if (!isset($this->lang['id']) || !array_key_exists($this->lang['id'], $langs)) {
+ $msg = 'Translation2::getLang(): unknown language "'.$langID.'".'
+ .' Use Translation2::setLang() to set a default language.';
+ return $this->storage->raiseError($msg, TRANSLATION2_ERROR_UNKNOWN_LANG);
+ }
+ $langID = $this->lang['id'];
+ }
+
+ if ($format == 'array') {
+ return $langs[$langID];
+ } elseif (isset($langs[$langID][$format])) {
+ return $langs[$langID][$format];
+ } elseif (isset($langs[$langID]['name'])) {
+ return $langs[$langID]['name'];
+ }
+ $msg = 'Translation2::getLang(): unknown language "'.$langID.'".'
+ .' Use Translation2::setLang() to set a default language.';
+ return $this->storage->raiseError($msg, TRANSLATION2_ERROR_UNKNOWN_LANG);
+ }
+
// }}}
// {{{ getLangs()
View
@@ -45,8 +45,8 @@ Currently, the following decorators are provided:
<email>mike@php.net</email>
<active>yes</active>
</developer>
- <date>2007-11-13</date>
- <time>22:15:30</time>
+ <date>2007-11-19</date>
+ <time>21:31:30</time>
<version>
<release>2.0.0RC2</release>
<api>2.0.0RC2</api>
@@ -63,7 +63,7 @@ Currently, the following decorators are provided:
- bug #12398: fixed return value of addLangToList() and updateLang() in the MDB2
admin container
- request #12405: added removePage() method in the Admin module
-- added getLangs() to the CacheLiteFunction Decorator
+- added getLang() and getLangs() to the CacheLiteFunction Decorator
- fixed the test suite
- fixed Coding Standards
</notes>
@@ -211,7 +211,7 @@ Currently, the following decorators are provided:
<release>beta</release>
<api>beta</api>
</stability>
- <date>2007-11-13</date>
+ <date>2007-11-19</date>
<license uri="http://www.debian.org/misc/bsd.license">BSD</license>
<notes>- request #11711: added setCharset() method in the DB container
- bug #11880: [XML driver] removing one language removes all strings for all languages
@@ -220,7 +220,7 @@ Currently, the following decorators are provided:
- bug #12398: fixed return value of addLangToList() and updateLang() in the MDB2
admin container
- request #12405: added removePage() method in the Admin module
-- added getLangs() to the CacheLiteFunction Decorator
+- added getLang() and getLangs() to the CacheLiteFunction Decorator
- fixed the test suite
- fixed Coding Standards
</notes>

0 comments on commit aa6f714

Please sign in to comment.