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

Interference character | (Straight line) In trans_choice function #53289

Open
MohammadZarifiyan opened this issue Oct 24, 2024 · 3 comments
Open

Comments

@MohammadZarifiyan
Copy link

Laravel Version

11.29

PHP Version

8.1

Database Driver & Version

No response

Description

When I use trans_choice and use straight line symbol (|) in the parameters, it causes the sentence structure to be messed up. It seems that Laravel first places the parameters in the sentences and then selects the sentence based on the number parameter in trans_choice. While the correct way is to first select the correct sentence in terms of number, then replace the parameters.

Steps To Reproduce

home.php file:

return [
   'greeting' => '{0} Hello :name|[1,*] Hello :name, you have :count unread messages'
];

Usage:

trans_choice('home.greeting', 0, ['name' => 'Alex | Moi']);

Above code must result in Hello Alex | Moi, But it results to Hello Alex.

Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@zakariaarrid
Copy link

@MohammadZarifiyan
try using HTML encoding for the pipe for quick solution
trans_choice('home.greeting', 0, ['name' => 'Alex | Moi']);

@ShowravBiswas
Copy link

You can use a custom placeholder

{!! str_replace('__PIPE__', '|', trans_choice('home.greeting', 0, ['name' => 'Alex __PIPE__ Moi'])) !!}

Above code return your desired result which is : Hello Alex | Moi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants