Skip to content

add i18n support - #6796

Open
benedikt-bartscher wants to merge 111 commits into
reflex-dev:mainfrom
benedikt-bartscher:add-i18n
Open

benedikt-bartscher wants to merge 111 commits into
reflex-dev:mainfrom
benedikt-bartscher:add-i18n

Conversation

@benedikt-bartscher

@benedikt-bartscher benedikt-bartscher commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

closes #2339

@codspeed

codspeed Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 4.52%

3 warnings

⚠️ 20 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 1 benchmark with a significant change ran in a different software environment

Its base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the change might come from this difference rather than from the code. Open the benchmark to see what changed.

See affected benchmarks

❌ 1 regressed benchmark
✅ 145 untouched benchmarks
⏩ 8 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_proxy_list_mutation 9.3 ms 9.7 ms -4.52%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing benedikt-bartscher:add-i18n (f7b4c21) with main (df7f157)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@greptile-apps

greptile-apps Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest changes appear safe to merge; no new actionable issue was found.

Summary

Adds optional internationalization through reflex-i18n, including browser and server translations, locale-aware formatting, catalog commands, and URL-based language routes.

  • Reflex apps can translate text and format values using the active locale.
  • Locale-specific URLs render matching translations and language links.
  • The reflex i18n commands maintain app and library translation catalogs.
  • Plugins can provide event context, implied variable dependencies, and extra routes.
  • The optional i18n package is available through Reflex imports and its command line.

Reviews (70) · Last reviewed commit: "Hide and localize an embedded app's moun..." · Reviewed by Greptile

Comment thread reflex/__init__.py Resolved
@benedikt-bartscher
benedikt-bartscher marked this pull request as ready for review July 18, 2026 11:09
@benedikt-bartscher
benedikt-bartscher requested review from a team and Alek99 as code owners July 18, 2026 11:09
@benedikt-bartscher benedikt-bartscher changed the title first i18n wip add basic i18n support Jul 18, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6b9a5f5342

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/reflex-i18n/pyproject.toml Outdated
Comment on lines +12 to +13
"reflex-base >= 0.9.7.dev0",
"reflex >= 0.9.7.dev0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove development pins before publishing reflex-i18n

With the new dispatch-release option, selecting reflex-i18n will create a release and trigger .github/workflows/publish.yml, whose publish job runs scripts/check_min_deps.py --check-dev-pins "$PACKAGE" and explicitly rejects published dependencies containing *.dev pins. Because these two requirements are part of reflex-i18n's published metadata, the publish workflow for any reflex-i18n release will fail at that gate until they are pinned to released versions.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this open for the maintainers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still for the maintainers, but with the current picture after merging main (c00c5ff): reflex itself carries the same kind of pin (reflex-base >= 0.9.12.dev0), so a dev pin in-tree is the normal state and the publish gate is what forces the bump. reflex-i18n's constraint is genuinely unreleased — it needs register_event_scope_provider, register_implicit_dependency and ExpandRoutesContext, all added by this PR — so no published floor would be truthful, and I'd rather not invent one. It uses none of the API #7268 raised floors for. check_min_deps.py reflex-i18n passes; --check-dev-pins reports the pin as expected.

Comment thread reflex/reflex.py Resolved
@benedikt-bartscher benedikt-bartscher changed the title add basic i18n support add i18n support Jul 18, 2026
@benedikt-bartscher

Copy link
Copy Markdown
Contributor Author

@masenf could you please take a brief look at this from an architectural design and DX perspective? it's totally okay if you have smth completly different in mind

@masenf masenf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benedikt-bartscher thanks for adding this and sorry for the review back-up. i did an initial look and i think the added extension points make sense and the API feels nice.

one potential issue i see affects SEO performance of the SSG static versions of the site -- since the translation depends on state, other languages might not be indexable by crawlers.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 8 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread docs/i18n/overview.md Resolved
reflex leaves the optional reflex-i18n names out of __all__ when that
package is not installed, as in the isolated environment the build hook
generates stubs in. The published reflex/__init__.pyi then stopped
re-exporting rx.t and rx.i18n, so pyright rejected them even with
reflex-i18n installed. The stub's __all__ now comes from the lazy
mappings, through the same exported_names helper attach uses.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Patching os.path.relpath also broke Babel's per-file relpath in
extract_from_dir, so the test raised before reaching its assertion. It now
replaces only the reflex_i18n.cli module's os binding.
Language tags are case-insensitive, as are the router and the server and
client segment lookups, so locales such as "en" and "EN" named one route
twice and let the server and client resolve it to different spellings.
The per-event scope read i18n_state.router.page.path, which composes a
RouterData view and goes through the deprecated RouterData.page accessor
(stack walk plus a logged deprecation warning) on every event, cookie mode
included, and looked the plugin up twice. Look the plugin up once, read
rx_router_route_id only when the plugin routes locales through the URL,
and resolve Accept-Language from rx_router_headers in the locale var.

Warm event through BaseStateEventProcessor (memory manager): cookie mode
81 -> 32-37 us, URL routing 83-86 -> 34-41 us (no i18n: 23-26 us).
_resolve_plugin re-implemented get_plugin with its own isinstance scan and
silently took the first of several I18nPlugin entries. Use get_plugin, so a
duplicate raises the same ConfigError as every other lookup.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 6 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread docs/i18n/overview.md Resolved
…, and cover hiding the page for a non-default locale
… page's <html>, and document the hold's timeout and prerender limits

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/reflex-i18n/src/reflex_i18n/_web/i18n.js">

<violation number="1" location="packages/reflex-i18n/src/reflex_i18n/_web/i18n.js:49">
P2: This fallback lets an embedded provider mutate the host page when its mount selector temporarily matches no element. The embed entry captures the target before async imports, while this code re-queries it; if the host replaces or removes that element, locale updates can change `<html lang>`/`dir` and the locale hold can hide the host page. Do not fall back to `document.documentElement` when `MOUNT_TARGET` is configured; retain the mounted target or guard the missing-root case.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

// The element the app renders into: an embedded app (EmbedPlugin) owns only its
// mount target, never the host page's <html>.
const appRoot = () =>
(env.MOUNT_TARGET && document.querySelector(env.MOUNT_TARGET)) ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This fallback lets an embedded provider mutate the host page when its mount selector temporarily matches no element. The embed entry captures the target before async imports, while this code re-queries it; if the host replaces or removes that element, locale updates can change <html lang>/dir and the locale hold can hide the host page. Do not fall back to document.documentElement when MOUNT_TARGET is configured; retain the mounted target or guard the missing-root case.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/reflex-i18n/src/reflex_i18n/_web/i18n.js, line 49:

<comment>This fallback lets an embedded provider mutate the host page when its mount selector temporarily matches no element. The embed entry captures the target before async imports, while this code re-queries it; if the host replaces or removes that element, locale updates can change `<html lang>`/`dir` and the locale hold can hide the host page. Do not fall back to `document.documentElement` when `MOUNT_TARGET` is configured; retain the mounted target or guard the missing-root case.</comment>

<file context>
@@ -42,9 +43,16 @@ const RTL_LANGUAGES = new Set([
+// The element the app renders into: an embedded app (EmbedPlugin) owns only its
+// mount target, never the host page's <html>.
+const appRoot = () =>
+  (env.MOUNT_TARGET && document.querySelector(env.MOUNT_TARGET)) ||
+  document.documentElement;
+
</file context>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement Anything you want improved roadmap https://github.com/reflex-dev/reflex/issues/2727

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Internationalization (I18N) and localization (L10N) (Feature Request)

3 participants