/**
  * Retrieves information about this object in the CURRENT locale
  *
  * @param string $locale The locale information to request, or null to use the default locale
  * @return ArrayData Mapped list of locale properties
  */
 public function CurrentLocaleInformation()
 {
     $locale = Fluent::current_locale();
     // Store basic locale information
     $data = array('Locale' => $locale, 'LocaleRFC1766' => i18n::convert_rfc1766($locale), 'Alias' => Fluent::alias($locale), 'Title' => i18n::get_locale_name($locale), 'LanguageNative' => i18n::get_language_name(i18n::get_lang_from_locale($locale), true));
     return new ArrayData($data);
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     //adding upload field - if item has already been saved
     if ($this->ID && $this->AssetsFolderID != 0) {
         //this is the default, for non multi-language sites
         if (!class_exists('Translatable') || $this->Locale == Translatable::default_locale()) {
             //Use SortableUploadField instead of UploadField!
             //The upload directory is expected to have been set in {@see UploadDirRules},
             //and should be something like: "assets/ID-Pagename"
             //TODO: This could easily be configurable through yml files (to e.g. "assets/galleries/ID"),
             //so this module could do without the upload dir rules
             //
             //read more about adding additinoal metadata to images here:
             //http://doc.silverstripe.org/framework/en/reference/uploadfield
             $imageField = new SortableUploadField('Images', '');
             $fields->addFieldToTab('Root.Images', $imageField);
         } else {
             $orig = $this->getTranslation(Translatable::default_locale());
             $html = sprintf('<a href="%s">%s</a>', Controller::join_links($orig->CMSEditLink(), '?locale=' . $orig->Locale), 'Images are administered through ' . i18n::get_locale_name($orig->Locale));
             $fields->addFieldToTab('Root.Images', LiteralField::create('ImagesDesc', $html));
         }
     }
     return $fields;
 }
 /**
  * @return mixed
  */
 public function getLanguageField()
 {
     $locale = Translatable::get_current_locale();
     if ($member = Member::currentUser()) {
         if (Permission::checkMember($member, 'VIEW_LANGS')) {
             return $this->getLanguageDropdownField($locale);
         }
     }
     return LiteralField::create('Locale', i18n::get_locale_name($locale));
 }
 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');
 }
 /**
  * Returns a form with all languages with languages already used appearing first.
  *
  * @return Form
  */
 public function updateSearchForm(Form $form)
 {
     $member = Member::currentUser();
     //check to see if the current user can switch langs or not
     if (Permission::checkMember($member, 'VIEW_LANGS')) {
         $field = new LanguageDropdownField('Locale', _t('CMSMain.LANGUAGEDROPDOWNLABEL', 'Language'), array(), 'SiteTree', 'Locale-English', singleton('SiteTree'));
         $field->setValue(Translatable::get_current_locale())->setForm($form);
     } else {
         // user doesn't have permission to switch langs
         // so just show a string displaying current language
         $field = new LiteralField('Locale', i18n::get_locale_name(Translatable::get_current_locale()));
     }
     $form->Fields()->unshift($field);
 }
 /**
  * Returns a form with all languages with languages already used appearing first.
  *
  * @return Form
  */
 function LangForm()
 {
     $member = Member::currentUser();
     //check to see if the current user can switch langs or not
     if (Permission::checkMember($member, 'VIEW_LANGS')) {
         $field = new LanguageDropdownField('Locale', _t('CMSMain.LANGUAGEDROPDOWNLABEL', 'Language'), array(), 'SiteTree', 'Locale-English', singleton('SiteTree'));
         $field->setValue(Translatable::get_current_locale());
     } else {
         // user doesn't have permission to switch langs
         // so just show a string displaying current language
         $field = new LiteralField('Locale', i18n::get_locale_name(Translatable::get_current_locale()));
     }
     $form = new Form($this->owner, 'LangForm', new FieldList($field), new FieldList(new FormAction('selectlang', _t('CMSMain_left.GO', 'Go'))));
     $form->unsetValidator();
     $form->addExtraClass('nostyle');
     return $form;
 }
 public function preRequest(\SS_HTTPRequest $request, \Session $session, \DataModel $model)
 {
     // Check languages to set
     $languages = array();
     foreach (SpellController::get_locales() as $locale) {
         $languages[] = i18n::get_locale_name($locale) . '=' . $locale;
     }
     // Set settings
     $editor = Config::inst()->get(__CLASS__, 'editor');
     HtmlEditorConfig::get($editor)->enablePlugins('spellchecker');
     HtmlEditorConfig::get($editor)->addButtonsToLine(2, 'spellchecker');
     $token = SecurityToken::inst();
     HtmlEditorConfig::get($editor)->setOption('spellchecker_rpc_url', $token->addToUrl('spellcheck/'));
     HtmlEditorConfig::get($editor)->setOption('browser_spellcheck', false);
     HtmlEditorConfig::get($editor)->setOption('spellchecker_languages', '+' . implode(', ', $languages));
     return true;
 }
 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);
     }
 }
 /**
  * @param FieldList $fields
  */
 public function updateCMSFields(FieldList $fields)
 {
     //adding upload field - if item has already been saved
     //AssetsFolderID is set by the uploaddirrules module
     if ($this->owner->ID && $this->owner->AssetsFolderID != 0) {
         //this is the default, for non multi-language sites
         if (!class_exists('Translatable') || $this->owner->Locale == Translatable::default_locale()) {
             //The upload directory is expected to have been set in {@see UploadDirRules},
             //This should be handled on the object that uses this extension!
             $imageField = SortableUploadField::create('Images', '')->setAllowedFileCategories('image');
             $fields->addFieldToTab('Root.Images', $imageField);
         } else {
             //Note that images are administered in the original language
             $orig = $this->owner->getTranslation(Translatable::default_locale());
             $html = sprintf('<a href="%s">%s</a>', Controller::join_links($orig->CMSEditLink(), '?locale=' . $orig->Locale), 'Images are administered through ' . i18n::get_locale_name($orig->Locale));
             $fields->addFieldToTab('Root.Images', LiteralField::create('ImagesDesc', $html));
         }
     }
 }
 public function init()
 {
     parent::init();
     // Locale" attribute is either explicitly added by LeftAndMain Javascript logic,
     // or implied on a translated record (see {@link Translatable->updateCMSFields()}).
     // $Lang serves as a "context" which can be inspected by Translatable - hence it
     // has the same name as the database property on Translatable.
     if ($this->getRequest()->requestVar("Locale")) {
         $this->Locale = $this->getRequest()->requestVar("Locale");
     } elseif ($this->getRequest()->requestVar("locale")) {
         $this->Locale = $this->getRequest()->requestVar("locale");
     } else {
         $this->Locale = Translatable::default_locale();
     }
     Translatable::set_current_locale($this->Locale);
     // collect languages for TinyMCE spellchecker plugin.
     // see http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
     $langName = i18n::get_locale_name($this->Locale);
     HtmlEditorConfig::get('cms')->setOption('spellchecker_languages', "+{$langName}={$this->Locale}");
     Requirements::javascript(CMS_DIR . '/javascript/CMSMain.js');
     Requirements::javascript(CMS_DIR . '/javascript/CMSMain_left.js');
     Requirements::javascript(CMS_DIR . '/javascript/CMSMain_right.js');
 }
