Skip to content

Script to Identify Unused Translation Entries #3609

@raclim

Description

@raclim

Adding in a Great Addition by @cassiano to help with Translation Work! Pasting in the comments originally made below. For more context around them, feel free to refer to the original pull request!


During the process of reviewing pt-BR translations I have developed a generic TS script (which should be run under Deno, not Node) which greatly facilitated my work. I will include it here:

p5js_editor_i18n_tools.ts

It is used to automatically analyze the codebase and remove unused entries. It also adds missing entries to any locale.

The idea is to run the script initially for the en-US locale, which I assume is the only locale containing all necessary entries. The script will remove any unused entries, by trying to locate them directly in the source code. It actually found 61 unused entries in the en-US file (unless proven contrary):

[
  "About.Learn",
  "AddToCollectionList.AnothersTitle",
  "AddToCollectionSketchList.AnothersTitle",
  "CodemirrorFindAndReplace.Find",
  "Collection.Description",
  "Collection.NumSketches_plural",
  "CollectionList.HeaderCreatedAt_mobile",
  "CollectionList.HeaderNumItems_mobile",
  "CollectionList.HeaderUpdatedAt_mobile",
  "CollectionView.TitleCreate",
  "CollectionView.TitleDefault",
  "Console.Close",
  "Console.Open",
  "CopyableInput.OpenViewTabARIA",
  "Explorer.Files",
  "Feedback.GoToForm",
  "Feedback.GoToGithub",
  "Feedback.ViaGithubDescription",
  "Feedback.ViaGithubHeader",
  "Feedback.ViaGoogleDescription",
  "Feedback.ViaGoogleHeader",
  "KeyboardShortcuts.CodeEditing.FindNextMatch",
  "KeyboardShortcuts.CodeEditing.FindPrevMatch",
  "LoginView.Email",
  "LoginView.Username",
  "MobileDashboardView.Assets",
  "MobileDashboardView.Collections",
  "MobileDashboardView.CreateCollection",
  "MobileDashboardView.CreateSketch",
  "MobileDashboardView.Examples",
  "MobileDashboardView.MyStuff",
  "MobileDashboardView.Sketches",
  "MobilePreferences.Accessibility",
  "MobilePreferences.AccessibleOutput",
  "MobilePreferences.AutocompleteHinter",
  "MobilePreferences.Autosave",
  "MobilePreferences.DarkTheme",
  "MobilePreferences.GeneralSettings",
  "MobilePreferences.HighContrastTheme",
  "MobilePreferences.LightTheme",
  "MobilePreferences.LineNumbers",
  "MobilePreferences.LintWarningSound",
  "MobilePreferences.PlainText",
  "MobilePreferences.Settings",
  "MobilePreferences.Sound",
  "MobilePreferences.TableText",
  "MobilePreferences.Theme",
  "MobilePreferences.UsedScreenReader",
  "MobilePreferences.WordWrap",
  "Nav.Auth.Asset",
  "Nav.Auth.My",
  "Nav.Auth.Welcome",
  "Nav.Lang",
  "NewPasswordView.EmptyPassword",
  "NewPasswordView.PasswordConfirmation",
  "NewPasswordView.PasswordMismatch",
  "Preferences.AddonOffARIA",
  "Preferences.AddonOnARIA",
  "SketchList.HeaderCreatedAt_mobile",
  "SketchList.HeaderUpdatedAt_mobile",
  "SketchList.View"
]

There is only one exception, the SkipLink.PlaySketch entry, which for technical reasons cannot be automatically checked, so it must be placed explicitly as a 3rd parameter (the second parameter below, -, refers to the default en-US locale):

deno --allow-read --allow-write ../p5js_editor_i18n_tools.ts . - SkipLink.PlaySketch

Follows the list of parameters for the script:

  1. p5.js project path.
  2. target locale folder (optional, defaults to 'en-US'). If 3rd parameter is present, supply '-' to use the default value.
  3. comma-separated list of unused key exceptions (optional). Please specify at least SkipLink.PlaySketch.

A new file will be generated in the translations/locales/en-US folder, called translations.reviewed.json. The original file should then be replaced by it, after being renamed to translations.json.

I strongly recommend that you double-check that those entries are in fact unused in the codebase before effectively deleting them.

You can run it now for the remaining locales. For example:

  • deno --allow-read --allow-write ../p5js_editor_i18n_tools.ts . pt-BR SkipLink.PlaySketch
  • deno --allow-read --allow-write ../p5js_editor_i18n_tools.ts . it SkipLink.PlaySketch
  • etc

All entries which require manual translation will be properly generated with a [NEEDS TRANSLATION <full-key>] marker, accompanied by the default english translation. For example:

  "LoginForm": {
    ...
    "Errors": {
      "invalidCredentials": "[NEEDS TRANSLATION - LoginForm.Errors.invalidCredentials] Invalid email or password."
    }
  }

Remaining locales usually miss between 50 and 70 entries, which will require manual translations.

That is it. I hope you find the script useful. Cheers!

Originally posted by @cassiano in #3593 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: DocumentationFor developer documentation related to the p5.js editorArea: TranslationFor localization of the p5.js editor or contributor documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions