Jump to:

23481 Posts in 18951 Topics by 2878 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: 3055 Views
  • yurigoul
    Avatar
    Community Member
    202 Posts

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

    ah, of course, that is what you get when gathering bits and pieces here and there and put them in your config because maybe they come in handy or maybe they will solve something.

  • theoldlr
    Avatar
    Community Member
    103 Posts

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

    @yurigoul
    My site does fit the description of your error... where not all pages have translations in each language. I will try your language switcher

    @Juanitou
    The error is clear, but it is not clear (to me) why I am getting it...

    Object::add_extension('SiteTree', 'Translatable');
    Translatable::set_default_locale('en_US');

    $allowed_locales = array(
    'en_US',
    'pt_BR',
    'es_CL'
    );

    Translatable::set_allowed_locales($allowed_locales);

    I'm not sure why it is not seeing the correct format 'pt_BR' as opposed to 'pt_br' that it is shown in the error.

    Is anyone aware of a list of locales that silverstripe recognizes? 'es_CL' Spanish (Chile) does not show up in the languages drop down, 'pt_BR' Portuguese (Brazil) does.

    Thanks!

  • Juanitou
    Avatar
    Community Member
    323 Posts

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

    Hi!

    I’m sorry, I don’t know what causes your error, even if I suspect the fact that some pages has not been translated.

    As for 'es_CL', it’s included in sapphire\core\i18n.php.

    Regards,
    Juan

  • yurigoul
    Avatar
    Community Member
    202 Posts

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

    But 'es_CL' is not in sapphire/lang (have a look at it to find the available translations)

    And although 'es_CL' is in sapphire/core/i18n.php ->public static $all_locales but that is not the list that is used to pick a translation, the list comes from $common_locales.

    I am setting my $common_locales in mysite/_config.php like this and it changes the menu just fine. I suspect you can add your translation there, even if one of them is not in the list.

    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;

    Next thing you do is add a lang dir to mysite and create a mysite/lang/es_CL.php there and you probably have to do that for all your languages if you want the messages on your site (front end) to be translated using the _t() function. If people also need to access the cms in es_CL you probably have to edit one of the spanish language files in sapphire/lang or if it is good enough you could just copy one of the spanish ones to es_CL.php. However I would not leave it there since it will be overwriten when you update silverstripe. I suspect it would work in mysite/lang but have not tried that...

    EDIT: the cms language files are of course in cms/lang ....

  • theoldlr
    Avatar
    Community Member
    103 Posts

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

    I've sorted through this a bit more and figured out what is causing the error...

    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
    ))
    );
    }
    }

    the line " $lang = i18n::get_lang_from_locale($code);" in most cases returns the language (i.e. 'pt' from pt_BR) by looking up 'pt_BR' in the $tinymce_lang array in i18n.php. However, in the case of 'pt_BR' what it returns is 'pt_br' because that is what is in the $tinymce_lang array. This explains where the 'pt_br' portion comes from that is found in my error.

    Later when "'name' => i18n::get_language_name($lang, true)" is called it uses in 'pt_br' to look up the language name in the $common_languages array in i18n.php. This is where I get the error because there is no 'pt_br' in that array. There is a 'pt-PT' and a 'pt-BR' though.

    Is this a mistake in the i18n.php file that you cannot use these two functions together for Portuguese (Brazil)? or is it the case that the methodology I'm using to do it is flawed? It would seem to me that it is an error with i18n since the method works for other languages, but I'm still new to this.

    Thanks!

  • theoldlr
    Avatar
    Community Member
    103 Posts

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

    All the right languages are showing up in the right places in the CMS now, but sometimes when I create translations it looks at the wrong original page. For example, I'll goto the media page and create a new translation from the translation tab. When the new translated page shows up, the original content might be from the products page. Any clue what is going on here? Any suggestions?

    Thanks!

    EDIT: Also, sometimes when I create a translation the page shows up in the translated site tree, but not as a translated page--it does not have "original content" type fields.

  • blaise4714
    Avatar
    Community Member
    10 Posts

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

    Hey Guys,
    i am new in silverstripe( a beginner) and i am trying to build a multilangual website. i use your codes to take an approach, i am getting back the following error message:
    [Notice] Trying to get property of non-object
    GET /silverstripe/
    38 'link' => "/?locale=" . $code,
    39 'urlSegment' => $page->URLSegment,
    40 'code' => $code,
    41 'shortCode' => substr($code, 0, 2),
    42 'current' => $current
    43 )));
    44 } else {
    45 $data->push(new ArrayData(array(
    46 'name' => i18n::get_language_name($lang, true),
    47 'link' => Director::baseURL() . $page->URLSegment, // here red
    48 'urlSegment' => $page->URLSegment,
    49 'code' => $code,
    50 'shortCode' => substr($code, 0, 2),
    51 'current' => $current
    52 )));
    53 }
    thank you in advance for your help

  • theoldlr
    Avatar
    Community Member
    103 Posts

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

    blaise4717,

    I think this is the error that was mentioned earlier in this thread. If you do not have a published translation for every page in each language you will get this error.

    You can avoid this by using a different switcher in your template. yurigoul mentions this in one of his earlier replies:

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

    3055 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.