public static function getNativeName($culture) { $cult = new sfCultureInfo($culture); return $cult->getNativeName(); }
$t->is($c->getIsNeutralCulture(), false, '->getIsNeutralCulture() returns false if the culture is specific'); $c = new sfCultureInfo('fr'); $t->is($c->getIsNeutralCulture(), true, '->getIsNeutralCulture() returns true if the culture is neutral'); // ->getEnglishName() $t->diag('->getEnglishName()'); $c = new sfCultureInfo('fr_FR'); $t->is($c->getEnglishName(), 'French (France)', '->getEnglishName() returns the english name of the current culture'); $c = new sfCultureInfo('fr'); $t->is($c->getEnglishName(), 'French', '->getEnglishName() returns the english name of the current culture'); $t->is($c->getEnglishName(), $c->EnglishName, '->getEnglishName() is equivalent to ->EnglishName'); // ->getNativeName() $t->diag('->getNativeName()'); $c = new sfCultureInfo('fr_FR'); $t->is($c->getNativeName(), 'français (France)', '->getNativeName() returns the native name of the current culture'); $c = new sfCultureInfo('fr'); $t->is($c->getNativeName(), 'français', '->getNativeName() returns the native name of the current culture'); $t->is($c->getNativeName(), $c->NativeName, '->getNativeName() is equivalent to ->NativeName'); // ->getCalendar() $t->diag('->getCalendar()'); $c = new sfCultureInfo('fr'); $t->is($c->getCalendar(), 'gregorian', '->getCalendar() returns the default calendar'); $t->is($c->getCalendar(), $c->Calendar, '->getCalendar() is equivalent to ->Calendar'); // __get() $t->diag('__get()'); try { $c->NonExistant; $t->fail('__get() throws an exception if the property does not exist'); } catch (sfException $e) { $t->pass('__get() throws an exception if the property does not exist'); } // __set()
public function executeEdit() { /** @var \myUser $sfUser */ $sfUser = sfContext::getInstance()->getUser(); $userId = $sfUser->getSubscriberId(); $schemaObj = $this->getCurrentSchema(); $CurrentCulture = $sfUser->getCulture(); //FIXME: If the user is an admin, set the available languages to all of the schema languages //FIXME: if the user has no languages set, silently set their language to the default (?) if ($userId) { $c = new Criteria(); $c->add(SchemaHasUserPeer::USER_ID, $userId); $c->add(SchemaHasUserPeer::SCHEMA_ID, $schemaObj->getId()); $schemaUser = SchemaHasUserPeer::doSelectOne($c); if ($sfUser->hasObjectCredential($schemaObj->getId(), 'schema', array(0 => array(0 => 'administrator', 2 => 'schemaadmin')))) { $UserLanguages = $schemaObj->getLanguages(); $DefaultLanguage = $schemaObj->getLanguage(); } else { if ($schemaUser) { $UserLanguages = $schemaUser->getLanguages(); $DefaultLanguage = $schemaUser->getDefaultLanguage(); } else { //set the languages from the schema $UserLanguages = $schemaObj->getLanguages(); $DefaultLanguage = $schemaObj->getLanguage(); } } if (is_array($UserLanguages) && !in_array($CurrentCulture, $UserLanguages)) { //save the current culture $UserCulture = $sfUser->getCulture(); $this->getUser()->setAttribute("UserCulture", $UserCulture); //reset the current culture for edit $sfUser->setCulture($DefaultLanguage); $this->getUser()->setAttribute("CurrentLanguage", $DefaultLanguage); $culture = new sfCultureInfo($this->getUser()->getCulture()); $this->setFlash('notice', 'Current language is not available for edit! Current editing language has been reset to: ' . $culture->getNativeName()); } $this->getUser()->setAttribute("languages", $UserLanguages); } parent::executeEdit(); /** @var $schemaProperty SchemaProperty */ $schemaProperty = $this->schema_property; if ($schemaProperty) { $schemaObj = $this->getCurrentSchema(); $schemaProperty->setSchemaUri($schemaObj->getNamespace()); $lexUri = $schemaProperty->getLexicalAlias(); if (empty($lexUri)) { $newURI = $schemaObj->getNamespace(); $this->setDefaultLexicalAlias($schemaProperty, $newURI); } } }
public function getCurrentLanguage() { $c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture()); return $c->getNativeName(); }