How do I output the translation of a Topic?

Permalink
Hi all,

I am building a multi-language site in c5 v5.7.5.2. I use Topics quite frequently and in one custom block, I list files according to a Topic attribute.

Since Topic names show up in the Site Translate Interface, I understand that I can translate them. I have tried to use tc() in the block controller to get the translation, i e like this in the view() method:

$this->set("topicTest", tc('Manuals', 'TreeNodeCategoryName'));


However it only outputs the context ('TreeNodeCategoryName').

Any idea how I do this? Are t()/tc() the right way to get the translations of Topics?

B r, joolss

 
mlocati replied on at Permalink Best Answer Reply
mlocati
As described in the manual (seehttp://documentation.concrete5.org/developers/concepts/localization... ), instead of
$this->set("topicTest", tc('Manuals', 'TreeNodeCategoryName'));

you should write
$this->set("topicTest", tc('TreeNodeCategoryName', 'Manuals'));
joolss replied on at Permalink Reply
OK, thanks, I had totally misunderstood the docs.

After updating my code, the source code reference shows up in the Translate Site Interface when I edit the topic in the current language.

However, It still doesn't output the translation, only "Manuals".

I have reloaded strings, saved the transl. file etc, have caching turned off.
mlocati replied on at Permalink Reply
mlocati
Could you try to replace TreeNodeCategoryName with those strings and re-translate it?
- Topic
- TopicCategoryName
- TopicName
- TreeName

I don't remember which is the correct one...
joolss replied on at Permalink Reply
Tried them all, but they only add a new entry (each with the specified context) in the lang file. I can't output any of them.

In the Translate Interface, I
- click "Reload strings",
- select the current language,
- search and finds the text,
- edits, and "Save to file",
- "Back To List",
- "Save to file" in the overview.
mlocati replied on at Permalink Reply
mlocati
I'm sorry but I can't help you anymore, I haven't worked with topics so far...
joolss replied on at Permalink Reply
Hehe, cool, thanks for all the help so far.
nmpribeiro replied on at Permalink Reply
Hi joolss,

Have you been able to understand better why it doesn't work?

I've found my concrete/blocks/topic_list/templates/flat_filter.php
there, under the li>a, I've done these:

<?php
                echo $child->getTreeNodeDisplayName().'<br>';
                echo tc('TopicName', $child->getTreeNodeDisplayName()).'<br>';
                echo tc('TopicName', 'Test Topic');
?>

I get 3 topic names, 1 the old plain displayName (not translated), then the correct displayName (but not translated, altho we tried the translate context method), and a 3rd the actual 'Test Topic' (not translated as well).

I have saved all translations, dealing with correct contexts (the translation interface has the context there), no caching activated, but no success.

Anyone bumped into this in the past?

** Edit:
I've just tested a plain old 'echo t('Yes');' and it doesn't translate either. Is translation being avoided on these views generation?

*** Edit:
ok, if I set the locale manually in php previous to the t() and tc() methods, I can get the translations. So there is something going on with the Localization mechanism deep down the view generation. So I am now trying to get the current locale so I can manually set it to workaround this huge bug, but it gives me this error:
Call to undefined method Concrete\Core\Block\View\BlockView::getActiveTranslateObject()
mlocati replied on at Permalink Reply
mlocati
Do you have the wrong locale when you're logged in? Or as a guest user?
nmpribeiro replied on at Permalink Reply
Thanks mlocati: Fixed - due to user language overlapping current page language (explained elsewhere)
buurvrouw replied on at Permalink Reply
buurvrouw
I've had a problem with topics not being able to translate with SkyBlueSofa's PageList+ He helped me solve it. It turned out to be something in the core.

The solution was to replace code getTreeNodeName() to getTreeNodeDisplayName('text')
in the the getTreeNodeDisplayPath() in /concrete/src/Tree/Node/Node.php on line 207

See the complete code here:https://www.concrete5.org/marketplace/addons/page-list/support/topic...

That solved it for me.