Skip to content

Conversation

@chaule97
Copy link

@chaule97 chaule97 commented Nov 4, 2024

odoo/odoo#52155

Starting from Odoo 14.0, the _() function supports named placeholders, which eliminates the need for manual string formatting like format() or %. I have written a script to convert old code to the new style.

  • convert _("It's %s") % 2024, _("It's %s") % (2024), _("It's {}").format(2024) to _("It's %s", 2024)

  • convert _("User %(name)s has %(items)s items") % {"name":"Dev", "items": 5}, _("User {name} has {items} items").format(name="Dev", items=5) to _("User %(name)s has %(items)s items", name="Dev", items=5)

  • show warning if we use unnamed placeholders in translated string, example: _("%s are only valid until %s", "User", 2024)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant