当前位置: 首页>>代码示例>>PHP>>正文


PHP Translate::checkAndReplaceArgs方法代码示例

本文整理汇总了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);
}
开发者ID:dev-lav,项目名称:htdocs,代码行数:46,代码来源:smartyfront.config.inc.php

示例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;
 }
开发者ID:jpodracky,项目名称:dogs,代码行数:32,代码来源:Translate.php

示例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('"', '&quot;', $ret);
     }
     return $lang_cache[$cache_key];
 }
开发者ID:jicheng17,项目名称:vipinsg,代码行数:54,代码来源:Translate.php

示例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('"', '&quot;', $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];
 }
开发者ID:ecssjapan,项目名称:guiding-you-afteropen,代码行数:65,代码来源:Translate.php

示例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);
}
开发者ID:M03G,项目名称:PrestaShop,代码行数:71,代码来源:smartyfront.config.inc.php


注:本文中的Translate::checkAndReplaceArgs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。