3214 Posts in 848 Topics by 810 members
| Go to End | Next > | |
| Author | Topic: | 3657 Views |
-
Re: Translating static content

10 May 2011 at 3:02am
When I add "i18n::set_locale('en_GB');" it also finds the English translation, but it doesn't seem to get the difference between the sites. Now it even overwrites the Dutch translations. When viewing the source code it also shows the right languages in the "<html lang="nl-NL" lang="nl-NL" xmlns="http://www.w3.org/1999/xhtml">" line.
What am I doing wrong? My config now looks like this;
// Set the site locale
Translatable::set_default_locale('nl_NL');Object::add_extension('SiteTree', 'Translatable');
Object::add_extension('SiteConfig', 'Translatable'); // 2.4 or newer onlyi18n::set_locale('nl_NL');
i18n::set_locale('en_GB'); -
Re: Translating static content

21 June 2011 at 12:18am
Is there maybe somebody else who knows a solution to this problem?
-
Re: Translating static content

5 August 2011 at 2:25am
You need to put that in your Templates:
<% _t('Page.ss.SEARCH','Search') %>
The reason for this is that you are calling an array.
You stored your Translation in: $lang['nl_NL']['Page.ss']['SEARCH']
You need to call _t('Page.ss.SEARCH')So what you basically do is seperate each value in the $lang array by a dot (.)
-
Re: Translating static content

5 August 2011 at 11:22pm Last edited: 5 August 2011 11:27pm
@Pixelspin, I'm having the exact same issue and it seems there's something messed with the silverstripe's implementation of i18n.
Let me explain it one more time for the others:
In my /mysite/ directory I've made a new one called /lang/. Inside I've created 2 files:
es_ES.php, with the following contents:<?php
global $lang;
$lang['es_ES']['Header']['HELLO_MSG'] = 'Hola';
?>
en_US.php, with the following contents:<?php
global $lang;
$lang['en_US']['Header']['HELLO_MSG'] = 'Hello';
?>Dynamic content on the website is already translated using the Translatable class, so now when I go to http://<domain>/hello it shows me dynamic content in English, and correspondingly the Spanish content at http://<domain>/hola
Here's the problem with i18n - it doesn't change the locale automatically, even though the site engine knows what language is being displayed. My _config.php file contains the line: i18n::set_locale('es_ES'); and it feels like i18n takes for granted that's the current language all the time.
When the Page.ss template contains this:
<% _t('Header.CHOOSE_COUNTRY') %> $ContentLocale
I always get the hello message in Spanish, no matter which language version of page I'm browsing (/hola or /hello), whilst the $ContentLocale changes depending on the current lang.I know I could call the i18n::set_locale method in a controller and therefore force the website to show content in the right language but shouldn't this be an automatic behavior? After all if $ContentLocale is set properly upon every request, then why the locale isn't?
I'm using the latest stable SS version 2.4.5, and XAMPP 1.7.3.
-
Re: Translating static content

6 August 2011 at 3:30am
Hi there
SilverStripe doesn't automatically set the correct i18n locale for pages translated by translatable. Try and put the following in your Page_Controller init() function, to force the correct locale for the current page:
public function init() {
parent::init();if($this->dataRecord->hasExtension('Translatable')) {
i18n::set_locale($this->dataRecord->Locale);
}
...Also read the SilverStripe Translatable documentation on github:
https://github.com/silverstripe/silverstripe-translatable/blob/master/docs/en/index.md
-
Re: Translating static content

6 August 2011 at 4:51am
Thanks for help martimiz, your solution works like a charm.
btw. I think it would be worth pointing out in silverstripe's i18n documentation that pages translated by translatable require that additional effort.
-
Re: Translating static content

22 November 2011 at 4:10pm
martimiz, I know you answered months ago, but this solution saved me today. I was completely stumped until I stumbled upon this little gem. Worked perfectly. Thanks.
-
Re: Translating static content

25 November 2011 at 5:17pm
Spoke too soon. All my translations are working perfectly, but the javascript translations for the validator - eg (Please fill out "%s", it is required) are no longer switching languages along with everything else.
| 3657 Views | ||
| Go to Top | Next > |




