Jump to:

23370 Posts in 18160 Topics by 2864 members

General Questions

SilverStripe Forums » General Questions » translatable partly working--questions on minor issues

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2 3
Go to End
Author Topic: 3006 Views
  • theoldlr
    Avatar
    Community Member
    103 Posts

    translatable partly working--questions on minor issues Link to this post

    I setup a few translation pages and it seems to work in part. Here are a few questions i have:

    1a) What security settings does a group need in order to access the language drop down to go to a translated site tree? (access to site content and access to all cms interfaces is not sufficient privilege for me) 1b)Is there a way to allow them access to only the translated site trees?

    2)For the homepage, example.com/?locale=de_DE works properly and goes to the translated homepage. Should this also work for other pages (i.e. example.com/pagename/?locale=de_DE should go the the translation of example.com/pagename)? (because it doesn't for me)

    3)The language chooser widget is mentioned in the multilingualcontent documentation, but installing it according to the included readme gives me site errors. Reading closer says that it is for the blog module only. Is this true? Am I missing something?

    Thanks in advance!

  • dendeffe
    Avatar
    Community Member
    135 Posts

    Re: translatable partly working--questions on minor issues Link to this post

    2) On my installation pages created through the translation tab are linked (you can switch languages and arrive at the specific page). If I create the page in a new language through the Create button in the page list, they are not linked.

  • theoldlr
    Avatar
    Community Member
    103 Posts

    Re: translatable partly working--questions on minor issues Link to this post

    Thanks for the reply, dendeffe. I deleted a page from the translated site tree and recreated it to be sure that I had made it via the translations tab, but it still did not work. They are linked (it shows there is a translation for this page in the primary site tree), but I cannot access it by adding /?locale=de_de to the end of the url. Any idea what might be wrong?

  • dendeffe
    Avatar
    Community Member
    135 Posts

    Re: translatable partly working--questions on minor issues Link to this post

    I think you are using a different language switcher. I've built mine from bits and pieces on the forum

    This is in my page.php

    <?php

    class Page extends SiteTree {
       
       public static $db = array(
       );
       
       public static $has_one = array(
       );
       

       
       /**
        * Returns a DataObjectSet with all available translations of the current page
        * @return DataObjectSet
        */
        function getTranslationsFunc() {
        if($this->URLSegment == "Security") return "";

        $langs = Translatable::get_existing_content_languages();
        $data = new DataObjectSet();

        // generate entry with only the default language if no translations of this page are available
        $availTransl = Translatable::getTranslations();
       

        foreach(array_keys($langs) as $code) {
        // get country code (e.g. "de")
        $lang = i18n::get_lang_from_locale($code);
        // current language?
        $current = ($code == Translatable::get_current_locale()) ? 'current': 'normal';
                
        $page = $this->getTranslation($code);
                //echo $page;exit();
                if(count($availTransl) == 0 && $current == "normal") {
           $data->push(new ArrayData(array(
           'name' => i18n::get_language_name($lang, true),
           'link' => "/?locale=" . $code,
           'urlSegment' => $page->URLSegment,
           'code' => $code,
           'shortCode' => substr($code, 0, 2),
           'current' => $current
           )));
                } else {
                   $data->push(new ArrayData(array(
           'name' => i18n::get_language_name($lang, true),
           'link' => Director::baseURL() . $page->URLSegment,
           'urlSegment' => $page->URLSegment,
           'code' => $code,
           'shortCode' => substr($code, 0, 2),
           'current' => $current
           )));
                }
        }

        return $data;
        }
       
       
    }

    class Page_Controller extends ContentController {
       
       public function init() {
          parent::init();

          // Note: you should use SS template require tags inside your templates
          // instead of putting Requirements calls here. However these are
          // included so that our older themes still work
          Requirements::themedCSS("layout");
          Requirements::themedCSS("typography");
          Requirements::themedCSS("form");
          if($this->dataRecord->hasExtension('Translatable')) {
           i18n::set_locale($this->dataRecord->Locale);
          }
          
       }
       
       
       
       /**
        * Returns a DataObjectSet with all available translations of the current page
        * @return DataObjectSet
        */
        function getTranslations() {
          
        // call method of Page Object
        return $this->getTranslationsFunc();
        }
       
       

    }

    ?>

    and this is my language switcher in the template

             <% if getTranslations %>
             <ul class="language">
             <% control getTranslations %>
             <li class="$current"><a href="$link"><span>$shortCode</span></a></li>
             <% end_control %>
             </ul>
             <% end_if %>

  • yurigoul
    Avatar
    Community Member
    202 Posts

    Re: translatable partly working--questions on minor issues Link to this post

    It works really nice, with links in the right language (Français instead of French), but only when all translations are there, otherwise it throws an error.

    So I stayed with the traditional language switcher and added things like <% if Locale == fr_FR %>Français<% end_if %>

  • theoldlr
    Avatar
    Community Member
    103 Posts

    Re: translatable partly working--questions on minor issues Link to this post

    Dendeffe,

    I tried using your language switcher, but I get errors. Is there perhaps something I'm not including in my config.php?:

    [Notice] Undefined index: pt_br
    GET /?flush=1

    Line 1506 in C:\website\sp\sapphire\core\i18n.php
    Source

    1497     *
    1498     * @see get_locale_name()
    1499     *
    1500     * @param mixed $code Language code
    1501     * @param boolean $native If true, the native name will be returned
    1502     * @return Name of the language
    1503     */
    1504    static function get_language_name($code, $native = false) {
    1505       $langs = self::$common_languages;
    1506       return ($native ? $langs[$code][1] : $langs[$code][0]);
    1507    }
    1508    
    1509    /**
    1510     * Get a name from a locale code (xx_YY).
    1511     *
    1512     * @see get_language_name()

    dendeffe, do you have a suggestion for this problem?

    yurigoul,

    Is this the same error you were referring to?

    Thanks guys, I know I let this thread get a little old.

  • yurigoul
    Avatar
    Community Member
    202 Posts

    Re: translatable partly working--questions on minor issues Link to this post

    I can not remember if this is the same error. The only thing I do know is that I had the following situation:

    In my site I had 4 possible translations: french, spanish, german and english

    Page X only has one translation, but is not translated in the other languages. And then an error is thrown if I use the function here. However if I do create the extra translations the error goes away.

    This is in my config (maybe that has something to do with it):

    Object::add_extension('SiteTree', 'Translatable');
    Translatable::set_default_locale('de_DE'); // This defines Translatable::current_lang() in Page.php

    // i18n
    i18n::enable();
    i18n::set_locale('de_DE');
    i18n::set_locale('en_US');
    i18n::set_locale('fr_FR');
    i18n::set_locale('es_ES');
    i18n::set_default_lang('de');

    // Define allowed locales overriding those present in i18n::$common_locales
    global $allowed_locales;
    $allowed_locales = array(
    'de_DE' => array('German', 'Deutsch'),
    'en_US' => array('English', 'English'),
    'fr_FR' => array('French', 'Français'),
    'es_ES' => array('Spanish', 'Español')

    );
    i18n::$common_locales = $allowed_locales;

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: translatable partly working--questions on minor issues Link to this post

    Hi all!

    @yurigoul
    I think your _config.php contains some lines you could remove:
    – i18n::set_locale('es_ES') is overwriting the three before it, so they are useless.
    – i18n::set_default_lang() is going to be deprecated in 2.4, you only need Translatable::set_default_locale().

    @theoldlr
    The error is pretty clear: you seem to not have defined 'pt_br' as a valid locale. By the way, it is not the valid format: pt_BR.

    Hope it helps,
    Juan

    3006 Views
Page: 1 2 3
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.