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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

translatable partly working--questions on minor issues


Go to End


19 Posts   6058 Views

Avatar
yurigoul

Community Member, 203 Posts

6 January 2010 at 11:31pm

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.

Avatar
theoldlr

Community Member, 103 Posts

7 January 2010 at 9:05am

@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!

Avatar
Juanitou

Community Member, 323 Posts

7 January 2010 at 10:36pm

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

Avatar
yurigoul

Community Member, 203 Posts

7 January 2010 at 11:40pm

Edited: 08/01/2010 2:23am

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

Avatar
theoldlr

Community Member, 103 Posts

9 January 2010 at 6:07am

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!

Avatar
theoldlr

Community Member, 103 Posts

13 January 2010 at 5:24am

Edited: 13/01/2010 7:14am

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.

Avatar
blaise4714

Community Member, 10 Posts

23 January 2010 at 11:26am

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

Avatar
theoldlr

Community Member, 103 Posts

23 January 2010 at 11:49am

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 %>"