Esempio n. 11
0
 function providePermissions()
 {
     if (!Object::has_extension('SiteTree', 'Translatable')) {
         return false;
     }
     $locales = self::get_allowed_locales();
     // Fall back to any locales used in existing translations (see #4939)
     if (!$locales) {
         $locales = DB::query('SELECT "Locale" FROM "SiteTree" GROUP BY "Locale"')->column();
     }
     $permissions = array();
     if ($locales) {
         foreach ($locales as $locale) {
             $localeName = i18n::get_locale_name($locale);
             $permissions['TRANSLATE_' . $locale] = sprintf(_t('Translatable.TRANSLATEPERMISSION', 'Translate %s', PR_MEDIUM, 'Translate pages into a language'), $localeName);
         }
     }
     $permissions['TRANSLATE_ALL'] = _t('Translatable.TRANSLATEALLPERMISSION', 'Translate into all available languages');
     return $permissions;
 }
 /**
  * Return a list of actives locales
  * 
  * @return array
  */
 public function ActiveLocalesNames()
 {
     $locales = array();
     $list = $this->owner->ActiveLocales;
     if (!$list) {
         return Fluent::locale_names();
     }
     foreach (explode(',', $list) as $locale) {
         $locales[$locale] = i18n::get_locale_name($locale);
     }
     return $locales;
 }
 public function translate(SS_HTTPRequest $request)
 {
     $locales = "";
     if (SiteTree::has_extension("Translatable")) {
         $locales = Translatable::get_allowed_locales();
     } else {
         $locales = array("it_IT");
     }
     $locales_list = new ArrayList();
     foreach ($locales as $key => $value) {
         $obj = new ViewableData();
         $obj->__set("Locale", $value);
         $obj->__set("LocaleName", i18n::get_locale_name($value));
         $obj->__set("Lang", i18n::get_lang_from_locale($value));
         $locales_list->push($obj);
     }
     if ($request->isAjax()) {
         if (isset($_POST["collect"])) {
             foreach ($locales as $value) {
                 $c = new TextCollector($value);
                 $c->run(LanguageAdmin::$modules, true);
             }
             die(_t("SUCCESSFULL_COLLECT", "The text was collected."));
         }
         if (isset($_POST["save"])) {
             $lang_array[$_POST["locale"]] = $_POST[$_POST["locale"]];
             $file = $_POST["file"];
             $yml_file = sfYaml::dump($lang_array);
             if ($fh = fopen($file, "w")) {
                 fwrite($fh, $yml_file);
                 fclose($fh);
                 file_get_contents("http://{$_SERVER['HTTP_HOST']}?flush");
             } else {
                 throw new LogicException("Cannot write language file! Please check permissions of {$langFile}");
             }
             die;
         }
         $files = $this->getFiles();
         if (isset($_POST["loadfiles"])) {
             //  die($this->getYaml($_POST["loadfiles"]));
             $this->customise(array("Translations" => $this->getYaml($_POST["loadfiles"]), "Modules" => $files, "Locales" => $locales_list));
             $content = $this->renderWith('LanguageAdmin_Content');
             return $content;
         } else {
             $this->customise(array("Modules" => $files, "Translations" => $this->getYaml($files->filter(array('Locale' => $locales_list->first()->Locale))->first()->Path), "Locales" => $locales_list, "CurrentLocale" => $locales_list->first()->LocaleName));
             $content = $this->renderWith('LanguageAdmin_Content');
             return $content;
         }
     } else {
         $files = $this->getFiles();
         $this->customise(array("Modules" => $files, "Translations" => $this->getYaml($files->filter(array('Locale' => $locales_list->first()->Locale))->first()->Path), "Locales" => $locales_list, "CurrentLocale" => $locales_list->first()->LocaleName));
         $content = $this->renderWith($this->getViewer('translate'));
         return $content;
     }
 }
 /**
  * Retrieves information about this object in the specified locale
  *
  * @param string $locale The locale information to request, or null to use the default locale
  * @return ArrayData Mapped list of locale properties
  */
 public function LocaleInformation($locale = null)
 {
     // Check locale
     if (empty($locale)) {
         $locale = Fluent::default_locale();
     }
     // Check linking mode
     $linkingMode = 'link';
     if ($this->owner->hasMethod('canViewInLocale') && !$this->owner->canViewInLocale($locale)) {
         $linkingMode = 'invalid';
     } elseif ($locale === Fluent::current_locale()) {
         $linkingMode = 'current';
     }
     // Check link
     $link = $this->owner->LocaleLink($locale);
     // Store basic locale information
     $data = array('Locale' => $locale, 'LocaleRFC1766' => i18n::convert_rfc1766($locale), 'Alias' => Fluent::alias($locale), 'Title' => i18n::get_locale_name($locale), 'LanguageNative' => i18n::get_language_name(i18n::get_lang_from_locale($locale), true), 'Link' => $link, 'AbsoluteLink' => $link ? Director::absoluteURL($link) : null, 'LinkingMode' => $linkingMode);
     return new ArrayData($data);
 }
 /**
  * Retrieves the list of locale names as an associative array
  *
  * @return array List of locale names mapped by locale code
  */
 public static function locale_names()
 {
     $locales = array();
     foreach (self::locales() as $locale) {
         $locales[$locale] = i18n::get_locale_name($locale);
     }
     return $locales;
 }
Esempio n. 16
0
 /**
  * Returns all languages with languages already used appearing first.
  * Called by the SSViewer when rendering the template.
  */
 function LangSelector()
 {
     $member = Member::currentUser();
     //check to see if the current user can switch langs or not
     if (Permission::checkMember($member, 'VIEW_LANGS')) {
         $dropdown = new LanguageDropdownField('LangSelector', 'Language', array(), 'SiteTree', 'Locale-English');
         $dropdown->setValue(Translatable::get_current_locale());
         return $dropdown;
     }
     //user doesn't have permission to switch langs so just show a string displaying current language
     return i18n::get_locale_name(Translatable::get_current_locale());
 }
Esempio n. 17
0
 /**
  * If the record is not shown in the default language, this method
  * will try to autoselect a master language which is shown alongside
  * the normal formfields as a readonly representation.
  * This gives translators a powerful tool for their translation workflow
  * without leaving the translated page interface.
  * Translatable also adds a new tab "Translation" which shows existing
  * translations, as well as a formaction to create new translations based
  * on a dropdown with available languages.
  * 
  * @todo This is specific to SiteTree and CMSMain
  * @todo Implement a special "translation mode" which triggers display of the
  * readonly fields, so you can translation INTO the "default language" while
  * seeing readonly fields as well.
  */
 function updateCMSFields(FieldSet &$fields)
 {
     // Don't apply these modifications for normal DataObjects - they rely on CMSMain logic
     if (!$this->owner instanceof SiteTree) {
         return;
     }
     $excludeFields = array('ViewerGroups', 'EditorGroups', 'CanViewType', 'CanEditType');
     // used in CMSMain->init() to set language state when reading/writing record
     $fields->push(new HiddenField("Locale", "Locale", $this->owner->Locale));
     // if a language other than default language is used, we're in "translation mode",
     // hence have to modify the original fields
     $creating = false;
     $baseClass = $this->owner->class;
     $allFields = $fields->toArray();
     while (($p = get_parent_class($baseClass)) != "DataObject") {
         $baseClass = $p;
     }
     // try to get the record in "default language"
     $originalRecord = $this->owner->getTranslation(Translatable::default_locale());
     // if no translation in "default language", fall back to first translation
     if (!$originalRecord) {
         $translations = $this->owner->getTranslations();
         $originalRecord = $translations ? $translations->First() : null;
     }
     $isTranslationMode = $this->owner->Locale != Translatable::default_locale();
     // Show a dropdown to create a new translation.
     // This action is possible both when showing the "default language"
     // and a translation. Include the current locale (record might not be saved yet).
     $alreadyTranslatedLocales = $this->getTranslatedLocales();
     $alreadyTranslatedLocales[$this->owner->Locale] = $this->owner->Locale;
     if ($originalRecord && $isTranslationMode) {
         $originalLangID = Session::get($this->owner->ID . '_originalLangID');
         // Remove parent page dropdown
         $fields->removeByName("ParentType");
         $fields->removeByName("ParentID");
         $translatableFieldNames = $this->getTranslatableFields();
         $allDataFields = $fields->dataFields();
         $transformation = new Translatable_Transformation($originalRecord);
         // iterate through sequential list of all datafields in fieldset
         // (fields are object references, so we can replace them with the translatable CompositeField)
         foreach ($allDataFields as $dataField) {
             if ($dataField instanceof HiddenField) {
                 continue;
             }
             if (in_array($dataField->Name(), $excludeFields)) {
                 continue;
             }
             if (in_array($dataField->Name(), $translatableFieldNames)) {
                 // if the field is translatable, perform transformation
                 $fields->replaceField($dataField->Name(), $transformation->transformFormField($dataField));
             } else {
                 // else field shouldn't be editable in translation-mode, make readonly
                 $fields->replaceField($dataField->Name(), $dataField->performReadonlyTransformation());
             }
         }
     } elseif ($this->owner->isNew()) {
         $fields->addFieldsToTab('Root', new Tab(_t('Translatable.TRANSLATIONS', 'Translations'), new LiteralField('SaveBeforeCreatingTranslationNote', sprintf('<p class="message">%s</p>', _t('Translatable.NOTICENEWPAGE', 'Please save this page before creating a translation')))));
     }
     $fields->addFieldsToTab('Root', new Tab('Translations', _t('Translatable.TRANSLATIONS', 'Translations'), new HeaderField('CreateTransHeader', _t('Translatable.CREATE', 'Create new translation'), 2), $langDropdown = new LanguageDropdownField("NewTransLang", _t('Translatable.NEWLANGUAGE', 'New language'), $alreadyTranslatedLocales, 'SiteTree', 'Locale-Native', $this->owner), $createButton = new InlineFormAction('createtranslation', _t('Translatable.CREATEBUTTON', 'Create'))));
     $createButton->includeDefaultJS(false);
     if ($alreadyTranslatedLocales) {
         $fields->addFieldToTab('Root.Translations', new HeaderField('ExistingTransHeader', _t('Translatable.EXISTING', 'Existing translations:'), 3));
         $existingTransHTML = '<ul>';
         foreach ($alreadyTranslatedLocales as $i => $langCode) {
             $existingTranslation = $this->owner->getTranslation($langCode);
             if ($existingTranslation) {
                 $existingTransHTML .= sprintf('<li><a href="%s">%s</a></li>', sprintf('admin/show/%d/?locale=%s', $existingTranslation->ID, $langCode), i18n::get_locale_name($langCode));
             }
         }
         $existingTransHTML .= '</ul>';
         $fields->addFieldToTab('Root.Translations', new LiteralField('existingtrans', $existingTransHTML));
     }
     $langDropdown->addExtraClass('languageDropdown');
     $createButton->addExtraClass('createTranslationButton');
 }
Esempio n. 18
0
 /**
  * @return String
  */
 public function getLongName()
 {
     return i18n::get_locale_name($this->value);
 }
 /**
  * Adds a translation section
  *
  * @param FieldList $fields The FieldList
  * 
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 04.04.2013
  */
 public function updateCMSFields(FieldList $fields)
 {
     $this->getCMSFieldsIsCalled = true;
     $fields->findOrMakeTab('Root.SEO')->setTitle($this->owner->fieldLabel('SeoTab'));
     $fields->findOrMakeTab('Root.SocialMedia')->setTitle($this->owner->fieldLabel('SocialMediaTab'));
     $fields->findOrMakeTab('Root.Translations')->setTitle($this->owner->fieldLabel('TranslationsTab'));
     $googleWebmasterCodeField = new TextField('GoogleWebmasterCode', $this->owner->fieldLabel('GoogleWebmasterCode'));
     $googleAnalyticsTrackingCodeField = new TextareaField('GoogleAnalyticsTrackingCode', $this->owner->fieldLabel('GoogleAnalyticsTrackingCode'));
     $googleConversionTrackingCodeField = new TextareaField('GoogleConversionTrackingCode', $this->owner->fieldLabel('GoogleConversionTrackingCode'));
     $piwikTrackingCodeField = new TextareaField('PiwikTrackingCode', $this->owner->fieldLabel('PiwikTrackingCode'));
     $fields->addFieldToTab('Root.SEO', $googleWebmasterCodeField);
     $fields->addFieldToTab('Root.SEO', $googleAnalyticsTrackingCodeField);
     $fields->addFieldToTab('Root.SEO', $googleConversionTrackingCodeField);
     $fields->addFieldToTab('Root.SEO', $piwikTrackingCodeField);
     $facebookLinkField = new TextField('FacebookLink', $this->owner->fieldLabel('FacebookLink'));
     $twitterLinkField = new TextField('TwitterLink', $this->owner->fieldLabel('TwitterLink'));
     $xingLinkField = new TextField('XingLink', $this->owner->fieldLabel('XingLink'));
     $fields->addFieldToTab('Root.SocialMedia', $facebookLinkField);
     $fields->addFieldToTab('Root.SocialMedia', $twitterLinkField);
     $fields->addFieldToTab('Root.SocialMedia', $xingLinkField);
     $translatable = new Translatable();
     $translatable->setOwner($this->owner);
     $translatable->updateCMSFields($fields);
     $localeField = new TextField('CurrentLocale', $this->owner->fieldLabel('CurrentLocale'), i18n::get_locale_name($this->owner->Locale));
     $createButton = new InlineFormAction('createsitetreetranslation', $this->owner->fieldLabel('createsitetreetranslation'));
     $publishButton = new InlineFormAction('publishsitetree', $this->owner->fieldLabel('publishsitetree'));
     $localeField->setReadonly(true);
     $localeField->setDisabled(true);
     $createButton->setRightTitle($this->owner->fieldLabel('createsitetreetranslationDesc'));
     $createButton->includeDefaultJS(false);
     $createButton->addExtraClass('createTranslationButton');
     $publishButton->includeDefaultJS(false);
     $publishButton->addExtraClass('createTranslationButton');
     $fields->addFieldToTab('Root.Translations', $localeField, 'CreateTransHeader');
     $fields->addFieldToTab('Root.Translations', $createButton, 'createtranslation');
     $fields->addFieldToTab('Root.Translations', $publishButton, 'createtranslation');
     $fields->removeByName('createtranslation');
     $this->getCMSFieldsForSilvercart($fields);
 }