Jump to:

794 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » SS 2.4.1 Tranlate Widget

Discuss SilverStripe Widgets.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1116 Views
  • Bambii7
    Avatar
    Community Member
    254 Posts

    SS 2.4.1 Tranlate Widget Link to this post

    I can't see how I can get hold of the develop simon_w so I'll post the code here. This is in regards to Language Chooser Widget [v0.2.3] http://silverstripe.org/Language-Chooser-Widget-2/

    Nothing needs changing apart from LanguageChooser.php all the logic still works just some of the class/function names have changed.

    <?php

    class LanguageChooser extends Widget {
    static $title = "Language Chooser";
    static $cmsTitle = "Language Chooser";
    static $description = "Allows you to choose your language";

    static $db = array("ShowCurrent" => "Boolean");
    static $defaults = array('ShowCurrent' => false);

    function getCMSFields(){
    return new FieldSet(new CheckboxField('ShowCurrent', _t('LanguageChooser.SHOWCURRENT', 'Show current language')));
    }

    function Chooser() {
          if(!Controller::curr()) {
             return;
          }
    $langs = Translatable::get_existing_content_languages ();
    $data = new DataObjectSet();
    foreach(array_keys($langs) as $code) {
    if($code == Translatable::current_lang() && !$this->ShowCurrent) {
    continue;
    }
    $page = Translatable::get_one_by_lang("SiteTree", $code, "`SiteTree`.ID = " . Controller::curr()->ID);
    if(!$page) {
    $data->push(new ArrayData(array('name' => i18n::get_locale_name($code), 'link' => Director::protocolAndHost() . Director::baseURL() . '?locale=' . $code)));
    } else {
    $data->push(new ArrayData(array('name' => i18n::get_locale_name($code), 'link' => Director::protocolAndHost() . Director::baseURL() . $page->URLSegment . '?locale=' . $code)));
    }
    }
    return $data;
    }

    function WidgetHolder() {
    if(count(Translatable::get_existing_content_languages()) > 1) {
    return $this->renderWith("WidgetHolder");
    }
    return "";
    }
    }

    ?>

    The i18n::get_locale_name($code) returns the language name which is used as the link. There are free sets of flag icons fr unicode, it'd be very nice to include these as the link, optionally instead of language names.

    1116 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.