Skip to content

Locale check script#1336

Merged
LlGC-mij merged 8 commits intoUniversalViewer:devfrom
404mike:locale-check
Mar 14, 2025
Merged

Locale check script#1336
LlGC-mij merged 8 commits intoUniversalViewer:devfrom
404mike:locale-check

Conversation

@404mike
Copy link
Copy Markdown
Contributor

@404mike 404mike commented Mar 11, 2025

A script to validate locales within the UV.

Using English as the primary language the script can be run on two tasks.

Checking for unused locales

Check if the locale is used anywhere within the UV modules?

node scripts/validate_locale.ts checkLocaleUsage

Will produce:

Final locale keys count: {
  '$collapse': 13,
  ....
  '$pause': 1,
  '$play': 1,
  '$brightness': 8,
  '$contrast': 8,
  '$saturation': 8,
  '$reset': 8,
  '$remember': 8
}
Unused locale keys: [
  [ '$entireFileX', 0 ],
  [ '$wholeImageHighResExplanation', 0 ],
  [ '$wholeImageLowResAsJpgExplanation', 0 ],
  [ '$log_in', 0 ],
  [ '$pleaseLogInToViewAtFullQuality', 0 ]
]

This works by loading the English locale file and checking each of the module configs for any usage, incrementing the usage through each iteration.

The script doesn't check any .tsx files.

Check for missing locales

Does the English locale contain strings that are missing from the other locales?

node scripts/validate_locale.ts compareLocales  

Will produce:

Key "$reset" missing in locale "cy-GB"
Key "$remember" missing in locale "cy-GB"
Key "$brightness" missing in locale "fr-FR"
Key "$contrast" missing in locale "fr-FR"
Key "$saturation" missing in locale "fr-FR"
Key "$reset" missing in locale "fr-FR"
Key "$remember" missing in locale "fr-FR"
Key "$brightness" missing in locale "pl-PL"
Key "$contrast" missing in locale "pl-PL"
Key "$saturation" missing in locale "pl-PL"
Key "$reset" missing in locale "pl-PL"
Key "$remember" missing in locale "pl-PL"

All outputs above were ran against main branch.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
universalviewer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2025 4:11pm

Copy link
Copy Markdown
Contributor

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

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

I haven't had a chance for a full review yet, but see below for one idea that might help make this more future-proof.

Copy link
Copy Markdown
Contributor

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

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

Thanks, @404mike -- I took a closer look at the rest of this. See below for a couple more thoughts.

Also, should we wire this up in the "scripts" section of package.json, so it can be executed with npm run? That might help make it more visible as an option for people new to the project.

@LlGC-mij
Copy link
Copy Markdown
Contributor

@demiankatz thank you for the feedback.

I've updated the script to cover all the feedback so far. I've also renamed a few things to hopefully make things a bit more clear as to what they do?

The latest change includes the ability to run the different tests from npm:

  checkLocaleUsage
    node scripts/validate_locale.ts checkLocaleUsage
  missingTranslations
    node scripts/validate_locale.ts missingTranslations
  hardCodedStrings
    node scripts/validate_locale.ts hardCodedStrings

Copy link
Copy Markdown
Contributor

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

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

Thanks, @LlGC-mij for the progress here. See below for a few finishing touches (and feel free to modify or ignore my naming suggestions if you don't like them).

Copy link
Copy Markdown
Contributor

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

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

This looks good to me now! Thanks, @404mike and @LlGC-mij!

Please feel free to merge if you're both happy with the state of things.

Should someone do a follow-up PR to address the hard-coded strings detected by the tool?

@LlGC-mij LlGC-mij merged commit 5f7b8f8 into UniversalViewer:dev Mar 14, 2025
5 checks passed
@LlGC-mij
Copy link
Copy Markdown
Contributor

Thank you @demiankatz. Both @404mike and I are the same person 😆 (I forgot to update my keys!).

I'm happy to look at fixing any issues found by the tool. I'll take a look next week.

@demiankatz
Copy link
Copy Markdown
Contributor

Ha, thanks, @LlGC-mij. You and yourself make an excellent team. ;-)

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.

3 participants