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.

Archive /

Our old forums are still available as a read-only archive.

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

Problem with i18n translation for included .ss files


Go to End


12 Posts   18042 Views

Avatar
cliersch

Community Member, 75 Posts

25 April 2008 at 3:41am

Edited: 25/04/2008 3:42am

Hi there,

I have a problem with the i18 n translation. I guess there is a bug! The translation doesn't work when I call it from an included .ss file:

I use the file Includes/MyInclude.ss with the code inside:

<p>My Translation: <% _t('HELLO', 'Hello world') %></p>

And there is in the en_US.php language file
$lang['en_US']['MyInclude.ss']['HELLO'] = 'Hello world';

And the de_DE.php file width
$lang['de_DE']['MyInclude.ss']['HELLO'] = 'Hallo Welt';

The translation dosen't work! What's wrong?
Is anybody able to help me!
Cheers,
tiga

Avatar
Blynx

Community Member, 20 Posts

25 April 2008 at 1:11pm

Edited: 25/04/2008 1:12pm

My best guess would be that files are first included, then parsed by the i18n module. This means that instead of

$lang['de_DE']['MyInclude.ss']['HELLO'] = 'Hallo Welt';

you would have to use
$lang['de_DE']['<Name of file where MyInclude.ss is included>']['HELLO'] = 'Hallöchen';

Could you try that and see if it works?

Cheers, Blynx

Avatar
cliersch

Community Member, 75 Posts

25 April 2008 at 9:43pm

Thank you, it works!!! Fine!
But I guess it's not the way it should work! Normally I may use the include on multiple page types - now I have to write many similar translation code terms for every page-type?

Actually there are other problems; I'm trying to build a Blog with i18n translation (on the latest SilverStripe SVN Version).
Some code - the BlogManagementWidget.php e.g. has static parts (static $title = "Blog Management";) How does it work to translate this title?

On the BlogEntry page is also included the PageCommentInterface_singlecomment.ss
All translations here (like <% _t('REMCOM','remove this comment') %>) don't work.

What's wrong with the code?

cheers,
tiga

Avatar
Blynx

Community Member, 20 Posts

26 April 2008 at 5:51pm

Edited: 26/04/2008 5:53pm

Well, it depends - this way you can include your page snippet in numerous pages, and always have the translations that are appropriate. But this might be a feature to look at, you could open a ticket here http://open.silverstripe.com/report/1, and see what the development team thinks of it.

Translating the title of a widget cannot be done with the standard _t() function (yet). There's already a ticket for this issue, so hopefully this is possible soon: http://open.silverstripe.com/ticket/2102
As a workaround for now, you can use functions instead of the static variables:

  function Title(){
    return _t("Widget.TITLE","title of the widget");
  }
  
  function CMSTitle(){
    return _t("Widget.CMSTITLE","cmstitle of the widget");
  }
  
  function Description(){
    return _t("Widget.DESCRIPTION","description of the widget");
  }

I can't really follow you with the 3rd problem, as the PageCommentInterface_singlecomment.ss is part of the CMS in my installation, not the blog.

Cheers, Blynx

Avatar
cliersch

Community Member, 75 Posts

29 April 2008 at 3:07am

Thanx, great! That helped me a lot! :-)
I'm going to open your recommendet tickets for the include problem and the widget translation.

There is still the problem with the PageCommentInterface_singlecomment.ss. This is not a part of the blog module but needed for blog comments management (Called from the BlogEntry.ss Page). The translation works in a strange way. Some parts will only be translated when I'm in "logged in" status. Other parts like <% _t('REMCOM','remove this comment') %> don't work. I'm not able to comprehend why and when some included files will be correct translated! Any idea?

Avatar
Blynx

Community Member, 20 Posts

29 April 2008 at 5:37am

Which theme are you using?
I've looked in the original blog module (tarballs version from 28/4), the blackcandy theme and the itheme, none of the BlogEntry.ss files include a PageCommentInterface_singlecomment.ss - could you post the contents of your BlogEntry.ss please?

Also, have you tries copying the language file from the cms (where the PageCommentInterface_singlecomment.ss is located in my installation) to the blog (where it is included)?

Avatar
cliersch

Community Member, 75 Posts

29 April 2008 at 8:16pm

I'm using my own theme and the newest blog modul (checked out from http://svn.silverstripe.com/open/modules/blog/trunk) with the language assistance. There ist the Blog Entry.ss file:

<!--------------------------------------------- -->
<% include BlogSideBar %>
<div id="BlogContent" class="typography">
	<% include BreadCrumbs %>
	
	<div class="blogEntry">
			<h2>$Title</h2>
			<p class="authorDate"><% _t('POSTEDBY', 'Posted by') %> $Author.XML <% _t('POSTEDON', 'on') %> $Date.Long | $Comments.Count <% _t('COMMENTS', 'Comments') %></p>
				<% if Tags %>
					<p class="tags">
						 <% _t('TAGS', 'Tags:') %> 
						<% control Tags %>
							<a href="$Link" title="<% _t('VIEWALLPOSTTAGGED', 'View all posts tagged') %> '$Tag'" rel="tag">$Tag</a><% if Last %><% else %>,<% end_if %>
						<% end_control %>
					</p>
				<% end_if %>
			<p>$ParsedContent</p>
			<br />
	</div>
			<% if CurrentMember %><p><a href="$EditURL" id="editpost" title="<% _t('EDITTHIS', 'Edit this post') %>"><% _t('EDITTHIS', 'Edit this post') %></a> | <a href="$Link(unpublishPost)" id="unpublishpost"><% _t('UNPUBLISHTHIS', 'Unpublish this post') %></a></p><% end_if %>
			
	$PageComments

</div><!--------------------------------------------- -->

You see the $PageComments? This is not from the blog module!
Inside the folder cms/lang are the language files, e.g.

$lang['en_US']['PageCommentInterface_singlecomment.ss']['REMCOM'] = 'remove this comment';

But they translation does not work on my BlogEntry Page.
I also tried to change to
$lang['en_US']['BlogEntry.ss']['REMCOM'] = 'remove this comment';

but it's not working.

Avatar
Blynx

Community Member, 20 Posts

29 April 2008 at 8:49pm

Ah, I see. This is a tricky one.
I'll try to break it down for you a little:
- The $PageComments executes the equivalent function in \sapphire\core\control\ContentController.php, because the class BlogEntry_Controller extends Page_Controller extends ContentController.
- This function now returns an object called PageCommentInterface, which itself uses the PageCommentInterface.ss file to be rendered.
- In this file, the PageCommentInterface_singlecomment.ss is then included.

I don't know how much you're into PHP and Objects and if the above makes any sense (it's almost 2am here...), but basically this means that the appropriate line in your translation file should look like
$lang['en_US']['PageCommentInterface.ss']['REMCOM'] = 'remove this comment';

Unfortunately I can't test it here as I don't use any comments on my page.

Cheers, Blynx

Go to Top