本文整理汇总了PHP中Translate::checkAndReplaceArgs方法的典型用法代码示例。如果您正苦于以下问题:PHP Translate::checkAndReplaceArgs方法的具体用法?PHP Translate::checkAndReplaceArgs怎么用?PHP Translate::checkAndReplaceArgs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translate
的用法示例。
在下文中一共展示了Translate::checkAndReplaceArgs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smartyTranslate
function smartyTranslate($params, &$smarty)
{
global $_LANG;
if (!isset($params['js'])) {
$params['js'] = false;
}
if (!isset($params['pdf'])) {
$params['pdf'] = false;
}
if (!isset($params['mod'])) {
$params['mod'] = false;
}
if (!isset($params['sprintf'])) {
$params['sprintf'] = null;
}
$string = str_replace('\'', '\\\'', $params['s']);
$filename = !isset($smarty->compiler_object) || !is_object($smarty->compiler_object->template) ? $smarty->template_resource : $smarty->compiler_object->template->getTemplateFilepath();
$basename = basename($filename, '.tpl');
$key = $basename . '_' . md5($string);
if (isset($smarty->source) && strpos($smarty->source->filepath, DIRECTORY_SEPARATOR . 'override' . DIRECTORY_SEPARATOR) !== false) {
$key = 'override_' . $key;
}
if ($params['mod']) {
return Translate::getModuleTranslation($params['mod'], $params['s'], $basename, $params['sprintf'], $params['js']);
} else {
if ($params['pdf']) {
return Translate::getPdfTranslation($params['s']);
}
}
if ($_LANG != null && isset($_LANG[$key])) {
$msg = $_LANG[$key];
} elseif ($_LANG != null && isset($_LANG[Tools::strtolower($key)])) {
$msg = $_LANG[Tools::strtolower($key)];
} else {
$msg = $params['s'];
}
if ($msg != $params['s'] && !$params['js']) {
$msg = stripslashes($msg);
} elseif ($params['js']) {
$msg = addslashes($msg);
}
if ($params['sprintf'] !== null) {
$msg = Translate::checkAndReplaceArgs($msg, $params['sprintf']);
}
return $params['js'] ? $msg : Tools::safeOutput($msg);
}
示例2: getPdfTranslation
/**
* Get a translation for a PDF
*
* @param string $string
* @return string
*/
public static function getPdfTranslation($string, $sprintf = null)
{
global $_LANGPDF;
$iso = Context::getContext()->language->iso_code;
if (!Validate::isLangIsoCode($iso)) {
Tools::displayError(sprintf('Invalid iso lang (%s)', Tools::safeOutput($iso)));
}
$override_i18n_file = _PS_THEME_DIR_ . 'pdf/lang/' . $iso . '.php';
$i18n_file = _PS_TRANSLATIONS_DIR_ . $iso . '/pdf.php';
if (file_exists($override_i18n_file)) {
$i18n_file = $override_i18n_file;
}
if (!(include $i18n_file)) {
Tools::displayError(sprintf('Cannot include PDF translation language file : %s', $i18n_file));
}
if (!isset($_LANGPDF) || !is_array($_LANGPDF)) {
return str_replace('"', '"', $string);
}
$string = preg_replace("/\\\\*'/", "\\'", $string);
$key = md5($string);
$str = array_key_exists('PDF' . $key, $_LANGPDF) ? $_LANGPDF['PDF' . $key] : $string;
if ($sprintf !== null) {
$str = Translate::checkAndReplaceArgs($str, $sprintf);
}
return $str;
}
示例3: getModuleTranslation
/**
* Get a translation for a module
*
* @param string|Module $module
* @param string $string
* @param string $source
* @return string
*/
public static function getModuleTranslation($module, $string, $source, $sprintf = null)
{
global $_MODULES, $_MODULE, $_LANGADM;
static $lang_cache = array();
// $_MODULES is a cache of translations for all module.
// $translations_merged is a cache of wether a specific module's translations have already been added to $_MODULES
static $translations_merged = array();
$name = $module instanceof Module ? $module->name : $module;
if (!isset($translations_merged[$name])) {
$filesByPriority = array(_PS_THEME_DIR_ . 'modules/' . $name . '/translations/' . Context::getContext()->language->iso_code . '.php', _PS_THEME_DIR_ . 'modules/' . $name . '/' . Context::getContext()->language->iso_code . '.php', _PS_MODULE_DIR_ . $name . '/translations/' . Context::getContext()->language->iso_code . '.php', _PS_MODULE_DIR_ . $name . '/' . Context::getContext()->language->iso_code . '.php');
foreach ($filesByPriority as $file) {
if (Tools::file_exists_cache($file)) {
include_once $file;
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
$translations_merged[$name] = true;
break;
}
}
}
$key = md5(str_replace('\'', '\\\'', $string));
$cache_key = $name . '|' . $string . '|' . $source;
if (!isset($lang_cache[$cache_key])) {
if ($_MODULES == null) {
if ($sprintf !== null) {
$string = Translate::checkAndReplaceArgs($string, $sprintf);
}
return str_replace('"', '"', $string);
}
$current_key = strtolower('<{' . $name . '}' . _THEME_NAME_ . '>' . $source) . '_' . $key;
$default_key = strtolower('<{' . $name . '}prestashop>' . $source) . '_' . $key;
if (isset($_MODULES[$current_key])) {
$ret = stripslashes($_MODULES[$current_key]);
} elseif (isset($_MODULES[$default_key])) {
$ret = stripslashes($_MODULES[$default_key]);
} elseif (!empty($_LANGADM)) {
$ret = Translate::getGenericAdminTranslation($string, $key, $_LANGADM);
} else {
$ret = stripslashes($string);
}
if ($sprintf !== null) {
$ret = Translate::checkAndReplaceArgs($ret, $sprintf);
}
$lang_cache[$cache_key] = str_replace('"', '"', $ret);
}
return $lang_cache[$cache_key];
}
示例4: getModuleTranslation
/**
* Get a translation for a module
*
* @param string|Module $module
* @param string $string
* @param string $source
* @return string
*/
public static function getModuleTranslation($module, $string, $source, $sprintf = null, $js = false)
{
global $_MODULES, $_MODULE, $_LANGADM;
static $lang_cache = array();
// $_MODULES is a cache of translations for all module.
// $translations_merged is a cache of wether a specific module's translations have already been added to $_MODULES
static $translations_merged = array();
$name = $module instanceof Module ? $module->name : $module;
$language = Context::getContext()->language;
if (!isset($translations_merged[$name]) && isset(Context::getContext()->language)) {
$filesByPriority = array(_PS_THEME_DIR_ . 'modules/' . $name . '/translations/' . $language->iso_code . '.php', _PS_THEME_DIR_ . 'modules/' . $name . '/' . $language->iso_code . '.php', _PS_MODULE_DIR_ . $name . '/translations/' . $language->iso_code . '.php', _PS_MODULE_DIR_ . $name . '/' . $language->iso_code . '.php');
foreach ($filesByPriority as $file) {
if (file_exists($file)) {
include_once $file;
$_MODULES = !empty($_MODULES) ? $_MODULES + $_MODULE : $_MODULE;
//we use "+" instead of array_merge() because array merge erase existing values.
$translations_merged[$name] = true;
}
}
}
$key = md5(str_replace('\'', '\\\'', $string));
$cache_key = $name . '|' . $string . '|' . $source . '|' . (int) $js;
if (!isset($lang_cache[$cache_key])) {
if ($_MODULES == null) {
if ($sprintf !== null) {
$string = Translate::checkAndReplaceArgs($string, $sprintf);
}
return str_replace('"', '"', $string);
}
$current_key = strtolower('<{' . $name . '}' . _THEME_NAME_ . '>' . $source) . '_' . $key;
$default_key = strtolower('<{' . $name . '}prestashop>' . $source) . '_' . $key;
// if (isset($_MODULES[$current_key]))
if (!empty($_MODULES[$current_key])) {
$ret = stripslashes($_MODULES[$current_key]);
} elseif (!empty($_MODULES[$default_key])) {
$ret = stripslashes($_MODULES[$default_key]);
} elseif (!empty($_LANGADM)) {
$ret = Translate::getGenericAdminTranslation($string, $key, $_LANGADM);
} else {
$ret = stripslashes($string);
}
if ($sprintf !== null) {
$ret = Translate::checkAndReplaceArgs($ret, $sprintf);
}
if ($js) {
$ret = addslashes($ret);
} else {
$ret = htmlspecialchars($ret, ENT_COMPAT, 'UTF-8');
}
if ($sprintf === null) {
$lang_cache[$cache_key] = $ret;
} else {
return $ret;
}
}
return $lang_cache[$cache_key];
}
示例5: smartyTranslate
function smartyTranslate($params, &$smarty)
{
global $_LANG;
if (!isset($params['js'])) {
$params['js'] = false;
}
if (!isset($params['pdf'])) {
$params['pdf'] = false;
}
if (!isset($params['mod'])) {
$params['mod'] = false;
}
if (!isset($params['sprintf'])) {
$params['sprintf'] = array();
}
if (!isset($params['d'])) {
$params['d'] = null;
}
if (!is_null($params['d'])) {
if (isset($params['tags'])) {
$backTrace = debug_backtrace();
$errorMessage = sprintf('Unable to translate "%s" in %s. tags() is not supported anymore, please use sprintf().', $params['s'], $backTrace[0]['args'][1]->template_resource);
if (_PS_MODE_DEV_) {
throw new Exception($errorMessage);
} else {
PrestaShopLogger::addLog($errorMessage);
}
}
if (!is_array($params['sprintf'])) {
$backTrace = debug_backtrace();
$errorMessage = sprintf('Unable to translate "%s" in %s. sprintf() parameter should be an array.', $params['s'], $backTrace[0]['args'][1]->template_resource);
if (_PS_MODE_DEV_) {
throw new Exception($errorMessage);
} else {
PrestaShopLogger::addLog($errorMessage);
return $params['s'];
}
}
}
if (($translation = Context::getContext()->getTranslator()->trans($params['s'], $params['sprintf'], $params['d'])) !== $params['s']) {
return $translation;
}
$string = str_replace('\'', '\\\'', $params['s']);
$filename = !isset($smarty->compiler_object) || !is_object($smarty->compiler_object->template) ? $smarty->template_resource : $smarty->compiler_object->template->getTemplateFilepath();
$basename = basename($filename, '.tpl');
$key = $basename . '_' . md5($string);
if (isset($smarty->source) && strpos($smarty->source->filepath, DIRECTORY_SEPARATOR . 'override' . DIRECTORY_SEPARATOR) !== false) {
$key = 'override_' . $key;
}
if ($params['mod']) {
return Translate::smartyPostProcessTranslation(Translate::getModuleTranslation($params['mod'], $params['s'], $basename, $params['sprintf'], $params['js']), $params);
} elseif ($params['pdf']) {
return Translate::smartyPostProcessTranslation(Translate::getPdfTranslation($params['s'], $params['sprintf']), $params);
}
if ($_LANG != null && isset($_LANG[$key])) {
$msg = $_LANG[$key];
} elseif ($_LANG != null && isset($_LANG[Tools::strtolower($key)])) {
$msg = $_LANG[Tools::strtolower($key)];
} else {
$msg = $params['s'];
}
if ($msg != $params['s'] && !$params['js']) {
$msg = stripslashes($msg);
} elseif ($params['js']) {
$msg = addslashes($msg);
}
if ($params['sprintf'] !== null) {
$msg = Translate::checkAndReplaceArgs($msg, $params['sprintf']);
}
return Translate::smartyPostProcessTranslation($params['js'] ? $msg : Tools::safeOutput($msg), $params);
}