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.

Template Questions /

Multi Language Issues


Reply


7 Posts   3697 Views

Avatar
dickv

Community Member, 3 Posts

22 July 2009 at 10:23am

I am developing a site in 2 languages, English and German. I have set up Translatable.

I woul like to setup the ability to create links in the template to switch between the 2 languages.

Here is the code I am using:

<% if Translations %>
<ul class="translations">
<% control Translations %>
<li class="$Locale.RFC1766">
   <a href="$Link" hreflang="$Locale.RFC1766" title="$Title">
<% sprintf(_t('SHOWINPAGE','Show page in %s'),$Locale.Nice) %>
   </a>
</li>
<% end_control %>
</ul>
<% end_if %>

This works for the German translation: It shows Show Page in German

It does no t work for the English translation, it shows Show Page in . It appears the variable

$Locale.Nice

is empty.

I then tried the following:

<% if Translations %>
<ul class="translations">
<% control Translations %>
<li class="$Locale.RFC1766">
   <a href="$Link" hreflang="$Locale.RFC1766" title="$Title">
<% if Locale.RFC1766 == en_NZ %>
    <% echo _t('SHOWINPAGE','Show page in English') %>
    <% else %>
    <% sprintf(_t('SHOWINPAGE','Show page in %s'),$Locale.Nice) %>
    <% end_if %>
   </a>
</li>
<% end_control %>
</ul>
<% end_if %>

It now comes with the following error message:

Parse error: syntax error, unexpected '}'

Avatar
kudesign

Community Member, 64 Posts

2 August 2009 at 7:21pm

Hi there, I am having the same problem, it switches languages for me, but it does not say ' Show page in <language>', instead it says '<% sprintf(_t('SHOWINPAGE','Show page in %s'),$Locale.Nice)%>'.... The system doesn't seem to recognize this line of code.

Any tips?

I am running v2.3.2 at the moment. Thanks for sharing!!!

Avatar
dickv

Community Member, 3 Posts

2 August 2009 at 8:31pm

Edited: 02/08/2009 8:32pm

Is there a space between

$Locale.Nice)

and

%>

Avatar
kudesign

Community Member, 64 Posts

3 August 2009 at 2:44am

Thanks for the reply. I entered the spaces,

<% sprintf(_t('SHOWINPAGE','Show page in %s'),$Locale.Nice) %>

and it reads a little better iin the live site, it says: 'Show page in' But it still does not type the 'language name'.

It must be something easy to do for the system to type the name of the available language, the information in the silverstripe doc require updating I think...

Please help silverstripe team!

Avatar
kudesign

Community Member, 64 Posts

3 August 2009 at 2:48am

When I take out .nice

<% sprintf(_t('SHOWINPAGE','Show page in % s'),$Locale) %>

In the English site it reads:

'Show the page in en_GB'

In the Chinese site it reads:

'Show the page in zh_TW'

Now I just need the system to translate en_GB to say 'English', and zh_TW to say 'Chinese'

PLEASE HELP!!

Avatar
Ingo

Forum Moderator, 801 Posts

23 August 2009 at 5:41pm

Hm, zh_TW is probably not in the i18n::$common_locales table, see http://doc.silverstripe.com/doku.php?id=multilingualcontent#add_new_locales

Avatar
lerni

Community Member, 80 Posts

1 December 2009 at 12:02am

just in case someone else is struggling with this as well. this post helped me:

http://silverstripe.org/template-questions/show/265935