Permalink
Browse files

Adding $language parameter to I18n::translate()

  • Loading branch information...
1 parent 08825e5 commit 30522d0219cffeaa1bde068bd492e4d4d751c869 @ADmad ADmad committed Nov 19, 2011
Showing with 10 additions and 6 deletions.
  1. +10 −6 lib/Cake/I18n/I18n.php
View
@@ -89,8 +89,7 @@ class I18n {
protected $_noLocale = false;
/**
- * Set to true when I18N::_bindTextDomain() is called for the first time.
- * If a translation file is found it is set to false again
+ * Translation categories
*
* @var array
*/
@@ -129,9 +128,11 @@ public static function &getInstance() {
* @param string $domain Domain The domain of the translation. Domains are often used by plugin translations
* @param string $category Category The integer value of the category to use.
* @param integer $count Count Count is used with $plural to choose the correct plural form.
+ * @param string $language Language to translate string to.
+ * If null it checks for language in session followed by Config.language configuration variable.
* @return string translated string.
*/
- public static function translate($singular, $plural = null, $domain = null, $category = 6, $count = null) {
+ public static function translate($singular, $plural = null, $domain = null, $category = 6, $count = null, $language = null) {
$_this = I18n::getInstance();
if (strpos($singular, "\r\n") !== false) {
@@ -144,10 +145,13 @@ public static function translate($singular, $plural = null, $domain = null, $cat
if (is_numeric($category)) {
$_this->category = $_this->_categories[$category];
}
- $language = Configure::read('Config.language');
- if (!empty($_SESSION['Config']['language'])) {
- $language = $_SESSION['Config']['language'];
+ if (empty($language)) {
+ if (!empty($_SESSION['Config']['language'])) {
+ $language = $_SESSION['Config']['language'];
+ } else {
+ $language = Configure::read('Config.language');
+ }
}
if (($_this->_lang && $_this->_lang !== $language) || !$_this->_lang) {

0 comments on commit 30522d0

Please sign in to comment.