本文整理汇总了PHP中LocaleUtil::getLocaleId方法的典型用法代码示例。如果您正苦于以下问题:PHP LocaleUtil::getLocaleId方法的具体用法?PHP LocaleUtil::getLocaleId怎么用?PHP LocaleUtil::getLocaleId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LocaleUtil
的用法示例。
在下文中一共展示了LocaleUtil::getLocaleId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: quoteString
public function quoteString($oTemplateIdentifier, &$iFlags)
{
$iFlags |= Template::NO_HTML_ESCAPE;
if (!$oTemplateIdentifier->getValue()) {
return $oTemplateIdentifier->hasParameter('defaultValue') ? $oTemplateIdentifier->getParameter('defaultValue') : null;
}
$sLocale = LocaleUtil::getLocaleId();
$sStyle = 'double';
if ($oTemplateIdentifier->hasParameter('style')) {
$sStyle = $oTemplateIdentifier->getParameter('style');
}
$bAlternate = $oTemplateIdentifier->hasParameter('alternate') && $oTemplateIdentifier->getParameter('alternate') === 'true';
if (StringUtil::startsWith($sLocale, 'en_')) {
if ($sStyle === 'single') {
return "‘{$oTemplateIdentifier->getValue()}’";
}
return "“{$oTemplateIdentifier->getValue()}”";
}
if (StringUtil::startsWith($sLocale, 'fr_') || $sLocale === 'de_CH') {
if ($sStyle === 'single') {
return "‹{$oTemplateIdentifier->getValue()}›";
}
return "«{$oTemplateIdentifier->getValue()}»";
}
if (StringUtil::startsWith($sLocale, 'de_') || StringUtil::startsWith($sLocale, 'nl_')) {
if ($bAlternate) {
if ($sStyle === 'single') {
return "›{$oTemplateIdentifier->getValue()}‹";
}
return "»{$oTemplateIdentifier->getValue()}«";
}
if ($sStyle === 'single') {
return "‚{$oTemplateIdentifier->getValue()}‘";
}
return "„{$oTemplateIdentifier->getValue()}“";
}
if ($sStyle === 'single') {
return "'{$oTemplateIdentifier->getValue()}'";
}
return '"' . $oTemplateIdentifier->getValue() . '"';
}
示例2: testGetLocaleIdDE
public function testGetLocaleIdDE()
{
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en-US,de-AT";
$this->assertSame("de_AT", LocaleUtil::getLocaleId("de"));
}
示例3: __construct
/**
* @param string $sTemplateName template name
* @param string|array $mPath template dir path
* @param boolean $bTemplateIsTextOnly template is text only (name will be used as content, path can be used to decide origin [null=filesystem, "db"=database, "browser"=request])
* @param boolean $bDirectOutput template will output directly to stream? only one the main template should have set this to true
* @param string $sTargetEncoding target encoding. usually the browser encoding. text will be converted from the source encoding (default is utf-8, at the moment only changed when using text-only templates) into the target encoding
* @param string $sRootTemplateName root template name, used internally when including subtemplates, default=null
* @param int $iDefaultFlags default flags, will be ORed to the flags you provide when calling {@link replaceIdentifier()} and {@link replaceIdentifierMultiple()}
*/
public function __construct($sTemplateName, $mPath = null, $bTemplateIsTextOnly = false, $bDirectOutput = false, $sTargetEncoding = null, $sRootTemplateName = null, $iDefaultFlags = 0)
{
if ($sTargetEncoding === null) {
$sTargetEncoding = Settings::getSetting("encoding", "browser", "utf-8");
}
if ($mPath === "db") {
$this->sEncoding = Settings::getSetting("encoding", "db", "utf-8");
} else {
if ($mPath === "browser") {
$this->sEncoding = Settings::getSetting("encoding", "browser", "utf-8");
}
}
if ($mPath === null || $mPath === "db" || $mPath === "browser") {
$mPath = DIRNAME_TEMPLATES;
}
$sTemplateText = "";
$this->aTemplateContents = array();
$oCache = null;
$bCacheIsCurrent = false;
if ($bTemplateIsTextOnly) {
$sTemplateText = $sTemplateName;
$sTemplateName = $sRootTemplateName;
} else {
if ($sTemplateName instanceof FileResource) {
$oPath = $sTemplateName;
$aPath = explode('/', $oPath->getRelativePath());
$sTemplateName = $oPath->getFileName(self::$SUFFIX);
} else {
$aPath = ResourceFinder::parsePathArguments(null, $mPath, $sTemplateName . self::$SUFFIX);
$oPath = ResourceFinder::findResourceObject($aPath);
}
if ($oPath === null) {
throw new Exception("Error in Template construct: Template file " . implode("/", $aPath + array($sTemplateName . self::$SUFFIX)) . " does not exist");
}
if (Settings::getSetting('general', 'template_caching', false)) {
$oCache = new Cache($oPath->getFullPath() . "_" . LocaleUtil::getLocaleId() . "_" . $sTargetEncoding . "_" . $sRootTemplateName, DIRNAME_TEMPLATES);
$bCacheIsCurrent = $oCache->entryExists() && !$oCache->isOutdated($oPath->getFullPath());
}
if (!$bCacheIsCurrent) {
$sTemplateText = file_get_contents($oPath->getFullPath());
}
$mPath = $aPath;
array_pop($mPath);
}
if ($sRootTemplateName === null && !$bTemplateIsTextOnly) {
$sRootTemplateName = $sTemplateName;
}
if ($sRootTemplateName === null) {
$sRootTemplateName = '';
}
$this->sTemplateName = $sRootTemplateName;
if (StringUtil::startsWith($sTemplateName, 'e_mail_') || StringUtil::startsWith($sTemplateName, 'email_')) {
$iDefaultFlags |= self::NO_HTML_ESCAPE;
} else {
if (StringUtil::endsWith($sTemplateName, '.js') || StringUtil::endsWith($sTemplateName, '.css')) {
$iDefaultFlags |= self::NO_HTML_ESCAPE | self::ESCAPE;
} else {
if (StringUtil::endsWith($this->sTemplateName, '.js') || StringUtil::endsWith($this->sTemplateName, '.css')) {
//I’m not a js template but my parent is
$iDefaultFlags &= ~(self::NO_HTML_ESCAPE | self::ESCAPE);
}
}
}
$this->mPath = $mPath;
$this->oSpecialTemplateIdentifierActions = new SpecialTemplateIdentifierActions($this);
$this->iDefaultFlags = $iDefaultFlags;
if ($bCacheIsCurrent) {
$this->aTemplateContents = $oCache->getContentsAsVariable();
foreach ($this->aTemplateContents as &$mContent) {
if ($mContent instanceof TemplatePart) {
$mContent->setTemplate($this);
}
}
} else {
if (is_array($sTemplateText)) {
$this->aTemplateContents = $sTemplateText;
} else {
$sTemplateText = StringUtil::encode($sTemplateText, $this->sEncoding, $sTargetEncoding);
$this->aTemplateContents = self::templateContentsFromText($sTemplateText, $this);
$this->replaceConditionals(true);
$this->renderDirectOutput();
}
$this->replaceSpecialIdentifiersOnStart();
if ($oCache !== null) {
$oCache->setContents($this->aTemplateContents);
}
}
$this->sEncoding = $sTargetEncoding;
$this->bDirectOutput = $bDirectOutput;
$this->replaceConditionals(true);
$this->renderDirectOutput();
//.........这里部分代码省略.........
示例4: testGetLocaleId
public function testGetLocaleId()
{
Session::getSession()->resetAttribute("preferred_user_language");
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en,en-us;q=0.7,en-uk;q=0.3";
$this->assertSame("en_EN", LocaleUtil::getLocaleId("en"));
}