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

[Paused] Add localization support #88

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Conversation

marcomura
Copy link
Contributor

@marcomura marcomura commented Jan 31, 2025

Commands and settings in the package.json are localized through files called package.nls.<locale>.json at the root of the project. They are picked up automatically by vscode. The default file package.nls.json is loaded when the file for the current locale is missing.

The package.json file references to string keys like %command.action%, which are replaced with the localized string contained in the package json file corresponding to the current locale, or the default one if missing.

The localized commands and settings need to be maintained manually, adding a string key and the actual string in the .json file when adding new commands/settings, and removing them when necessary.

Source code (ts/tsx) strings are localized through the vscode-l10n package, which works via the vscode.l10n.t() function.
Localized strings are placed under the l10n directory at the root of the project (configured in package.json), and the files inside are called bundle.l10n.<locale>.json. The default file bundle.l10n.json is just a placeholder and never actually used.

The vscode.l10n.t() function requires the default string itself, and not a key representing the string like for commands and settings. When the bundle file for the current locale isn't found, the string passed to t() will be used as the actual displayed string.
E.g.,
vscode.l10n.t("hello") -> ...it-it locale, bundle found -> "ciao"
vscode.l10n.t("hello") -> ...fr-fr locale, bundle not found -> "hello"

The localized strings are maintained running the command npm run npx, which updates the placeholder bundle.l10n.json in the l10n folder with all the strings that are passed to a vscode.l10n.t() function.
After adding/removing/modifying localized strings, just run that command to update the bundle file.

The actual translation is a process that needs to be set up and ran externally.

Trick to make the webview working:
The webview environment doesn't have the localization bundle loaded, I guess because they are running separately by the extension host.

As a solution, I've embedded in the html files (reactView.html and reactWebview.html) the localization bundle, injected by their controllers (getHtmlForView.ts and abtractWebview.ts) and successively loaded by the root webview JiraExplorerPanel.tsx.

There are some strings that don't look correctly localized, which means that either that is not the root webview, or there are multiple independent webviews that should hold that logic. In either case, this needs a fix.

@bwieger-atlassian-com bwieger-atlassian-com changed the title Add localization support [Paused] Add localization support Feb 5, 2025
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.

1 participant