Inconsistency between code and doc translation of modules

未关闭
#2,148 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@kpodemski 已经在做这个了。

开始于 2026年7月14日。

评估

这个 Issue 还没有评估数据。

描述

Prerequisites
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
  1. Create a translation like that "$this->trans('The %name% does not exists', ['%name%' => $name], 'Modules.Mymodule.Admin');"
  2. Try to translate by something like "Le nom %name% n'existe pas"
  3. Save. It will display a success but will not actually save it.
  4. 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

主要语言
Scala
星标
137
派生
559
平均合并
5 天 12 小时
30 天内合并 PR
6

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

PrestaShop/docs 的其他 Issue

查看 PrestaShop/docs 的全部 Issue

相似的 Issue

更多 Scala Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。