locales() public static method

Retrieves the list of locales
public static locales ( mixed $domain = null ) : array
$domain mixed Domain to determine the locales for. If null, the global list be returned. If true, then the current domain will be used.
return array List of locales
コード例 #1
0
 public function updateRelativeLink(&$base, &$action)
 {
     // Don't inject locale to subpages
     if ($this->owner->ParentID && SiteTree::config()->nested_urls) {
         return;
     }
     // For blank/temp pages such as Security controller fallback to querystring
     $locale = Fluent::current_locale();
     if (!$this->owner->exists()) {
         $base = Controller::join_links($base, '?' . Fluent::config()->query_param . '=' . urlencode($locale));
         return;
     }
     // Check if this locale is the default for its own domain
     $domain = Fluent::domain_for_locale($locale);
     if ($locale === Fluent::default_locale($domain)) {
         // For home page in the default locale, do not alter home url
         if ($base === null) {
             return;
         }
         // For all pages on a domain where there is only a single locale,
         // then the domain itself is sufficient to distinguish that domain
         // See https://github.com/tractorcow/silverstripe-fluent/issues/75
         $domainLocales = Fluent::locales($domain);
         if (count($domainLocales) === 1) {
             return;
         }
     }
     // Simply join locale root with base relative URL
     $localeURL = Fluent::alias($locale);
     $base = Controller::join_links($localeURL, $base);
 }
コード例 #2
0
 /**
  * Checks that fluent is configured correctly
  *
  * @throws ConvertTranslatableException
  */
 protected function checkInstalled()
 {
     // Assert that fluent is configured
     $locales = Fluent::locales();
     if (empty($locales)) {
         throw new ConvertTranslatableException("Please configure Fluent.locales prior to migrating from translatable");
     }
     $defaultLocale = Fluent::default_locale();
     if (empty($defaultLocale) || !in_array($defaultLocale, $locales)) {
         throw new ConvertTranslatableException("Please configure Fluent.default_locale prior to migrating from translatable");
     }
 }
コード例 #3
0
 public function updateSettingsFields(FieldList $fields)
 {
     // Present a set of checkboxes for filtering this item by locale
     $menuFilterField = FieldGroup::create()->setTitle($this->owner->fieldLabel('ShowInMenus'))->setDescription(_t('Fluent.LocaleMenuFilterDescription', 'Select the locales where this item is visible in the menu'));
     foreach (Fluent::locales() as $locale) {
         $id = Fluent::db_field_for_locale("ShowInMenus", $locale);
         $fields->removeByName($id, true);
         // Remove existing (in case it was auto scaffolded)
         $title = i18n::get_locale_name($locale);
         $menuFilterField->push(new CheckboxField($id, $title));
     }
     $fields->removeByName('ShowInMenus', true);
     $fields->addFieldToTab('Root.Settings', $menuFilterField, 'CanViewType');
 }
コード例 #4
0
 public function updateCMSFields(FieldList $fields)
 {
     // Present a set of checkboxes for filtering this item by locale
     $filterField = FieldGroup::create()->setTitle(_t('Fluent.LocaleFilter', 'Locale Filter'))->setDescription(_t('Fluent.LocaleFilterDescription', 'Check a locale to show this item on that locale'));
     foreach (Fluent::locales() as $locale) {
         $id = Fluent::db_field_for_locale("LocaleFilter", $locale);
         $fields->removeByName($id, true);
         // Remove existing (in case it was auto scaffolded)
         $title = i18n::get_locale_name($locale);
         $filterField->push(new CheckboxField($id, $title));
     }
     if ($fields->hasTabSet()) {
         $fields->findOrMakeTab('Root.Locales', _t('Fluent.TABLOCALES', 'Locales'));
         $fields->addFieldToTab('Root.Locales', $filterField);
     } else {
         $fields->add($filterField);
     }
 }
