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

Where to store the multilanguage content?


Go to End


6 Posts   1622 Views

Avatar
pepperoni

Community Member, 1 Post

5 November 2009 at 1:16am

Hi,

my website uses multilingual content and for sure I have to translate my templates also. Example:

mymodule/templates/BigPage1.ss

<h1><% _t("TITLE1","This is the BigPage1.ss") %></h1>
<p><% include SmallPage %></p>

mymodule/templates/BigPage2.ss

<h1><% _t("TITLE2","This is the BigPage2.ss") %></h1>
<p><% include SmallPage %></p>

mymodule/includes/SmallPage.ss

<% _t("SAMPLE","Just a sample text.") %>

So, where to store the content now? Should I save the "en_US.php" in mymodule/lang/ or in mysite/lang/. What about contents in /themes/mytheme/ ? This is my first question, because I don't really get it, that you have to store the translated data in mysite/lang, when you translate your themes!? Ain't it?

Well, let's go to my second question: After finding where to store my translated pieces I should now how to save them. I've read that you always have to address the highest template, else the variable is not found. As far as I know the following code will not work

$lang['en_US']['SmallPage.ss']['SAMPLE'] = "The translated text";
$lang['en_US']['BigPage1.ss']['TITLE1'] = "Title of BigPage1";
$lang['en_US']['BigPage2.ss']['TITLE2'] = "Title of BigPage2";

at least for the including of the small page because you should use BigPage.ss instead. To make my example work I need the following, dont I?
$lang['en_US']['BigPage1.ss']['SAMPLE'] = "The translated text";
$lang['en_US']['BigPage2.ss']['SAMPLE'] = "The translated text";
$lang['en_US']['BigPage1.ss']['TITLE1'] = "Title of BigPage1";
$lang['en_US']['BigPage2.ss']['TITLE2'] = "Title of BigPage2";

are there any regulations to follow? I'd appreciate a link or an explanation to where the template content is searched by silverstripe. oh man, I wrote so much, I hope anybody answers...

Greetings
pepperoni

Avatar
dalesaurus

Community Member, 283 Posts

5 November 2009 at 6:42pm

Well I have read it but I am a bit daunted by your undertaking. This is some pretty advanced i18n work you're up to, this forum probably isn't the best place to get your hands dirty.

If you have a change try to catch one of the core team on IRC. Mentioning i18n issues always gets people excited!

Avatar
Fuzz10

Community Member, 791 Posts

5 November 2009 at 9:33pm

>This is some pretty advanced i18n work you're up to, this forum probably isn't
>the best place to get your hands dirty.

Advanced ? I disagree, this is a pretty basic question that pops up for everyone doing multi-lingual sites.

To be honest , I've always created my own IF -> THEN construction for translating template-content , because I wasn't sure about the LANG files construction. So I'm interested in the answer too.. ;)

Avatar
Willr

Forum Moderator, 5523 Posts

5 November 2009 at 9:58pm

I'm pretty sure the i18n TextCollector is designed to work with mysite/ folders. Noot too sure on themes, as they do have a slightly different setup but Perhaps try running

http://<mysite>/dev/tasks/i18nTextCollectorTask/?module=mysite

And see if that generates the lang folder in mysite with the translation templates.

For your individual modules you would just replace mysite with your module name.

Avatar
bummzack

Community Member, 904 Posts

5 November 2009 at 10:37pm

Edited: 05/11/2009 10:42pm

Hi pepperoni

Your translated file looks fine. Instead of using the template file as "namespace" you could also use an arbitrary string, like this:

$lang['en_US']['MySite']['SAMPLE'] = 'Sample US';

Then access it in the template like this:

<% _t('MySite.SAMPLE', 'Dummy') %>

This is useful, when you're using the same translation in multiple templates.

Your code should work the way it is now.. if it doesn't check the following:
- Did you enable i18n in the _config.php file? You have to call i18n::enable(); there.
- Do you set the current locale? You can hard-code it in your _config.php using: i18n::set_locale('xx_XX');.
- If you want the i18n locale set depending on the current "Translatable" language, put the following in your Page_Controller class:

public function init(){
	parent::init();
	
	if($this->dataRecord->hasExtension('Translatable')) {
		i18n::set_locale($this->dataRecord->Locale);
	}
}

Above code is taken from: http://doc.silverstripe.org/doku.php?id=multilingualcontent#setting_the_i18n_locale
Something like: i18n::set_locale(Translatable::get_current_locale()); would work as well.

HTH

Update Sorry, forgot to add: Yes, you would place your lang file in mysite/lang/

Avatar
dalesaurus

Community Member, 283 Posts

6 November 2009 at 5:07am

Advanced ? I disagree, this is a pretty basic question that pops up for everyone doing multi-lingual sites.

Ok, how about the honest answer: I am an uneducated rube when it comes to SS and i18n, and also a stupid American who generally assumes everyone speaks English. I will be of no use to the OP but I'd at least like to make the effort to let them know someone has read it.

Better fuzz? :)