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');
    }
 public function init()
 {
     parent::init();
     Requirements::clear();
     Requirements::insertHeadTags('<meta http-equiv="Content-language" content="' . i18n::get_locale() . '" />');
     Requirements::themedCSS('sendfriend', 'screen');
 }
 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);
 }
 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);
 }
Exemple #5
0
 public function Special()
 {
     if (i18n::get_locale() === 'zh_CN') {
         return $this->Special_cn;
     }
     return $this->Special;
 }
 /**
  * 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;
 }
 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();
 }
Exemple #8
0
	/**
     * 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);
    }
 /**
  * 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();
 }
 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();
 }
 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();
 }
Exemple #12
0
 public function Content()
 {
     if (i18n::get_locale() === 'zh_CN') {
         return $this->Content_cn;
     }
     return $this->Content;
 }
 /**
  * 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());
 }
	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');
	}
 /**
  * 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;
 }
Exemple #16
0
 public function Name()
 {
     if (i18n::get_locale() === 'zh_CN') {
         return $this->Name_cn;
     }
     return $this->Name;
 }
 public function getLanguage()
 {
     if ($this->getField('Language')) {
         return $this->getField('Language');
     } else {
         return i18n::get_locale();
     }
 }
 function setUp()
 {
     // Static publishing will just confuse things
     StaticPublisher::$disable_realtime = true;
     parent::setUp();
     $this->origLocale = i18n::get_locale();
     i18n::set_locale('en_NZ');
 }
Exemple #19
0
 public function setUp()
 {
     parent::setUp();
     $this->originalLocale = i18n::get_locale();
     i18n::set_locale('en_NZ');
     $this->origTimeFormat = TimeField::$default_config['timeformat'];
     TimeField::$default_config['timeformat'] = 'HH:mm:ss';
 }
 public function setUp()
 {
     parent::setUp();
     $this->originalLocale = i18n::get_locale();
     i18n::set_locale('en_NZ');
     $this->origConfig = Config::inst()->get('DateField', 'default_config');
     Config::inst()->update('DateField', 'default_config', array('dateformat' => 'dd/MM/yyyy'));
 }
 /**
  * Injects some custom javascript to provide instant loading of DataObject
  * tables.
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 13.01.2011
  */
 public function onAfterInit()
 {
     Translatable::set_current_locale(i18n::get_locale());
     if (Director::is_ajax()) {
         return true;
     }
     Requirements::css('silvercart/admin/css/SilvercartMain.css');
 }
 public function setUp()
 {
     parent::setUp();
     $this->originalLocale = i18n::get_locale();
     i18n::set_locale('en_NZ');
     $this->origTimeConfig = Config::inst()->get('TimeField', 'default_config');
     Config::inst()->update('TimeField', 'default_config', array('timeformat' => 'HH:mm:ss'));
 }
Exemple #23
0
 public function setUp()
 {
     parent::setUp();
     $this->originalLocale = i18n::get_locale();
     i18n::set_locale('en_NZ');
     $this->origDateFormat = DateField::$default_config['dateformat'];
     DateField::$default_config['dateformat'] = 'dd/MM/yyyy';
 }
 function __construct($name, $title = null, $value = null)
 {
     parent::__construct($name, $title, $value);
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/tinymce/tinymce.min.js');
     $lang = i18n::get_lang_from_locale(i18n::get_locale());
     if ($lang != 'en') {
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/tinymce/langs/' . $lang . '.js');
     }
 }
 public function doSignup(array $data)
 {
     $o_Member = Member::create();
     $this->saveInto($o_Member);
     $o_Member->Locale = i18n::get_locale();
     $o_Member->write();
     // We use Email Verified Member
     $this->controller->redirect('Security/emailsent/' . $data['Email']);
 }
 protected function getFormat()
 {
     if (array_key_exists(i18n::get_locale(), $this->supported_locales)) {
         $locale = i18n::get_locale();
     } else {
         $locale = 'en_US';
     }
     return $this->locale_formats[$locale];
 }
 function __construct($name, $title = null, $value = null, $form = null, $rightTitle = null)
 {
     if (!$this->locale) {
         $this->locale = i18n::get_locale();
     }
     if (!$this->getConfig('dateformat')) {
         $this->setConfig('dateformat', i18n::get_date_format());
     }
     parent::__construct($name, $title, $value, $form, $rightTitle);
 }
 function __construct($name, $title = null, $value = "")
 {
     if (!$this->locale) {
         $this->locale = i18n::get_locale();
     }
     if (!$this->getConfig('timeformat')) {
         $this->setConfig('timeformat', i18n::get_time_format());
     }
     parent::__construct($name, $title, $value);
 }
 /**
  * Get the current locale.
  * Tries to get the locale from Translatable, Fluent or the default i18n (depending on what is installed)
  * @return string the locale in use
  */
 public static function get_current_locale()
 {
     if (class_exists('Translatable')) {
         return Translatable::get_current_locale();
     }
     if (class_exists('Fluent')) {
         return Fluent::current_locale();
     }
     return i18n::get_locale();
 }
 public function Format($format = null, $localized = true)
 {
     if ($this->value) {
         $zendDate = new Zend_Date($this->getValue(), 'y-MM-dd');
         if ($localized) {
             $zendDate->setLocale(i18n::get_locale());
         }
         return $zendDate->toString($format);
     }
 }