Kdyby / Translation

Integration of Symfony/Translation into Nette Framework
https://packagist.org/packages/kdyby/translation
Other
89 stars 84 forks source link

Fix translation of messages with dot at the end #181

Closed lulco closed 3 years ago

lulco commented 3 years ago

If you have some strings like:

Hello. Hello world.

(with dot at the end), whole message is marked as domain, and id is empty, which leads to translation these messages as empty strings.

lulco commented 3 years ago

@enumag any chance this could be merge to near release?

enumag commented 3 years ago

I'm reluctant to fix this. Because then one might expect that any message will work but from what I gather a message with a dot in the middle will split into domain and message anyway, right? Unless this worked before and was broken later then I'd leave it as is I think.

lulco commented 3 years ago

Everything you mentioned works:

Hello.World works also Hello world.

I found that it is partially fixed in extractMessageDomain:

if (strpos($message, '.') !== FALSE && strpos($message, ' ') === FALSE) {

The only problem is if $id (message) is empty because symfony translator returns empty string:

if ('' === $id = (string) $id) {
    return '';
}

Maybe I just add condition to extractMessageDomain() that dot should not be last character?