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

Raise errors on long i18n message ids #1438

Merged
merged 5 commits into from
May 15, 2020
Merged

Raise errors on long i18n message ids #1438

merged 5 commits into from
May 15, 2020

Conversation

toolness
Copy link
Collaborator

@toolness toolness commented May 14, 2020

From a Slack conversation:

So right now after merging our two i18n PRs it looks like the norent i18n bundle for English at https://tenants2-staticfiles-atul-dev.s3.amazonaws.com/frontend/locales-en-norent-chunk.bb81f08785cb61c11a68.bundle.js is about 9k gzipped, which is a bit of a bummer since, being the english catalog, it's literally all just an object full of strings like "Your password": "Your password". And then our source bundle has a bunch of references to those strings (since they need to be looked up in the 18n bundle), so when the ID strings consist of entire paragraphs of text, it's like we've got 3 separate instances of them in our source code, which probably bloats it when it's all added up.

This adds functionality to our localebuilder tool which logs warnings (which we could convert to errors in a future PR) raises errors whenever lingui message catalog IDs are longer than 100 175 characters, indicating that significant space might be saved if we shorten them. We can always change the limit if we want, too.

Here's a screenshot of its output:

image

Since localebuilder is run in production and the output is colorized, this PR also moves chalk from our devDependencies to dependencies (it's already ultimately in there anyways due to various third-party packages in dependencies already needing it).

@toolness toolness mentioned this pull request May 15, 2020
33 tasks
@sraby
Copy link
Member

sraby commented May 15, 2020

Ok @toolness, I just added ID tags to fix all of our msgid-length warnings! I decided to set the threshold to 175 characters, as this seemed to be a good break point in the list of messages that we got.

Comment on lines +20 to +22
t(
"norent.tweetTemplateForSharingNoRent"
)`No idea how you'll pay rent this month? Tell your landlord with norent.org from @JustFixNYC. This free tool sends a certified letter informing them of your protections. Join the #cancelrent movement at norent.org.`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh super dope, I didn't realize there was a way to manually specify an ID for these non-JSX thingys!

@toolness
Copy link
Collaborator Author

Awesome thanks! I'll fix up the letter builder ones and then activate HARDFAIL and merge!

@toolness
Copy link
Collaborator Author

oh wow, thanks, I didn't actually realize you addressed all the warnings, not just the ones in primary pages!

@toolness toolness merged commit 07b15d8 into master May 15, 2020
@toolness toolness deleted the warn-on-long-msg-ids branch May 15, 2020 20:21
@toolness toolness changed the title Log warnings on long i18n message ids Raise errors on long i18n message ids May 15, 2020
toolness added a commit that referenced this pull request May 19, 2020
So #1438 helped us reduce the size of our browser code footprint, but Crowdin didn't like it much, because it presented the message ID as the string to be translated, rather than the English version of the actual string.

Fortunately, after talking to Crowdin support, it looks like this is remedied with a simple header on the PO file, which this PR adds.
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.

2 participants