Skip to main content

vue-i18n-python

An unofficial Python port of vue-i18n. Not affiliated with or endorsed by intlify; vue-i18n is © kazuya kawaguchi and contributors, MIT licensed.

Same JSON message files, same API, same behaviour — in Python. The point is a Vue front end and a Python back end reading one set of translations and producing the same strings from them.

import json

from vue_i18n import create_core_context, translate

ctx = create_core_context(
    locale="sl",
    fallback_locale="en",
    messages={                                     # the files your front end already loads
        "sl": json.load(open("locales/sl.json")),
        "en": json.load(open("locales/en.json")),
    },
)

translate(ctx, "hello", {"name": "Jure"})          # 'Zdravo Jure'
translate(ctx, "trips", 5)                         # plural form for 5

docs.velis.si/vue-i18n-python is the manual.

Why this exists, and who should not use it Rationale
Installing it and the call shapes Getting started
The one thing that surprises people Plural rules
Where it deliberately differs from vue-i18n Differences
Every public function API reference

Message files are ordinary vue-i18n resources: {named} placeholders, {0} positional values, a | b | c plurals, @:linked messages, @.upper: modifiers, {'@'} literals. Nothing asks you to migrate a file or learn a syntax, and vue-i18n-extract and the rest of the toolchain keep working.

Option names are vue-i18n's, in snake_case: fallbackLocale is fallback_locale, missingWarn is missing_warn.

Checking what you wrote

t("cart.emty") does not fail — it renders the key and waits for a customer to find it. The bundled checker finds it first, on both ends of the project:

python -m vue_i18n.check locales/ --source backend/ --source frontend/src

Broken @:links, messages that will not compile, keys one locale is missing, keys the code asks for and no locale has. Python is parsed; .vue and .ts are pattern-matched, which is approximate and labelled so — and still more than xgettext, which cannot open a .vue file at all.

How faithful is it?

Faithful enough that the claim is checked rather than asserted. Every part of the port is recorded against the real thing and replayed on every test run:

corpus what it pins
conformance/translate.json 57 translate() calls against @intlify/core-base itself
conformance/render.json 74 messages rendered by real vue-i18n
conformance/compile.json 128 messages: ASTs, error codes, error messages, source locations
conformance/resolve.json 200 key-path resolutions
conformance/fallback.json 374 fallback chains
conformance/display.json 1612 values through JavaScript's String() semantics

The recordings are generated by running upstream, never written by hand — scripts/conformance/README.md says how to regenerate them.

Following upstream

This port tracks vue-i18n's released versions, never a pre-release. Upstream is a git submodule pinned to the version being tracked, so "which vue-i18n does this match" is answered by a checkout rather than by a claim. UPSTREAM.md records the pin, maps every module to the upstream file it came from, and holds the procedure for moving to a new release.

Where it differs

Some differences are forced by the platform: JavaScript strings are UTF-16 and Python's are not, Intl does not exist here so d() and n() go through babel with different CLDR data, and a Python int stays exact past 2^53.

Others are chosen, and each one is written down in PROGRESS.md with the reasoning, a comment at the site and a test that asserts it. GAPS.md lists what is knowingly missing.

Plural rules

If your Vue application already passes pluralRules to createI18n, pass the same rule here and nothing changes. A rule is (choice, choices_length) -> index, the same signature as in JavaScript, so it transcribes directly:

def south_slavic(choice, choices_length, _org=None):
    if choices_length == 2:
        return 0 if choice == 1 else 1
    ...

ctx = create_core_context(..., plural_rules={"sl": south_slavic})
translate(ctx, "trips", 103)     # '103 povezave' - the fourth form, as in the browser

If you pass no rule, you get vue-i18n's default, and that default ignores the locale: two forms mean singular/plural, and anything more clamps at index 2, so a fourth or fifth form is unreachable in any language. This port reproduces that rather than quietly improving on it — the same message with no rule renders 3 povezavi, 5 povezavi and 105 povezavi — the count interpolates, the ending is what sticks — here and in the browser alike.

vue_i18n.plurals is there if you would rather not hand-write the rule. It is opt-in; the runtime never reaches for it. It carries CLDR rules for 224 locales, an explicit zero form that CLDR does not have, and a ladder for messages with fewer forms than the locale has categories. Note that it will not agree with a hand-written rule in every case — if your front end has one, port that one, and keep the two ends identical.

Status

Early, and honest about it — see PROGRESS.md for what exists and GAPS.md for what does not.

License

MIT

Metadata

Release files for vue-i18n-python 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vue-i18n-python 0.2.0
File Size Uploaded Provenance Actions
vue_i18n_python-0.2.0.tar.gz 148.9 kB Without provenance Details for vue_i18n_python-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vue-i18n-python 0.2.0
File Interpreter ABI Platform Actions
vue_i18n_python-0.2.0-py3-none-any.whl Python 3 none any Details for vue_i18n_python-0.2.0-py3-none-any.whl

Total release size: 238.2 kB

Release files / vue_i18n_python-0.2.0.tar.gz

Download URL vue_i18n_python-0.2.0.tar.gz
Size 148.9 kB
Tags Source
SHA-256 checksum
How to use checksums
edca0cca3477a84cd447bd400fa5f894965539317fa3281e126f0b0257185dcf
BLAKE2b-256 checksum
How to use checksums
bea5cef4dc606ea45e13b4859cbc615a128d1d183baf87dc1294ef8542416113
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.2

Release files / vue_i18n_python-0.2.0-py3-none-any.whl

Download URL vue_i18n_python-0.2.0-py3-none-any.whl
Size 89.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
086f96ebea3cdeb835c1ada1487ea38bf83e16a2b52eb4debb931a4a6407f6fe
BLAKE2b-256 checksum
How to use checksums
b1e5595e7f1200496717310af6ce1ff9ffabd44dcfb71d01266b24f595123be0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.2

Security for vue-i18n-python 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page