Search code examples
syntaxgettext

gettext PO files syntax


Can I make different translation in different places?

For example:

#: orders/models.py:49 templates/products_list.html:54
msgid "Order"
msgstr "Заказать"

But I want anything like this (it's not working)

#: orders/models.py:49
msgid "Order"
msgstr "Заказ"
templates/products_list.html:54
msgid "Order"
msgstr "Заказать"

Solution

  • You can use the context parameter of the pgettext function to select different translations. In the po file this would look as follows:

    #: orders/models.py:49
    msgctxt models
    msgid "Order"
    msgstr "Заказ"
    
    templates/products_list.html:54
    msgctxt products
    msgid "Order"
    msgstr "Заказать"