•  
      request #37583 Placeholders order in translated strings
    Infos
    #37583
    Nicolas Terray (nterray)
    2024-04-22 17:47
    2024-04-15 18:41
    39172
    Details
    Placeholders order in translated strings

    Some sentences in Tuleap contains %s placeholder so that it can be replaced by the content of a variable at runtime.

    This works fine when there is a single placeholder in the sentence. But when there is more than one, for example user %s removed from project '%s', then there might be an issue with some locales that don't have the same order of words than the original english sentence.

    In order to don't have the issue, we must use ordered placeholders like so: user %1$s removed from project '%2$s', that way %1$s is always the first argument, and %1$s is always the second argument, regardless the position of the placeholder in the translated sentence.

    There are a lot of occurrence in existing codebase, it will be fixed by different contributions.

    Ideally we should have a tool to detect that we don't introduce new sentences containing unordered placeholders (CI, pre-commit, …).

    Translation / gettext / i18n
    All
    Empty
    • [ ] enhancement
    • [ ] internal improvement
    Empty
    Stage
    Empty
    Under implementation
    Empty
    Attachments
    Empty
    References
    Referencing request #37583
    Referenced by request #37583

    Follow-ups

    User avatar
    Joris MASSON (jmasson)2024-04-22 17:47

    suggestion: what do you think about finding another function than sprintf for that purpose ? %1$s is better than before but still far from "helping" for translators. In frontend codebase, we push for interpolation functions with more explicit placeholder names, like %{artifacts} or %{projects}. I suggest we do the same for PHP.
    I had looked some time ago, and I don't think sprintf allows to use named parameters like that.