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

Silverstripe _t() function inside template problem [Solved]


Go to End


3 Posts   1284 Views

Avatar
darianno

Community Member, 14 Posts

28 March 2015 at 5:47am

Edited: 28/03/2015 5:56am

Hello!

I have installed latest version of SilverStripe (3.1.12) on my server and added Translatable module. I have problems with _t() function on template.

Ok here's my code:

mysite/_config.php

..
i18n::set_locale('sl_SI');
i18n::set_locale('en_US');
Translatable::set_default_locale('sl_SI');
Translatable::set_allowed_locales(array(
   'sl_SI', // Slovenian
   'en_US' // English
	)
);
..

.. so sl_SI is my default locale, en_US is secondary.

mysite/lang/en.yml

en:
  Categories:
    Cat1: Producent EN

mysite/lang/sl.yml

sl:
  Categories:
    Cat1: Producent

mytemplate.ss file

..
<%t Categories.Cat1 'Producent' %>
..

I'm always getting translation from English file (en.yml). What am I doing wrong?

I've done same thing (same configuration) on SS version 3.1.6 and works like a charm there.

Maybe some bug on new version or I forgot something?

Thank you for your help.

Avatar
wmk

Community Member, 87 Posts

28 March 2015 at 5:59am

Hi darianno,

setting up translatable can be very tricky. Youll have to set the current locale in your controller afaik. Zauberifisch once made a nice gist for that issue, maybe it helps.

BTW: don't forget to ?flush, otherwise Silverstripe doesn't know of any changes in the lang files!

Avatar
darianno

Community Member, 14 Posts

28 March 2015 at 6:07am

Edited: 28/03/2015 6:08am

Thank you @wmk !

This TranslatableControllerExtension from Zauberifisch works! I'm getting correct translations in template now.

Thanks!