Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix translation of messages with dot at the end #181

Merged
merged 8 commits into from
Feb 19, 2021
Merged

Fix translation of messages with dot at the end #181

merged 8 commits into from
Feb 19, 2021

Conversation

lulco
Copy link
Contributor

@lulco lulco commented Dec 16, 2020

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
Copy link
Contributor Author

lulco commented Feb 19, 2021

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

@enumag
Copy link
Member

enumag commented Feb 19, 2021

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
Copy link
Contributor Author

lulco commented Feb 19, 2021

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?

src/Translator.php Outdated Show resolved Hide resolved
Co-authored-by: Jáchym Toušek <enumag@gmail.com>
@enumag enumag merged commit 57124c2 into Kdyby:master Feb 19, 2021
@lulco lulco deleted the fix-message-with-dot-at-the-end branch February 19, 2021 19:47
nufue pushed a commit to inspire-develop/Translation that referenced this pull request Apr 27, 2022
* Fix translation of messages with dot at the end

* Fixed mixed indentations

* Fixed syntax error in test

* Rerun travis

* Fix Closure::fromCallable + coding standards

* Dot cannot be at last position

* Update src/Translator.php

Co-authored-by: Jáchym Toušek <enumag@gmail.com>

Co-authored-by: Jáchym Toušek <enumag@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants