Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the other translation shortcuts for context support #4023

Merged
merged 1 commit into from Aug 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Cake/Console/Command/Task/ExtractTask.php
Expand Up @@ -380,6 +380,13 @@ protected function _extractTokens() {
$this->_parse('__dcn', array('domain', 'singular', 'plural', 'count', 'category'));

$this->_parse('__x', array('context', 'singular'));
$this->_parse('__xn', array('context', 'singular', 'plural'));
$this->_parse('__dx', array('domain', 'context', 'singular'));
$this->_parse('__dxc', array('domain', 'context', 'singular', 'category'));
$this->_parse('__dxn', array('domain', 'context', 'singular', 'plural'));
$this->_parse('__dxcn', array('domain', 'context', 'singular', 'plural', 'count', 'category'));
$this->_parse('__xc', array('context', 'singular', 'category'));

}
}

Expand Down
198 changes: 197 additions & 1 deletion lib/Cake/basics.php
Expand Up @@ -800,7 +800,203 @@ function __x($context, $singular, $args = null) {
App::uses('I18n', 'I18n');
$translated = I18n::translate($singular, null, null, null, null, null, $context);
$arguments = func_get_args();
return I18n::insertArgs($translated, array_slice($arguments, 1));
return I18n::insertArgs($translated, array_slice($arguments, 2));
}

}

if (!function_exists('__xn')) {

/**
* Returns correct plural form of message identified by $singular and $plural for count $count.
* Some languages have more than one form for plural messages dependent on the count.
*
* @param string $context Context of the text
* @param string $singular Singular text to translate
* @param string $plural Plural text
* @param integer $count Count
* @param mixed $args Array with arguments or multiple arguments in function
* @return mixed plural form of translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__n
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link is incorrect. Could change the fragment to #__xn assuming that section will be added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, all links seem to be wrong. Should I add the right anchor to all of the links or would it be better if I remove the links entirely.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Marlinc just remove the links

*/
function __xn($context, $singular, $plural, $count, $args = null) {
if (!$singular) {
return;
}

App::uses('I18n', 'I18n');
$translated = I18n::translate($singular, $plural, null, I18n::LC_MESSAGES, $count, null, $context);
$arguments = func_get_args();
return I18n::insertArgs($translated, array_slice($arguments, 4));
}

}

if (!function_exists('__dx')) {

/**
* Allows you to override the current domain for a single message lookup.
*
* @param string $domain Domain
* @param string $context Context of the text
* @param string $msg String to translate
* @param mixed $args Array with arguments or multiple arguments in function
* @return translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__d
*/
function __dx($domain, $context, $msg, $args = null) {
if (!$msg) {
return;
}
App::uses('I18n', 'I18n');
$translated = I18n::translate($msg, null, $domain, null, null, null, $context);
$arguments = func_get_args();
return I18n::insertArgs($translated, array_slice($arguments, 3));
}

}

if (!function_exists('__dxn')) {

/**
* Allows you to override the current domain for a single plural message lookup.
* Returns correct plural form of message identified by $singular and $plural for count $count
* from domain $domain.
*
* @param string $domain Domain
* @param string $context Context of the text
* @param string $singular Singular string to translate
* @param string $plural Plural
* @param integer $count Count
* @param mixed $args Array with arguments or multiple arguments in function
* @return plural form of translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dn
*/
function __dxn($domain, $context, $singular, $plural, $count, $args = null) {
if (!$singular) {
return;
}
App::uses('I18n', 'I18n');
$translated = I18n::translate($singular, $plural, $domain, I18n::LC_MESSAGES, $count, null, $context);
$arguments = func_get_args();
return I18n::insertArgs($translated, array_slice($arguments, 5));
}

}

if (!function_exists('__dxc')) {

/**
* Allows you to override the current domain for a single message lookup.
* It also allows you to specify a category.
*
* The category argument allows a specific category of the locale settings to be used for fetching a message.
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
*
* Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
*
* - LC_ALL I18n::LC_ALL
* - LC_COLLATE I18n::LC_COLLATE
* - LC_CTYPE I18n::LC_CTYPE
* - LC_MONETARY I18n::LC_MONETARY
* - LC_NUMERIC I18n::LC_NUMERIC
* - LC_TIME I18n::LC_TIME
* - LC_MESSAGES I18n::LC_MESSAGES
*
* @param string $domain Domain
* @param string $context Context of the text
* @param string $msg Message to translate
* @param integer $category Category
* @param mixed $args Array with arguments or multiple arguments in function
* @return translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dc
*/
function __dxc($domain, $context, $msg, $category, $args = null) {
if (!$msg) {
return;
}
App::uses('I18n', 'I18n');
$translated = I18n::translate($msg, null, $domain, $category, null, null, $context);
$arguments = func_get_args();
return I18n::insertArgs($translated, array_slice($arguments, 4));
}

}

if (!function_exists('__dxcn')) {

/**
* Allows you to override the current domain for a single plural message lookup.
* It also allows you to specify a category.
* Returns correct plural form of message identified by $singular and $plural for count $count
* from domain $domain.
*
* The category argument allows a specific category of the locale settings to be used for fetching a message.
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
*
* Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
*
* - LC_ALL I18n::LC_ALL
* - LC_COLLATE I18n::LC_COLLATE
* - LC_CTYPE I18n::LC_CTYPE
* - LC_MONETARY I18n::LC_MONETARY
* - LC_NUMERIC I18n::LC_NUMERIC
* - LC_TIME I18n::LC_TIME
* - LC_MESSAGES I18n::LC_MESSAGES
*
* @param string $domain Domain
* @param string $context Context of the text
* @param string $singular Singular string to translate
* @param string $plural Plural
* @param integer $count Count
* @param integer $category Category
* @param mixed $args Array with arguments or multiple arguments in function
* @return plural form of translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__dcn
*/
function __dxcn($domain, $context, $singular, $plural, $count, $category, $args = null) {
if (!$singular) {
return;
}
App::uses('I18n', 'I18n');
$translated = I18n::translate($singular, $plural, $domain, $category, $count, null, $context);
$arguments = func_get_args();
return I18n::insertArgs($translated, array_slice($arguments, 6));
}

}

if (!function_exists('__xc')) {

/**
* The category argument allows a specific category of the locale settings to be used for fetching a message.
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
*
* Note that the category must be specified with a class constant of I18n, instead of the constant name. The values are:
*
* - LC_ALL I18n::LC_ALL
* - LC_COLLATE I18n::LC_COLLATE
* - LC_CTYPE I18n::LC_CTYPE
* - LC_MONETARY I18n::LC_MONETARY
* - LC_NUMERIC I18n::LC_NUMERIC
* - LC_TIME I18n::LC_TIME
* - LC_MESSAGES I18n::LC_MESSAGES
*
* @param string $context Context of the text
* @param string $msg String to translate
* @param integer $category Category
* @param mixed $args Array with arguments or multiple arguments in function
* @return translated string
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#__c
*/
function __xc($context, $msg, $category, $args = null) {
if (!$msg) {
return;
}
App::uses('I18n', 'I18n');
$translated = I18n::translate($msg, null, null, $category, null, null, $context);
$arguments = func_get_args();
return I18n::insertArgs($translated, array_slice($arguments, 3));
}

}
Expand Down