本文整理汇总了PHP中i18n::get_locale方法的典型用法代码示例。如果您正苦于以下问题:PHP i18n::get_locale方法的具体用法?PHP i18n::get_locale怎么用?PHP i18n::get_locale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类i18n
的用法示例。
在下文中一共展示了i18n::get_locale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
// Send default settings according to locale
$locale = i18n::get_locale();
$symbols = Zend_Locale_Data::getList($locale, 'symbols');
$currency = Currency::config()->currency_symbol;
$decimals = $symbols['decimal'];
$thousands = $decimals == ',' ? ' ' : ',';
// Accouting needs to be initialized globally
FormExtraJquery::include_accounting();
Requirements::customScript(<<<EOT
window.accounting.settings = {
currency: {
symbol : "{$currency}",
format: "%s%v",
decimal : "{$decimals}",
thousand: "{$thousands}",
precision : 2
},
number: {
precision : 0,
thousand: "{$thousands}",
decimal : "{$decimals}"
}
}
EOT
, 'accountingInit');
}
开发者ID:helpfulrobot,项目名称:lekoala-silverstripe-form-extras,代码行数:28,代码来源:FormExtraLeftAndMainExtension.php
示例2: init
public function init()
{
parent::init();
Requirements::clear();
Requirements::insertHeadTags('<meta http-equiv="Content-language" content="' . i18n::get_locale() . '" />');
Requirements::themedCSS('sendfriend', 'screen');
}
示例3: testFieldInDenmark
function testFieldInDenmark()
{
$locale = i18n::get_locale();
i18n::set_locale('da_DK');
// Should start at 0
$field = new PercentageField('Test', 'TestField');
$this->assertEquals(0, $field->dataValue());
$this->assertEquals('0%', $field->Value());
// Entering 50 should yield 0.5
$field->setValue('50');
$this->assertEquals(0.5, $field->dataValue());
$this->assertEquals('50%', $field->Value());
// Entering 50% should yield 0.5
$field->setValue('50%');
$this->assertEquals(0.5, $field->dataValue());
$this->assertEquals('50%', $field->Value());
// Entering -50% should yield -0.5
$field->setValue('-50%');
$this->assertEquals(-0.5, $field->dataValue());
$this->assertEquals('-50%', $field->Value());
// Entering 0.5 should yield 0.5
$field->setValue('0,5');
$this->assertEquals(0.5, $field->dataValue());
$this->assertEquals('50%', $field->Value());
// Entering 0.5% should yield 0.005
$field->setValue('0,5%');
$this->assertEquals(0.005, $field->dataValue());
$this->assertEquals('0,5%', $field->Value());
i18n::set_locale($locale);
}
开发者ID:helpfulrobot,项目名称:markguinn-silverstripe-shop-extendedpricing,代码行数:30,代码来源:PercentageFieldTest.php
示例4: handleRequest
public function handleRequest(SS_HTTPRequest $request, DataModel $model = NULL)
{
$body = null;
$lang = i18n::get_locale();
$path = Config::inst()->get('UniversalErrorPage', 'DefaultPath');
if (!$path) {
$path = $this->defaultErrorPagePath;
}
$forCode = Config::inst()->get('UniversalErrorPage', $this->ErrorCode);
$localeForCode = preg_replace('/\\.([a-z]+)$/i', '-' . $lang . '.$1', $forCode);
$errorPages = array($localeForCode, $forCode, $path . "error-{$this->ErrorCode}-{$lang}.html", $path . "error-{$this->ErrorCode}-{$lang}.php", $path . "error-{$lang}.html", $path . "error-{$lang}.php", $path . 'error.html', $path . 'error.php');
$this->extend('updateHandleRequest', $errorPages);
// now check if any of the pages exist
foreach ($errorPages as $errorPage) {
if (!$body && file_exists($errorPage)) {
$ext = pathinfo($errorPage, PATHINFO_EXTENSION);
if ($ext == 'php') {
ob_start();
include $errorPage;
$body = ob_get_clean();
} else {
$body = file_get_contents($errorPage);
}
break;
}
}
if ($body) {
$response = new SS_HTTPResponse();
$response->setStatusCode($this->ErrorCode);
$response->setBody($body);
return $response;
}
return parent::handleRequest($request, $model);
}
示例5: Special
public function Special()
{
if (i18n::get_locale() === 'zh_CN') {
return $this->Special_cn;
}
return $this->Special;
}
示例6: format
/**
* Format a value as a number
*
* @param string $value
* @param int $precision
* @return string
*/
public static function format($value, $precision = null, $locale = null)
{
if ($precision === null) {
$precision = self::$default_precision;
}
if ($locale) {
$currentLocale = self::$_locale;
self::$_locale = $locale;
}
if (is_array($value)) {
foreach ($value as &$val) {
$val = self::format($val, $precision);
}
return $value;
}
if (self::$_locale !== i18n::get_locale()) {
self::initVariables();
}
if (self::$_decimals === null) {
self::initVariables();
}
$rawValue = self::unformat($value);
$formattedValue = number_format($rawValue, $precision, self::$_decimals, self::$_thousands);
if ($locale) {
self::$_locale = $currentLocale;
}
return $formattedValue;
}
示例7: setUp
public function setUp()
{
parent::setUp();
//Remap translation group for home pages
Translatable::disable_locale_filter();
$default = $this->objFromFixture('Page', 'home');
$defaultFR = $this->objFromFixture('Page', 'home_fr');
$defaultFR->addTranslationGroup($default->ID, true);
Translatable::enable_locale_filter();
$this->origLocaleRoutingEnabled = Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL');
Config::inst()->update('MultilingualRootURLController', 'UseLocaleURL', false);
$this->origDashLocaleEnabled = Config::inst()->get('MultilingualRootURLController', 'UseDashLocale');
Config::inst()->update('MultilingualRootURLController', 'UseDashLocale', false);
$this->origAcceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.5';
$this->origCookieLocale = Cookie::get('language');
Cookie::force_expiry('language');
$this->origCurrentLocale = Translatable::get_current_locale();
Translatable::set_current_locale('en_US');
$this->origLocale = Translatable::default_locale();
Translatable::set_default_locale('en_US');
$this->origi18nLocale = i18n::get_locale();
i18n::set_locale('en_US');
$this->origAllowedLocales = Translatable::get_allowed_locales();
Translatable::set_allowed_locales(array('en_US', 'fr_FR'));
MultilingualRootURLController::reset();
}
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-translatablerouting,代码行数:27,代码来源:MultilingualRootURLControllerTest.php
示例8: testGettingWrittenDataObject
/**
* Write a Money object to the database, then re-read it to ensure it
* is re-read properly.
*/
function testGettingWrittenDataObject() {
$local = i18n::get_locale();
i18n::set_locale('en_US'); //make sure that the $ amount is not prefixed by US$, as it would be in non-US locale
$obj = new MoneyTest_DataObject();
$m = new Money();
$m->setAmount(987.65);
$m->setCurrency('USD');
$obj->MyMoney = $m;
$this->assertEquals("$987.65", $obj->MyMoney->Nice(),
"Money field not added to data object properly when read prior to first writing the record."
);
$objID = $obj->write();
$moneyTest = DataObject::get_by_id('MoneyTest_DataObject',$objID);
$this->assertTrue($moneyTest instanceof MoneyTest_DataObject);
$this->assertEquals('USD', $moneyTest->MyMoneyCurrency);
$this->assertEquals(987.65, $moneyTest->MyMoneyAmount);
$this->assertEquals("$987.65", $moneyTest->MyMoney->Nice(),
"Money field not added to data object properly when read."
);
i18n::set_locale($local);
}
示例9: locale
/**
* Get the locale of the Member, or if we're not logged in or don't have a locale, use the default one
* @return string
*/
protected function locale()
{
if (($member = Member::currentUser()) && $member->Locale) {
return $member->Locale;
}
return i18n::get_locale();
}
示例10: CurrencySymbol
public function CurrencySymbol()
{
require_once THIRDPARTY_PATH . "/Zend/Currency.php";
$locale = new Zend_Locale(i18n::get_locale());
$symbol = new Zend_Currency($locale);
return $symbol->getSymbol();
}
示例11: setUp
public function setUp()
{
parent::setUp();
Translatable::disable_locale_filter();
//Publish all english pages
$pages = Page::get()->filter('Locale', 'en_US');
foreach ($pages as $page) {
$page->publish('Stage', 'Live');
}
//Rewrite the french translation groups and publish french pages
$pagesFR = Page::get()->filter('Locale', 'fr_FR');
foreach ($pagesFR as $index => $page) {
$page->addTranslationGroup($pages->offsetGet($index)->ID, true);
$page->publish('Stage', 'Live');
}
Translatable::enable_locale_filter();
$this->origLocaleRoutingEnabled = Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL');
Config::inst()->update('MultilingualRootURLController', 'UseLocaleURL', false);
$this->origDashLocaleEnabled = Config::inst()->get('MultilingualRootURLController', 'UseDashLocale');
Config::inst()->update('MultilingualRootURLController', 'UseDashLocale', false);
$this->origAcceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.5';
$this->origCookieLocale = Cookie::get('language');
Cookie::force_expiry('language');
Cookie::set('language', 'en');
$this->origCurrentLocale = Translatable::get_current_locale();
Translatable::set_current_locale('en_US');
$this->origLocale = Translatable::default_locale();
Translatable::set_default_locale('en_US');
$this->origi18nLocale = i18n::get_locale();
i18n::set_locale('en_US');
$this->origAllowedLocales = Translatable::get_allowed_locales();
Translatable::set_allowed_locales(array('en_US', 'fr_FR'));
MultilingualRootURLController::reset();
}
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-translatablerouting,代码行数:35,代码来源:MultilingualModelAsControllerTest.php
示例12: Content
public function Content()
{
if (i18n::get_locale() === 'zh_CN') {
return $this->Content_cn;
}
return $this->Content;
}
示例13: convertCountryCodeToName
/**
* Convert country code to name
*
* @param string $code
* @return string
*/
public static function convertCountryCodeToName($code)
{
if (!$code) {
return;
}
return Zend_Locale::getTranslation($code, 'territory', i18n::get_locale());
}
示例14: setUp
function setUp() {
parent::setUp();
$this->alternateBasePath = $this->getCurrentAbsolutePath() . "/_fakewebroot";
$this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot';
FileSystem::makeFolder($this->alternateBaseSavePath);
Director::setBaseFolder($this->alternateBasePath);
// Push a template loader running from the fake webroot onto the stack.
$templateManifest = new SS_TemplateManifest($this->alternateBasePath, false, true);
$templateManifest->regenerate(false);
SS_TemplateLoader::instance()->pushManifest($templateManifest);
$this->_oldTheme = SSViewer::current_theme();
SSViewer::set_theme('testtheme1');
$classManifest = new SS_ClassManifest($this->alternateBasePath, true, true, false);
SS_ClassLoader::instance()->pushManifest($classManifest);
$this->originalLocale = i18n::get_locale();
// Override default adapter to avoid cached translations between tests.
// Emulates behaviour in i18n::get_translators()
$this->origAdapter = i18n::get_translator('core');
$adapter = new Zend_Translate(array(
'adapter' => 'i18nSSLegacyAdapter',
'locale' => i18n::default_locale(),
'disableNotices' => true,
));
i18n::register_translator($adapter, 'core');
$adapter->removeCache();
i18n::include_by_locale('en');
}
示例15: applyParsley
/**
* applyParsley
* @return this
**/
public function applyParsley()
{
$this->parsleyEnabled = true;
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
Requirements::javascript(ZENVALIDATOR_PATH . '/javascript/parsley/parsley.remote.min.js');
$lang = i18n::get_lang_from_locale(i18n::get_locale());
if ($lang != 'en') {
Requirements::javascript(ZENVALIDATOR_PATH . '/javascript/parsley/i18n/' . $lang . '.js');
}
if ($this->form) {
if ($this->defaultJS) {
$this->form->addExtraClass('parsley');
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
Requirements::javascript(ZENVALIDATOR_PATH . '/javascript/zenvalidator.js');
} else {
$this->form->addExtraClass('custom-parsley');
}
foreach ($this->constraints as $fieldName => $constraints) {
foreach ($constraints as $constraint) {
$constraint->applyParsley();
}
}
}
return $this;
}