Inconsistency between code and doc translation of modules
@kpodemski đang làm issue này rồi.
Từ ngày 14/7/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Prerequisites
- I understand and accept the project's code of conduct.
- I have already searched in existing issues and found no previous report of this bug.
Describe the bug and add attachments
Hello,
I tried to use the documentation way of translating in a module (in php files), using variables like %name%, but got an error when trying to translate "You must specify as many arguments (%d, %s ...) as the original string."
If instead of doing "The %name% does not exists" I do "The %s does not exists" it works.
Steps to reproduce
- Create a translation like that "$this->trans('The %name% does not exists', ['%name%' => $name], 'Modules.Mymodule.Admin');"
- Try to translate by something like "Le nom %name% n'existe pas"
- Save. It will display a success but will not actually save it.
- In Prestashop logs you will see the error "You must specify as many arguments (%d, %s ...) as the original string."
Expected behavior
The expected behavior would be to either fix the code to make it works like the doc says it should, or fix the doc to the way the code works.
Actual Result
The issue seem to come from the file "src\PrestaShopBundle\Translation\Constraints\PassVsprintfValidator.php" in the validate() function, where the test on the numbers of argument from original string and translated string return something different.
If we go in the function returning those numbers (same file function countArgumentsOfTranslation()) and display what is found by the regex used there, we can see that the original string will have one argument "% d" while the translated string will have no argument. That is because the regex seems to get "%" + optional number+ authorized letter in a list.
Since "n" is not in the list of authorized letter, the first "%" is ignored in both string and the second of the translated string to as it is followed by " n'existe", but since "d" is authorized, the second "%" of the original string is considered a variable as it is followed by " does".
Using codes like in sprintf seems to works as the list of authorized letters is mostly similar to what is found in the PHP doc of sprintf.
The used regex is in file "src\PrestaShopBundle\Translation\PrestaShopTranslatorTrait.php" and look like this: "#(?:%%|%(?:[0-9]+$)?[+-]?(?:[ 0]|'.)?-?[0-9]*(?:.[0-9]+)?[bcdeufFosxX])#"
PrestaShop version where the bug happens
9.0.0
Module version where the bug happens
1.0.0
PHP version(s) where the bug happened
8.3
Your company or customer's name goes here (if applicable).
No response
- Ngôn ngữ chính
- Scala
- Star
- 137
- Fork
- 559
- Merge trung bình
- 5 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PrestaShop/docs
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
PrestaShop/docs#1390 ·
-
Docs 1.7: You advise to use FrameworkBundleAdminController but templating part is not updatedĐang mởquestion
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
PrestaShop/docs#1049 ·
-
8.x Version specific
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 52/100
PrestaShop/docs#1998 ·
-
Handling catpchasĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
PrestaShop/docs#1985 · 2 bình luận ·
-
improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
PrestaShop/docs#1784 · 1 reaction ·
Tất cả issue của PrestaShop/docs
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
com-lihaoyi/mill#7998 ·
Maintainer thường phản hồi trong vòng 1 ngày