Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Widgets /

Discuss SilverStripe Widgets.

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

SS 2.4.1 Tranlate Widget

Go to End



Community Member, 254 Posts

5 August 2010 at 3:29pm

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]

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


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()) {
                $langs = Translatable::get_existing_content_languages ();
                $data = new DataObjectSet();
                foreach(array_keys($langs) as $code) {
                        if($code == Translatable::current_lang() && !$this->ShowCurrent) {
                        $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.