charger Posted September 29, 2021 Share Posted September 29, 2021 I’m on PW 3.0.184 and PHP 7.3.3 and have an issue when I insert a \n into a translation string. The string shows up correctly in the language translator in the backend. However, if I translate the string and then echo it via template file, it won’t return the translated string but its default value. As soon as I remove the \n out of the translation string, the translated value is correctly returned. I used the example from the docs to test: $out = __("It's time for you \nto get to the party."); // good Can someone confirm this? Link to comment Share on other sites More sharing options...
horst Posted September 29, 2021 Share Posted September 29, 2021 I cannot find any example with newline character in the docs? Do I oversee something? I thought that escape characters are not supported by the translation. If I'm right, maybe it should be written explicitly in the docs too. I think the right usage is or can be like this: // use %s with sprintf() $out = sprintf(__("It's time for you %sto get to the party."), "\n"); 1 Link to comment Share on other sites More sharing options...
charger Posted September 29, 2021 Author Share Posted September 29, 2021 OK, will try to use variables then to insert the newline character. But it’s definitely in the docs. See the attached screenshot. 1 Link to comment Share on other sites More sharing options...
horst Posted September 29, 2021 Share Posted September 29, 2021 1 hour ago, charger said: But it’s definitely in the docs. See the attached screenshot. Ok, I see. Then you should post an issue on github. Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted September 29, 2021 Share Posted September 29, 2021 Hey, @charger! I just faced the same problem recently. You can make it work like you expect by using single quotes like this: $out = __('It\'s time for you \nto get to the party.'); Though I would love to see it work with double quotes too) 1 Link to comment Share on other sites More sharing options...
charger Posted September 30, 2021 Author Share Posted September 30, 2021 That I noticed too. But in my case I have to use double quotes as I also use variables within the string. Tried every combination I could think of ? Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted September 30, 2021 Share Posted September 30, 2021 Use single quotes + sprintf. That's what I did. Read the docs about placeholders. Link to comment Share on other sites More sharing options...
charger Posted September 30, 2021 Author Share Posted September 30, 2021 When using single quotes \n is not interpreted as newline character. Btw. GitHub issue was created. 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted September 30, 2021 Share Posted September 30, 2021 Ok, I think I did a str_replace: str_replace('\n', '<br>', $string); And added a thumbs up for your issue) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now