コード例 #5
0
 /**
  * Actives locales as defined in siteconfig
  *
  * @return \ArrayList
  */
 public function ActiveLocalesList()
 {
     if (!$this->owner->hasMethod('LocaleInformation')) {
         return new ArrayList();
     }
     $data = array();
     $config = SiteConfig::current_site_config();
     $list = $config->ActiveLocales;
     $ctrl = null;
     if (Controller::has_curr()) {
         $ctrl = Controller::curr();
     }
     if (!$list) {
         if ($ctrl && $ctrl->hasMethod('Locales')) {
             return $ctrl->Locales();
         }
         return $config->Locales();
     }
     $validLocales = Fluent::locales();
     foreach (explode(',', $list) as $locale) {
         if (!in_array($locale, $validLocales)) {
             continue;
         }
         if ($ctrl && $ctrl->hasMethod('LocaleInformation')) {
             $data[] = $ctrl->LocaleInformation($locale);
         } else {
             $data[] = $this->owner->LocaleInformation($locale);
         }
     }
     return new ArrayList($data);
 }
コード例 #6
0
 public function updateCMSFields(FieldList $fields)
 {
     // get all fields to translate and remove
     $translated = $this->getTranslatedTables();
     foreach ($translated as $table => $translatedFields) {
         foreach ($translatedFields as $translatedField) {
             // Find field matching this translated field
             // If the translated field has an ID suffix also check for the non-suffixed version
             // E.g. UploadField()
             $field = $fields->dataFieldByName($translatedField);
             if (!$field && preg_match('/^(?<field>\\w+)ID$/', $translatedField, $matches)) {
                 $field = $fields->dataFieldByName($matches['field']);
             }
             // Highlight any translated field
             if ($field) {
                 $field->addExtraClass('LocalisedField');
             }
             // Remove translation DBField from automatic scaffolded fields
             foreach (Fluent::locales() as $locale) {
                 $fieldName = Fluent::db_field_for_locale($translatedField, $locale);
                 $fields->removeByName($fieldName, true);
             }
         }
     }
 }
コード例 #7
0
 public function updateCMSFields(FieldList $fields)
 {
     // get all fields to translate and remove
     $translated = $this->getTranslatedTables();
     foreach ($translated as $table => $translatedFields) {
         foreach ($translatedFields as $translatedField) {
             // Find field matching this translated field
             // If the translated field has an ID suffix also check for the non-suffixed version
             // E.g. UploadField()
             $field = $fields->dataFieldByName($translatedField);
             if (!$field && preg_match('/^(?<field>\\w+)ID$/', $translatedField, $matches)) {
                 $field = $fields->dataFieldByName($matches['field']);
             }
             // Highlight any translated field
             if ($field && !$field->hasClass('LocalisedField')) {
                 // Add a language indicator next to the fluent icon
                 $locale = Fluent::current_locale();
                 $title = $field->Title();
                 $field->setTitle('<span class="fluent-locale-label">' . strtok($locale, '_') . '</span>' . $title);
                 $field->addExtraClass('LocalisedField');
             }
             // Remove translation DBField from automatic scaffolded fields
             foreach (Fluent::locales() as $locale) {
                 $fieldName = Fluent::db_field_for_locale($translatedField, $locale);
                 $fields->removeByName($fieldName, true);
             }
         }
     }
 }
コード例 #8
0
 /**
  * Test output for helpers in domain mode
  */
 public function testDomainsHelpers()
 {
     Config::inst()->update('Fluent', 'force_domain', true);
     // Test Fluent::domains
     $this->assertEquals(array('www.example.com', 'www.example.ca', 'www.example.co.nz'), array_keys(Fluent::domains()));
     // Test Fluent::default_locale
     $usDefault = $this->withURL('www.example.com', '/', '/', function ($test) {
         return Fluent::default_locale(true);
     });
     $this->assertEquals('en_US', $usDefault);
     $this->assertEquals('en_US', Fluent::default_locale('www.example.com'));
     $this->assertEquals('fr_CA', Fluent::default_locale());
     // Test Fluent::domain_for_locale
     $this->assertEquals(null, Fluent::domain_for_locale('nl_NL'));
     $this->assertEquals('www.example.com', Fluent::domain_for_locale('en_US'));
     $this->assertEquals('www.example.com', Fluent::domain_for_locale('es_ES'));
     $this->assertEquals('www.example.ca', Fluent::domain_for_locale('fr_CA'));
     $this->assertEquals('www.example.co.nz', Fluent::domain_for_locale('en_NZ'));
     // Test Fluent::locales
     $usLocales = $this->withURL('www.example.com', '/', '/', function ($test) {
         return Fluent::locales(true);
     });
     $this->assertEquals(array('es_ES', 'en_US'), $usLocales);
     $this->assertEquals(array('es_ES', 'en_US'), Fluent::locales('www.example.com'));
     $this->assertEquals(array('fr_CA', 'en_NZ', 'en_US', 'es_ES'), Fluent::locales());
     Config::inst()->update('Fluent', 'force_domain', false);
 }
コード例 #9
0
 public function updateCMSFields(FieldList $fields)
 {
     // get all fields to translate and remove
     $translated = $this->getTranslatedTables();
     foreach ($translated as $table => $translatedFields) {
         foreach ($translatedFields as $translatedField) {
             // Find field matching this translated field
             // If the translated field has an ID suffix also check for the non-suffixed version
             // E.g. UploadField()
             $field = $fields->dataFieldByName($translatedField);
             if (!$field && preg_match('/^(?<field>\\w+)ID$/', $translatedField, $matches)) {
                 $field = $fields->dataFieldByName($matches['field']);
             }
             // Highlight any translatable field
             if ($field && !$field->hasClass('LocalisedField')) {
                 // Add a language indicator next to the fluent icon
                 $locale = Fluent::current_locale();
                 $title = $field->Title();
                 $titleClasses = 'fluent-locale-label';
                 // Add a visual indicator for whether the value has been changed from the default locale
                 $isModified = Fluent::isFieldModified($this->owner, $field, $locale);
                 $modifiedTitle = 'Using default locale value';
                 if ($isModified) {
                     $titleClasses .= ' fluent-modified-value';
                     $modifiedTitle = 'Modified from default locale value - click to reset';
                 }
                 $field->setTitle(sprintf('<span class="%s" title="%s">%s</span>%s', $titleClasses, $modifiedTitle, strtok($locale, '_'), $title));
                 // Set the default value to the element so we can compare it with JavaScript
                 if (Fluent::default_locale() !== $locale) {
                     $field->setAttribute('data-default-locale-value', $this->owner->{Fluent::db_field_for_locale($field->getName(), Fluent::default_locale())});
                 }
                 $field->addExtraClass('LocalisedField');
             }
             // Remove translation DBField from automatic scaffolded fields
             foreach (Fluent::locales() as $locale) {
                 $fieldName = Fluent::db_field_for_locale($translatedField, $locale);
                 $fields->removeByName($fieldName, true);
             }
         }
     }
     $this->addLocaleIndicatorMessage($fields);
 }
コード例 #10
0
 /**
  * Resets all translated fields to their value in the default locale
  */
 public function resetTranslations()
 {
     $translated = $this->getTranslatedTables();
     foreach ($translated as $table => $fields) {
         foreach ($fields as $field) {
             $defaultField = Fluent::db_field_for_locale($field, Fluent::default_locale());
             $defaultValue = $this->owner->{$defaultField};
             foreach (Fluent::locales() as $locale) {
                 if ($locale === Fluent::default_locale()) {
                     continue;
                 }
                 $localeField = Fluent::db_field_for_locale($field, $locale);
                 $originalValue = $this->owner->{$localeField};
                 $this->owner->{$localeField} = $defaultValue;
                 // If these values differ, but a change isn't detected, then force a change
                 if ($this->owner->exists() && $originalValue != $defaultValue && !$this->owner->isChanged($field)) {
                     $this->owner->forceChange();
                 }
                 $this->owner->write();
             }
         }
     }
 }