Skip to content

create_core_context

Builds the context every other call is made against. Build it once and reuse it.

python
from vue_i18n import create_core_context

ctx = create_core_context(
    locale="pt-BR",
    fallback_locale="en",
    messages={"pt-BR": {...}, "pt": {...}, "en": {...}},
)

Every argument is keyword-only.

Messages and locale

default
locale"en-US"The current locale, or a callable returning one (vue-i18n's LocaleDetector).
fallback_localethe localeA string, a list, a per-locale map, or False. See fallback locales.
messages{locale: {}}{locale: {key: message}}, nested or flat.
datetime_formats{locale: {}}Named Intl.DateTimeFormat option objects, per locale.
number_formats{locale: {}}Named Intl.NumberFormat option objects, per locale.

An option of the wrong type falls back to its default rather than raising. A translation layer that refuses to start because one option was misspelled is worse than one that warns and translates.

Missing keys and warnings

default
missingNone`(ctx, locale, key, type) -> str
missing_warnTruebool, or a compiled regex to narrow it to matching keys.
fallback_warnTrueSame, for falling back to another locale.
fallback_formatFalseWhen set, an unresolved key is rendered as a message rather than returned raw.
unresolvingFalseWhen set, an unresolved key returns NOT_RESOLVED (-1) instead of the key.
on_warnPython's warnings(message) -> None. Overrides the default channel entirely.

Rendering

default
modifiersbuilt-insExtra linked-message modifiers. upper, lower and capitalize are always present and win on a name clash, as upstream.
plural_rules{}{locale: (choice, choices_length) -> index}. See plural rules.
post_translationNone(result, key) -> result, applied to every translation.
processorNoneCustom type / interpolate / normalize, for building something other than a string.
escape_parameterFalseHTML-escape interpolated values. Read the caveat in differences before enabling.

Seams

Rarely needed, and here because upstream has them.

default
message_compilerthe built-in(source, ctx) -> message function.
message_resolvernested paths(messages, key) -> value. Pass resolve_with_key_value for flat keys only.
locale_fallbackerfallback_with_locale_chainThe fallback walker.
fallback_contextNoneAnother context to fall back to, vue-i18n's global-scope mechanism.
versionthe package versionReported as ctx.version.

Attributes worth knowing

python
ctx.current_locale       # `locale` resolved to a string, calling the detector if it is one
ctx.messages             # the resource, mutable - editing it takes effect on the next call
ctx.cid                  # a per-context id, as upstream

update_fallback_locale

python
from vue_i18n import update_fallback_locale

update_fallback_locale(ctx, "ca", {"ca": ["es", "en"], "default": ["en"]})

Changes the fallback and clears the chain cache. Assigning ctx.fallback_locale directly does not clear it, and the next lookup answers with the chain computed from the old value — a sharp edge inherited from upstream and reported as intlify/vue-i18n#2562.

Released under the MIT License. vue-i18n is © kazuya kawaguchi and contributors; this is an unofficial port and is not affiliated with intlify.