Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django i18n: Specifying context. (msgctxt)

This page, about gettext generally, mentions the ability to specify a context for a string marked for translation. (http://www.gnu.org/software/gettext/manual/gettext.html#PO-Files) This helps when you have two instances of the same string in an application that have different meanings (e.g. "back" in one instance may mean "go back" while in another it may mean "not the front" -- it's possible that these are two different words in a foreign language)

Does Django's i18n allow you to specify a context?

like image 834
Dustin Rasener Avatar asked Jun 08 '26 16:06

Dustin Rasener


1 Answers

Yes since version 1.3 Django supports "Contextual Markers". See eg. this example from the documentation:

 from django.utils.translation import pgettext

 month = pgettext("month name", "May")
like image 139
Bernhard Vallant Avatar answered Jun 11 '26 13:06

Bernhard Vallant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!