Repository navigation
add i18n support - #6796
add i18n support#6796benedikt-bartscher wants to merge 111 commits into
Conversation
Merging this PR will degrade performance by 4.52%3 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
[Medium impact] The latest changes appear safe to merge; no new actionable issue was found. SummaryAdds optional internationalization through
Reviews (70) · Last reviewed commit: "Hide and localize an embedded app's moun..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 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".
| "reflex-base >= 0.9.7.dev0", | ||
| "reflex >= 0.9.7.dev0", |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
I'll leave this open for the maintainers
There was a problem hiding this comment.
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.
|
@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
left a comment
There was a problem hiding this comment.
@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.
e68fb65 to
3e540c0
Compare
There was a problem hiding this comment.
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
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.
There was a problem hiding this comment.
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.
…pace on Python 3.15
…the deprecated console helpers
There was a problem hiding this comment.
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
…ookie mode never flashes the source text
There was a problem hiding this comment.
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
…, and cover hiding the page for a non-default locale
… page's <html>, and document the hold's timeout and prerender limits
There was a problem hiding this comment.
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)) || |
There was a problem hiding this comment.
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>
closes #2339