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

i18n Textcollector


Go to End


7 Posts   1255 Views

Avatar
suntrop

Community Member, 141 Posts

6 December 2016 at 9:44pm

The Developer Guide (https://docs.silverstripe.org/en/3/developer_guides/i18n/) tells me to run http://example.com/dev/tasks/i18nTextCollectorTask to see where my translations are, but the pages just prints out "Running Task i18n Textcollector Task" and nothing more.

I didn't install SS with composer, I upgraded just now from 3.1 to 3.5 and downloaded the PHPUnit manually into /vendor/bin/

What's the problem?

Avatar
martimiz

Forum Moderator, 1391 Posts

9 December 2016 at 2:02am

If you're translating a module, the first thing I would do is execute the task for that module only! Else the textcollector will try and renew translations for the entire site!

http://example.com/dev/tasks/i18nTextCollectorTask?module=mymodule

If I remember correctly, the collector will instantiate every class to track its translations, and some classes may throw an error, for instance if they want classes that can't be found for some reason. I rember that happening in respect tu PHPUnit...

Avatar
suntrop

Community Member, 141 Posts

9 December 2016 at 10:18pm

Thanks for that hint. I have no module, I have just some phrases in my templates.

Avatar
martimiz

Forum Moderator, 1391 Posts

9 December 2016 at 11:32pm

Ok - if the templates are located in mysite, then you can use module=mysite, and have a 'mysite/lang' folder that the collector can write to.

If they are in themes, it is harder, cause themes aren't modules. If its just a couple of phrases I usually skip the collector and just add the translations to the yml manually...

Avatar
suntrop

Community Member, 141 Posts

10 December 2016 at 3:47am

Phrases are in /themes/ and there are just a few.
The part about the yml file is a bit short here https://docs.silverstripe.org/en/3/developer_guides/i18n/#language-definitions

Where do I have to put the lang directory and how do I define a phrase/use in my template?

Avatar
martimiz

Forum Moderator, 1391 Posts

10 December 2016 at 8:34am

Edited: 10/12/2016 8:39am

To translate a string in a template, do

<% _t('CLassOrTemplateName.SOMEPHRASE', 'Some Phrase') %>

You can put that lang directory in mysite, then create a file mysite/lang/en.yml like so

en:
  ClassOrTemplateName:
    SOMEPHRASE: 'Some Phrase'
    SOMEOTHERPHRASE: 'Some other Phrase'

Then for another language xx.yml:

xx:
  ClassOrTemplateName:
    SOMEPHRASE: 'Some xx translation'
    SOMEOTHERPHRASE: 'some other xx translation'

'ClassOrTemplate' can be any name, but the idea is that the name points in the direction of the file where the translation is being used. So you could use something like MyTemplate_ss to make a distinction between classes and templates...

Originally in templates, you would omit 'ClassOrTemplateName': the languagefile would then just (autmatically) use the name of the template file. But that wouldn't always work with nested and included templates.

Avatar
suntrop

Community Member, 141 Posts

23 December 2016 at 12:55am

Thanks a million! I got it working … ok wasn't that hard, but the docs are pretty low-voiced about it :-)

Thanks makes the templates so much more readable!