# msgctxt

Source: https://zotonic.com/docs/3130/msgctxt

URI: https://zotonic.com/id/3130

Language: en



Set a template's default gettext message context:

```django
{% msgctxt "shop: checkout" %}
<h2>{_ Order _}</h2>
{% button text=_"Continue" %}
```

Declare it once, before output or blocks. An `extends` or `overrules` tag may precede it. The context must be a literal string and is extracted as `msgctxt` in the POT file. Use stable semantic labels, rather than template filenames.

The default applies to `{_ ... _}`, `_"..."`, and `{% trans ... %}` messages. Override it with <a href="/id/doc_template_tag_tag_with_msgctxt" class="doc-reference doc-reference-tag"><code>tag#with_msgctxt</code></a> or an explicit `msgctxt` argument on <a href="/id/doc_template_tag_tag_trans_ext" class="doc-reference doc-reference-tag"><code>tag#trans_ext</code></a>. Included and inherited templates use their own declarations.

For each language, lookup tries the contextual translation and then the contextless translation. It then tries fallback languages, finally using the English source. An empty context string is distinct from no message context.

Adding a context creates new catalog identities. Existing contextless translations remain usable through fallback while contextual entries are translated.

A module can supply the default for all its templates using an attribute on its module Erlang file, alongside `mod_title` and `mod_description`:

```erlang
-mod_msgctxt("shop: checkout").
```

The selected template file's owning module supplies this default, including when templates override another module's templates. Includes and inherited templates each use their own module's default. A template's `msgctxt` declaration overrides the module default; scopes and explicit `trans` arguments override it in turn. An explicitly empty context remains an override.

POT extraction uses the same default. The attribute applies to templates; Erlang translation calls and macros continue to take their message context explicitly. Modules without the attribute retain their existing behavior.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/3130?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/3130?language=en>)
