Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement frontend localization #705

Merged
merged 5 commits into from
Sep 17, 2024
Merged

Conversation

rgalanakis
Copy link
Member

@rgalanakis rgalanakis commented Sep 11, 2024

Use a backend preprocessor to process localization files into a version that 1) indicates what formatter to use (plain, markdown without paragraphs, markdown with paragraphs) and a simpler interpolation (a single '@%' placeholder and an argument for each substitution). Each substitution argument indicates if it is just an option lookup, has a formatter, or points to another localization string.

The frontend code has been adjusted to load, lookup, and apply these preprocessed transformations. We didn't need to change most callsites; but we do get rid of the md/mdp formatters since the formatter is in the preprocessed file, which was the point of this work in the first place. So it's just the 'localization backend functions' that changed.

The new 'localization backend' is based on i18next (which is now gone), but is not meant to recreate the entire thing, just the parts we use and find valuable.

Fixes #308 (saves 110kb) and fixes #694.

This is just the backend change.
Copy link

codecov bot commented Sep 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.97%. Comparing base (573796f) to head (d95630f).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #705      +/-   ##
==========================================
+ Coverage   97.95%   97.97%   +0.02%     
==========================================
  Files         448      449       +1     
  Lines       20493    20664     +171     
==========================================
+ Hits        20074    20246     +172     
+ Misses        419      418       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rgalanakis rgalanakis marked this pull request as ready for review September 12, 2024 01:06
Use the new preprocessed files for rendering.
They include if we need markdown or plain renderer,
and the code is 4kb vs. 120kb.
We need to handle nested localizations, where:
- `"abc": "**hi**"`, uses the `m` formatter, and
- `"s1": "$t(abc)"`, depends on `abc`,
  but doesn't know it will need markdown.

So we do a first pass to find all the 'naive' formatters,
and then another pass where we look at all the formatters
for all the (recursive) nestings, so we'd know that `s1` gets `m`
in our example.

This required a pretty big refactor, with internal classes
to keep track of the nestings, and now we have more friendly
formatter classes. But fundamentally everything works
the same as the previous commit (and the output format
didn't change at all).
@rgalanakis rgalanakis force-pushed the reformat-loc-rez-strings branch from a118cf7 to d95630f Compare September 12, 2024 15:25
@rgalanakis rgalanakis merged commit 7a7c708 into main Sep 17, 2024
5 checks passed
@rgalanakis rgalanakis deleted the reformat-loc-rez-strings branch September 17, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preprocess localization strings to determine whether to use md or t Reduce bundle size: replace i18next
1 participant