本文整理汇总了PHP中Localization::getTranslate方法的典型用法代码示例。如果您正苦于以下问题:PHP Localization::getTranslate方法的具体用法?PHP Localization::getTranslate怎么用?PHP Localization::getTranslate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Localization
的用法示例。
在下文中一共展示了Localization::getTranslate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: t2
/** Translate text (plural form).
* @param string $singular The singular form.
* @param string $plural The plural form.
* @param int $number The number.
* @param mixed ... Unlimited optional number of arguments: if specified they'll be used for printf
* @return string Returns the translated text.
* @example t2('%d child', '%d children', $n) will return translated '%d child' if $n is 1, translated '%d children' otherwise.
* @example t2('%d child', '%d children', $n, $n) will return translated '1 child' if $n is 1, translated '2 children' if $n is 2.
*/
function t2($singular, $plural, $number) {
$zt = Localization::getTranslate();
if(is_object($zt)) {
$translated = $zt->plural($singular, $plural, $number);
} else {
$translated = ($number == 1) ? $singular : $plural;
}
if(func_num_args() == 3) {
return $translated;
}
$arg = array();
for($i = 3; $i < func_num_args(); $i++) {
$arg[] = func_get_arg($i);
}
return vsprintf($translated, $arg);
}
示例2: tc
/** Translate text (simple form) with a context.
* @param string $context A context, useful for translators to better understand the meaning of the text to be translated.
* @param string $text The text to be translated.
* @param mixed ... Unlimited optional number of arguments: if specified they'll be used for printf.
* @return string Returns the translated text.
* @example tc('Recipient', 'To %s') will return translation for 'To %s' (example for Italian 'A %s').
* @example tc('End date', 'To %s') will return translation for 'To %s' (example for Italian 'Fino al %s').
* @example tc('Recipient', 'To %s', 'John') will return translation for 'To %s' (example: 'A %s'), using 'John' for printf (so the final result will be 'A John' for Italian).
* @example tc('End date', 'To %s', '01/01/2000') will return translation for 'To %s' (example: 'Fino al %s'), using '01/01/2000' for printf (so the final result will be 'Fino al 01/01/2000' for Italian).
*/
function tc($context, $text)
{
$zt = Localization::getTranslate();
if (is_object($zt)) {
$msgid = $context . "" . $text;
$msgtxt = $zt->_($msgid);
if ($msgtxt != $msgid) {
$text = $msgtxt;
}
}
if (func_num_args() == 2) {
return $text;
}
$arg = array();
for ($i = 2; $i < func_num_args(); $i++) {
$arg[] = func_get_arg($i);
}
return vsprintf($text, $arg);
}
示例3: t
function t($text) {
$zt = Localization::getTranslate();
if (func_num_args() == 1) {
if (is_object($zt)) {
return $zt->_($text);
} else {
return $text;
}
}
$arg = array();
for($i = 1 ; $i < func_num_args(); $i++) {
$arg[] = func_get_arg($i);
}
if (is_object($zt)) {
return vsprintf($zt->_($text), $arg);
} else {
return vsprintf($text, $arg);
}
}
示例4: setupLocalization
public function setupLocalization(LocalizablePackageInterface $package, $locale = null, $translate = 'current')
{
if ($translate === 'current') {
$translate = \Localization::getTranslate();
}
if (is_object($translate)) {
if (!isset($locale) || !strlen($locale)) {
$locale = Localization::activeLocale();
}
$languageFile = $package->getTranslationFile($locale);
if (is_file($languageFile)) {
$translate->addTranslationFile('gettext', $languageFile);
}
}
}
示例5: setupPackageLocalization
/** Loads package translation files into zend translate
* @param string $folder = null The directory name containing the locale file to load (for example: 'en_US'). If empty we'll use the locale identifier of $translate
* @param string $locale = null The identifier of the locale to activate (for example: 'en_US'). If empty we'll use $folder
* @param string|Zend_Translate $translate = 'current' The Zend_Translate instance that holds the translations (set to 'current' to use the current one)
*/
public function setupPackageLocalization($folder = NULL, $locale = NULL, $translate = 'current')
{
if ($translate === 'current') {
$translate = Localization::getTranslate();
}
if (is_object($translate)) {
$path = $this->getPackagePath() . '/' . DIRNAME_LANGUAGES;
if (!isset($folder) || !strlen($folder)) {
$folder = $translate->getLocale();
}
if (!isset($locale)) {
$locale = $folder;
}
if (file_exists($path . '/' . $folder . '/LC_MESSAGES/messages.mo')) {
$translate->addTranslation($path . '/' . $folder . '/LC_MESSAGES/messages.mo', $locale);
}
}
}
示例6: init
public function init() {Localization::getTranslate();}
示例7: setupPackageLocalization
/**
* Loads package translation files into zend translate
* @param string $locale
* @param string $key
* @return void
*/
public function setupPackageLocalization($locale = NULL, $key = NULL) {
$translate = Localization::getTranslate();
if (is_object($translate)) {
$path = $this->getPackagePath() . '/' . DIRNAME_LANGUAGES;
if(!isset($locale) || !strlen($locale)) {
$locale = ACTIVE_LOCALE;
}
if(!isset($key)) {
$key = $locale;
}
if (file_exists($path . '/' . $locale . '/LC_MESSAGES/messages.mo')) {
$translate->addTranslation($path . '/' . $locale . '/LC_MESSAGES/messages.mo', $key);
}
}
}
示例8: setupPackageLocalization
public function setupPackageLocalization() {
$translate = Localization::getTranslate();
if (is_object($translate)) {
$path = $this->getPackagePath() . '/' . DIRNAME_LANGUAGES;
if (file_exists($path . '/' . LOCALE . '/LC_MESSAGES/messages.mo')) {
$translate->addTranslation($path . '/' . LOCALE . '/LC_MESSAGES/messages.mo', LOCALE);
}
}
}