mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding doc comments to translation functions in basics.php
Refactoring I18n class to use one locale directory for an application. Translations will be located in app/locales/[LANGUAGE]/LC_MESSAGES/[CONTROLLER].mo or [CONTROLLER].po If not found app/locales/[LANGUAGE]/LC_MESSAGES/default.mo or default.po All core translations will be located in cake/locales/[LANGUAGE]/LC_MESSAGES/ git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4122 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
4c586b7893
commit
d23de28349
3 changed files with 76 additions and 64 deletions
|
@ -1039,21 +1039,20 @@
|
|||
}
|
||||
/**
|
||||
*
|
||||
* Returns a translated string if one is found,
|
||||
* or the submitted message if not found.
|
||||
* Returns a translated string if one is found, or the submitted message if not found.
|
||||
*
|
||||
* @param unknown_type $msg
|
||||
* @param unknown_type $return
|
||||
* @return unknown
|
||||
* @param string $msg
|
||||
* @param boolean $return
|
||||
* @return translated string if $return is false string will be echoed
|
||||
*/
|
||||
function __($msg, $return = null) {
|
||||
function __($msg, $return = false) {
|
||||
if(!class_exists('I18n')) {
|
||||
uses('i18n');
|
||||
}
|
||||
$calledFrom = debug_backtrace();
|
||||
$dir = dirname($calledFrom[0]['file']);
|
||||
|
||||
if(is_null($return)) {
|
||||
if($return === false) {
|
||||
echo I18n::translate($msg, null, null, null, null, $dir);
|
||||
} else {
|
||||
return I18n::translate($msg, null, null, null, null, $dir);
|
||||
|
@ -1064,20 +1063,20 @@
|
|||
* Returns correct plural form of message identified by $msg1 and $msg2 for count $count.
|
||||
* Some languages have more than one form for plural messages dependent on the count.
|
||||
*
|
||||
* @param unknown_type $msg1
|
||||
* @param unknown_type $msg2
|
||||
* @param unknown_type $count
|
||||
* @param unknown_type $return
|
||||
* @return unknown
|
||||
* @param string $msg1
|
||||
* @param string $msg2
|
||||
* @param integer $count
|
||||
* @param boolean $return
|
||||
* @return plural form of translated string if $return is false string will be echoed
|
||||
*/
|
||||
function __n($msg1, $msg2, $count, $return = null) {
|
||||
function __n($msg1, $msg2, $count, $return = false) {
|
||||
if(!class_exists('I18n')) {
|
||||
uses('i18n');
|
||||
}
|
||||
$calledFrom = debug_backtrace();
|
||||
$dir = dirname($calledFrom[0]['file']);
|
||||
|
||||
if(is_null($return)) {
|
||||
if($return === false) {
|
||||
echo I18n::translate($msg1, $msg2, null, null, $count, $dir);
|
||||
} else {
|
||||
return I18n::translate($msg1, $msg2, null, null, $count, $dir);
|
||||
|
@ -1089,21 +1088,21 @@
|
|||
* Returns correct plural form of message identified by $msg1 and $msg2 for count $count
|
||||
* from domain $domain
|
||||
*
|
||||
* @param unknown_type $domain
|
||||
* @param unknown_type $msg1
|
||||
* @param unknown_type $msg2
|
||||
* @param unknown_type $count
|
||||
* @param unknown_type $return
|
||||
* @return unknown
|
||||
* @param string $domain
|
||||
* @param string $msg1
|
||||
* @param string $msg2
|
||||
* @param integer $count
|
||||
* @param boolean $return
|
||||
* @return plural form of translated string if $return is false string will be echoed
|
||||
*/
|
||||
function __dn($domain, $msg1, $msg2, $count, $return = null) {
|
||||
function __dn($domain, $msg1, $msg2, $count, $return = false) {
|
||||
if(!class_exists('I18n')) {
|
||||
uses('i18n');
|
||||
}
|
||||
$calledFrom = debug_backtrace();
|
||||
$dir = dirname($calledFrom[0]['file']);
|
||||
|
||||
if(is_null($return)) {
|
||||
if($return === false) {
|
||||
echo I18n::translate($msg1, $msg2, $domain, null, $count, $dir);;
|
||||
} else {
|
||||
return I18n::translate($msg1, $msg2, $domain, null, $count, $dir);
|
||||
|
@ -1128,22 +1127,22 @@
|
|||
* LC_MESSAGES 5
|
||||
* LC_ALL 6
|
||||
*
|
||||
* @param unknown_type $domain
|
||||
* @param unknown_type $msg1
|
||||
* @param unknown_type $msg2
|
||||
* @param unknown_type $count
|
||||
* @param unknown_type $category
|
||||
* @param unknown_type $return
|
||||
* @return unknown
|
||||
* @param string $domain
|
||||
* @param string $msg1
|
||||
* @param string $msg2
|
||||
* @param integer $count
|
||||
* @param string $category
|
||||
* @param boolean $return
|
||||
* @return plural form of translated string if $return is false string will be echoed
|
||||
*/
|
||||
function __dcn($domain, $msg1, $msg2, $count, $category, $return = null) {
|
||||
function __dcn($domain, $msg1, $msg2, $count, $category, $return = false) {
|
||||
if(!class_exists('I18n')) {
|
||||
uses('i18n');
|
||||
}
|
||||
$calledFrom = debug_backtrace();
|
||||
$dir = dirname($calledFrom[0]['file']);
|
||||
|
||||
if(is_null($return)) {
|
||||
if($return === false) {
|
||||
echo I18n::translate($msg1, $msg2, $domain, $category, $count, $dir);
|
||||
} else {
|
||||
return I18n::translate($msg1, $msg2, $domain, $category, $count, $dir);
|
||||
|
@ -1166,20 +1165,20 @@
|
|||
* LC_MESSAGES 5
|
||||
* LC_ALL 6
|
||||
*
|
||||
* @param unknown_type $domain
|
||||
* @param unknown_type $msg
|
||||
* @param unknown_type $category
|
||||
* @param unknown_type $return
|
||||
* @return unknown
|
||||
* @param string $domain
|
||||
* @param string $msg
|
||||
* @param string $category
|
||||
* @param boolean $return
|
||||
* @return translated string if $return is false string will be echoed
|
||||
*/
|
||||
function __dc($domain, $msg, $category, $return = null) {
|
||||
function __dc($domain, $msg, $category, $return = false) {
|
||||
if(!class_exists('I18n')) {
|
||||
uses('i18n');
|
||||
}
|
||||
$calledFrom = debug_backtrace();
|
||||
$dir = dirname($calledFrom[0]['file']);
|
||||
|
||||
if(is_null($return)) {
|
||||
if($return === false) {
|
||||
echo I18n::translate($msg, null, $domain, $category, null, $dir);
|
||||
} else {
|
||||
return I18n::translate($msg, null, $domain, $category, null, $dir);
|
||||
|
@ -1194,14 +1193,14 @@
|
|||
* @param unknown_type $return
|
||||
* @return unknown
|
||||
*/
|
||||
function __d($domain, $msg, $return = null) {
|
||||
function __d($domain, $msg, $return = false) {
|
||||
if(!class_exists('I18n')) {
|
||||
uses('i18n');
|
||||
}
|
||||
$calledFrom = debug_backtrace();
|
||||
$dir = dirname($calledFrom[0]['file']);
|
||||
|
||||
if(is_null($return)) {
|
||||
if($return === false) {
|
||||
echo I18n::translate($msg, null, $domain, null, null, $dir);
|
||||
} else {
|
||||
return I18n::translate($msg, null, $domain, null, null, $dir);
|
||||
|
|
|
@ -95,7 +95,7 @@ class I18n extends Object {
|
|||
$_this =& I18n::getInstance();
|
||||
$language = Configure::read('Config.language');
|
||||
|
||||
if(!empty($_SESSION['Config']['locale'])) {
|
||||
if($language === null && !empty($_SESSION['Config']['locale'])) {
|
||||
$_this->locale = $_SESSION['Config']['locale'];
|
||||
} else{
|
||||
$_this->__l10n->get($language);
|
||||
|
@ -291,34 +291,39 @@ class I18n extends Object {
|
|||
$_this =& I18n::getInstance();
|
||||
$_this->__noLocal = true;
|
||||
|
||||
$searchPath[] = VIEWS . $domain . DS . 'locale';
|
||||
$searchPath[] = CAKE . 'locale';
|
||||
|
||||
foreach (explode(",",$_this->locale) as $d) {
|
||||
$d = trim($d);
|
||||
$d = strtok($d, "@.-+=%:; ");
|
||||
|
||||
if (strlen($d)) {
|
||||
$dir[] = $d;
|
||||
}
|
||||
|
||||
if (strpos($d, "_")) {
|
||||
$dir[] = strtok($d, "_");
|
||||
}
|
||||
}
|
||||
$searchPath[] = APP . 'locale';
|
||||
$searchPath[] = CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'locale';
|
||||
|
||||
foreach ($searchPath as $directory) {
|
||||
foreach ($dir as $lang) {
|
||||
foreach ($_this->__l10n->languagePath as $lang) {
|
||||
$file = $directory . DS . $lang . DS . 'LC_MESSAGES' . DS . $domain;
|
||||
$default = APP . 'locale'. DS . $lang . DS . 'LC_MESSAGES' . DS . 'default';
|
||||
$core = CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'locale'. DS . $lang . DS . 'LC_MESSAGES' . DS . 'core';
|
||||
|
||||
if (file_exists($fn = "$file.mo") && ($f = fopen($fn, "rb"))) {
|
||||
$_this->__loadMo($f, $domain);
|
||||
$_this->__noLocal = null;
|
||||
break 2;
|
||||
} elseif (file_exists($fn = "$default.mo") && ($f = fopen($fn, "rb"))) {
|
||||
$_this->__loadMo($f, $domain);
|
||||
$_this->__noLocal = null;
|
||||
break 2;
|
||||
} elseif (file_exists($fn = "$file.po") && ($f = fopen($fn, "r"))) {
|
||||
$_this->__loadPo($f, $domain);
|
||||
$_this->__noLocal = null;
|
||||
break 2;
|
||||
} elseif (file_exists($fn = "$default.po") && ($f = fopen($fn, "r"))) {
|
||||
$_this->__loadPo($f, $domain);
|
||||
$_this->__noLocal = null;
|
||||
break 2;
|
||||
} elseif (file_exists($fn = "$core.mo") && ($f = fopen($fn, "rb"))) {
|
||||
$_this->__loadMo($f, $domain);
|
||||
$_this->__noLocal = null;
|
||||
break 2;
|
||||
} elseif (file_exists($fn = "$core.po") && ($f = fopen($fn, "r"))) {
|
||||
$_this->__loadPo($f, $domain);
|
||||
$_this->__noLocal = null;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ class L10n extends Object {
|
|||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $winLocale = 'eng';
|
||||
var $default = null;
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
|
@ -301,6 +301,9 @@ class L10n extends Object {
|
|||
*
|
||||
*/
|
||||
function __construct() {
|
||||
if (defined('DEFAULT_LANGUAGE')) {
|
||||
$this->default = DEFAULT_LANGUAGE;
|
||||
}
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
|
@ -325,9 +328,8 @@ class L10n extends Object {
|
|||
function __setLanguage($language = null) {
|
||||
if ((!is_null($language)) && (isset($this->__l10nCatalog[$this->__l10nMap[$language]]))) {
|
||||
$this->language = $this->__l10nCatalog[$this->__l10nMap[$language]]['language'];
|
||||
$this->languagePath = array(0 => $this->__l10nCatalog[$language]['locale'],
|
||||
1 => $this->__l10nCatalog[$language]['localeFallback'],
|
||||
2 => $this->__l10nCatalog[DEFAULT_LANGUAGE]['localeFallback']);
|
||||
$this->languagePath = array(0 => $this->__l10nCatalog[$this->__l10nMap[$language]]['locale'],
|
||||
1 => $this->__l10nCatalog[$this->__l10nMap[$language]]['localeFallback']);
|
||||
$this->lang = $language;
|
||||
$this->locale = $this->__l10nCatalog[$this->__l10nMap[$language]]['locale'];
|
||||
} elseif (defined('DEFAULT_LANGUAGE')) {
|
||||
|
@ -337,6 +339,9 @@ class L10n extends Object {
|
|||
$this->lang = DEFAULT_LANGUAGE;
|
||||
$this->locale = $this->__l10nCatalog[$this->__l10nMap[DEFAULT_LANGUAGE]]['locale'];
|
||||
}
|
||||
if($this->default) {
|
||||
$this->languagePath = array(2 => $this->__l10nCatalog[$this->default]['localeFallback']);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Enter description here...
|
||||
|
@ -344,14 +349,17 @@ class L10n extends Object {
|
|||
*/
|
||||
function __autoLanguage() {
|
||||
$_detectableLanguages = split ('[,;]', env('HTTP_ACCEPT_LANGUAGE'));
|
||||
foreach ($_detectableLanguages as $langKey => $key) {
|
||||
foreach ($_detectableLanguages as $key => $langKey) {
|
||||
if (isset($this->__l10nCatalog[$langKey])) {
|
||||
|
||||
$this->language = $this->__l10nCatalog[$langKey]['language'];
|
||||
$this->languagePath = array(0 => $this->__l10nCatalog[$langKey]['locale'],
|
||||
1 => $this->__l10nCatalog[$langKey]['localeFallback'],
|
||||
2 => $this->__l10nCatalog[DEFAULT_LANGUAGE]['localeFallback']);
|
||||
1 => $this->__l10nCatalog[$langKey]['localeFallback']);
|
||||
$this->lang = $langKey;
|
||||
$this->locale = $this->__l10nCatalog[$langKey]['locale'];
|
||||
if($this->default) {
|
||||
$this->languagePath = array(2 => $this->__l10nCatalog[$this->default]['localeFallback']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue