Bug #37387

Translate Helper: Arguments replacement is not working for default value

Added by Krzysztof Daniel over 9 years ago. Updated over 9 years ago.

Status:
Resolved
Priority:
Must have
Category:
ViewHelpers
Start date:
2012-05-22
Due date:
% Done:

100%

Estimated time:
Has patch:
No

Description

I have following tag and there is no translation in xliff file yet for key 'something'

<f:translate id="something" arguments="{0: 'test'}">You haven't created a {0}, yet</f:translate>

Expected behavior would be that it will output:
You haven't created a test, yet

But argument replacement is not working for default message and output is now:
You haven't created a , yet

#1

Updated by Karsten Dambekalns over 9 years ago

  • Status changed from New to Accepted
  • Assignee set to Karsten Dambekalns
  • Target version set to 1.1 beta 2
#2

Updated by Karsten Dambekalns over 9 years ago

  • Status changed from Accepted to Needs Feedback
  • Target version changed from 1.1 beta 2 to 1.1

Right, but the fact that there is output is rather due to the fact that the VH itself does:

    $originalLabel = $value === NULL ? $this->renderChildren() : $value;
    …
        $translation = $this->translator->translateById($id, $arguments, $quantity, $localeObject, $source, $package);
        if ($translation === $id) {
            return $originalLabel;
        } else {
    …

So this is not really a "default value" but more a fallback - and doing placeholder resolving is anything but trivial (see FormatResolver->resolvePlaceholders).

#3

Updated by Krzysztof Daniel over 9 years ago

So what do you suggest? That this "translation by label" that shall be supported same way as by key and in my opinion even if label is not in translation files yet, placeholders shall be replaced.

#4

Updated by Krzysztof Daniel over 9 years ago

Any update on this?

#5

Updated by Bastian Waidelich over 9 years ago

Krzysztof Daniel wrote:

I have following tag and there is no translation in xliff file yet for key 'something'

<f:translate id="something" arguments="{0: 'test'}">You haven't created a {0}, yet</f:translate>

Expected behavior would be that it will output:
You haven't created a test, yet

Do you have a valid use case for this? Why not just type

<f:translate id="something" arguments="{0: 'test'}">You haven't created a test, yet</f:translate>

?

#6

Updated by Krzysztof Daniel over 9 years ago

Because the value comes form variable.

<f:translate id="something" arguments="{0: '{username}'}">Hello {0}</f:translate>

I could do something like

<f:translate arguments="{0: '{username}'}">Hello {username}</f:translate>

But than translation by label would not work properly.

#7

Updated by Bastian Waidelich over 9 years ago

Krzysztof Daniel wrote:

<f:translate arguments="{0: '{username}'}">Hello {username}</f:translate>
But than translation by label would not work properly.

I see, that makes sense. In that case it should work though (not specifying the id argument) - did you test it?

#8

Updated by Krzysztof Daniel over 9 years ago

But those are workarounds. Expected behavior shall be unified.

And if you look into real life example:

<f:translate id="notification.sender_and_date" arguments="{0: '{notification.sender}', 1: '{notification.createdAt -> f:format.date(format:\'d-m-Y H:i\')}'}">{notification.sender} {notification.createdAt -> f:format.date(format:'d-m-Y H:i')}</f:translate>

Execution of those helper multiple times is reaaaaaaly bad.

To make it work properly I expect that:

<f:translate arguments="{0: '{username}'}">Hello {0}</f:translate>

shall work and I can than use helpers in one place only etc.

Also our customer is extracting f:translate tags automatically to xliff files. And than they are translating it like:

<source>Hello {username}</source>
<target>Czesc {username}</target>

And in this case the variable replacing is not working anymore. And than the arguments array makes no sense. And it is hard to explain to customer / translator to replace {whatever} to {0} and {1} and {2}... in proper order only in xliff files.

#9

Updated by Karsten Dambekalns over 9 years ago

  • Status changed from Needs Feedback to Accepted

Krzysztof Daniel wrote:

Also our customer is extracting f:translate tags automatically to xliff files. And than they are translating it like:

Your provide the tool used and I'll fix this issue. Deal? ;)

#10

Updated by Gerrit Code Review over 9 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/12743

#11

Updated by Karsten Dambekalns over 9 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#12

Updated by Gerrit Code Review over 9 years ago

  • Status changed from Resolved to Under Review

Patch set 1 for branch FLOW3-1.1 has been pushed to the review server.
It is available at http://review.typo3.org/12869

#13

Updated by Karsten Dambekalns over 9 years ago

  • Status changed from Under Review to Resolved
  • Target version changed from 1.1 to 1.1 RC2

Also available in: Atom PDF