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

feat(web): add support for language packs #146012

Closed
wants to merge 20 commits into from

Conversation

jsjoeio
Copy link
Contributor

@jsjoeio jsjoeio commented Mar 24, 2022

Description

This PR adds support for using language packs with VS Code Web via the CLI flag --locale.

Known Limitations

There are a couple limitations with this implementation. Hoping that the Code Team can provide guidance on whether these limitations need to be addressed before merging and if so, how they recommend addressing them.

Implementation only works on a full build

I am not sure why exactly, but this patch only works when you do a full build of VS Code and run that (meaning you can't use this in dev mode).

Requires commit in product.json

I had to manually add commit to product.json in the build output because of this logic.

Only works with --locale CLI flag

Switching the display language only works using the --locale CLI flag. I believe this is because the argv.json is only modified in the client and saved in the IndexedDB.

image

If we patched this to use the file system instead of userRoamingDataHome, it could potentially work normally (without passing a CLI flag).

Still shows "Install in Browser" which leads to error

Even if it's installed on the remote/server, you still see the "Install in Browser" button. When you click on it, you get an error toast notification. Error comes from this block. Do language packs not have manifests?

image

image

Demo

Screen.Recording.2022-03-30.at.9.29.12.AM.mov

How to Test

  1. git clone https://github.com/microsoft/vscode.git
  2. gh pr checkout 146012
  3. yarn
  4. yarn gulp "vscode-reh-web-darwin-x64-min" (replace darwin-x64 with your platform)
  5. cd .. && ./vscode-reh-web-darwin-x64/bin/code-server-oss
  6. Open VS Code in browser
  7. Download an extension pack (i.e. Spanish)
  8. Install from VSIX file
  9. Kill VS Code and run again: ./vscode-reh-web-darwin-x64/bin/code-server-oss --locale es
  10. See display in Spanish

Fixes #82595
Fixes coder/code-server#4703

Contributors

@@ -44,3 +50,39 @@ export namespace InternalNLSConfiguration {
return candidate && typeof candidate._languagePackId === 'string';
}
}

export const getLocaleFromConfig = async (argvResource: string): Promise<string> => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

May be able to use this function:

function getUserDefinedLocale(argvConfig) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually...not 1:1 and can't import from JS file I don't think (well I don't see any other files using this since it's not exported) so going to leave as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar function/logic as well:

vscode/src/main.js

Lines 233 to 256 in f3a9245

function readArgvConfigSync() {
// Read or create the argv.json config file sync before app('ready')
const argvConfigPath = getArgvConfigPath();
let argvConfig;
try {
argvConfig = JSON.parse(stripComments(fs.readFileSync(argvConfigPath).toString()));
} catch (error) {
if (error && error.code === 'ENOENT') {
createDefaultArgvConfigSync(argvConfigPath);
} else {
console.warn(`Unable to read argv.json configuration file in ${argvConfigPath}, falling back to defaults (${error})`);
}
}
// Fallback to default
if (!argvConfig) {
argvConfig = {
'disable-color-correct-rendering': true // Force pre-Chrome-60 color profile handling (for https://github.com/microsoft/vscode/issues/51791)
};
}
return argvConfig;
}

src/vs/server/node/remoteLanguagePacks.ts Outdated Show resolved Hide resolved
@jsjoeio
Copy link
Contributor Author

jsjoeio commented Mar 28, 2022

I'm running into issues building locally. Any ideas? Does windows-process-tree only get installed on Windows? I'm developing on macOS.

[15:28:58] Error: /Users/jp/dev/oss/vscode/src/vs/workbench/contrib/debug/node/terminals.ts(9,10): '"windows-process-tree"' has no exported member named 'IProcessTreeNode'. Did you mean 'ProcessTreeNode'?
[15:28:58] Error: /Users/jp/dev/oss/vscode/src/vs/platform/terminal/node/windowsShellHelper.ts(135,89): '"/Users/jp/dev/oss/vscode/node_modules/@types/windows-process-tree/index"' has no exported member named 'IProcessTreeNode'. Did you mean 'ProcessTreeNode'?
[15:28:58] Finished compilation with 2 errors after 165738 ms
[15:28:58] Error: /Users/jp/dev/oss/vscode/src/vs/workbench/contrib/debug/node/terminals.ts(9,10): '"windows-process-tree"' has no exported member named 'IProcessTreeNode'. Did you mean 'ProcessTreeNode'?
[15:28:58] Error: /Users/jp/dev/oss/vscode/src/vs/platform/terminal/node/windowsShellHelper.ts(135,89): '"/Users/jp/dev/oss/vscode/node_modules/@types/windows-process-tree/index"' has no exported member named 'IProcessTreeNode'. Did you mean 'ProcessTreeNode'?
[15:28:58] Finished compilation with 2 errors after 165740 ms
[15:28:58] 'vscode-reh-web-darwin-x64-min' errored after 2.85 min
[15:28:58] Error: Found 2 errors
    at Stream.<anonymous> (/Users/jp/dev/oss/vscode/build/lib/reporter.js:91:29)
    at _end (/Users/jp/dev/oss/vscode/node_modules/through/index.js:65:9)
    at Stream.stream.end (/Users/jp/dev/oss/vscode/node_modules/through/index.js:74:5)
    at Stream.onend (internal/streams/legacy.js:47:10)
    at Stream.emit (events.js:412:35)
    at Stream.emit (domain.js:532:15)
    at drain (/Users/jp/dev/oss/vscode/node_modules/through/index.js:34:23)
    at Stream.stream.queue.stream.push (/Users/jp/dev/oss/vscode/node_modules/through/index.js:45:5)
    at Stream.end (/Users/jp/dev/oss/vscode/node_modules/through/index.js:15:35)
    at _end (/Users/jp/dev/oss/vscode/node_modules/through/index.js:65:9)
error Command failed with exit code 1.

@jsjoeio jsjoeio marked this pull request as ready for review March 28, 2022 22:36
@TylerLeonhardt
Copy link
Member

Looks like the build is in a bad state. Unrelated to your change. Should be fixed tomorrow.

@TylerLeonhardt
Copy link
Member

@jsjoeio just an FYI I updated your brand from main to help with the CI and local failures.

@TylerLeonhardt
Copy link
Member

Implementation only works on a full build
Requires commit in product.json

Yes I believe all of this is expected and is the same as Desktop. The commit is used in the path of one of the localization files and also when running out of sources we don’t bundle files (for easier debugging) but bundling is important for the localization feature. @dbaeumer please let me know if I have this wrong.

@TylerLeonhardt
Copy link
Member

Only works with --locale CLI flag

yeah I’d like to get to the bottom of this before we merge this PR in. I should have some cycles to look into it this week.

@jsjoeio
Copy link
Contributor Author

jsjoeio commented Mar 29, 2022

I should have some cycles to look into it this week.

Awesome! Thank you so much for the quick replies and offering to help us get to the bottom of this! Really appreciate it. Let me know how else I can be helpful.

@jsjoeio
Copy link
Contributor Author

jsjoeio commented Mar 30, 2022

Okay a couple updates:

  • added demo video
  • updated testing instructions

I'm not sure how to fix this Hygine error:

$ node build/lib/layersChecker.js
[build/lib/layersChecker.ts]: Reference to 'document' from 'lib.dom.d.ts' violates layer '**/vs/base/common/platform.ts' (/home/runner/work/vscode/vscode/src/vs/base/common/platform.ts ([8](https://github.com/microsoft/vscode/runs/5756751534?check_suite_focus=true#step:11:8)7,20)
[build/lib/layersChecker.ts]: Reference to 'document' from 'lib.dom.d.ts' violates layer '**/vs/base/common/platform.ts' (/home/runner/work/vscode/vscode/src/vs/base/common/platform.ts (87,48)
[build/lib/layersChecker.ts]: Reference to 'getElementById' from 'lib.dom.d.ts' violates layer '**/vs/base/common/platform.ts' (/home/runner/work/vscode/vscode/src/vs/base/common/platform.ts (87,57)
[build/lib/layersChecker.ts]: Reference to 'getAttribute' from 'lib.dom.d.ts' violates layer '**/vs/base/common/platform.ts' (/home/runner/work/vscode/vscode/src/vs/base/common/platform.ts (88,32)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I see navigator used in the same block where I'm using document.

Maybe there's a way to refactor this code to do it the "proper way":

	const el = typeof document !== 'undefined' && document.getElementById('vscode-remote-nls-configuration');
	const rawNlsConfig = el && el.getAttribute('data-settings');

@jsjoeio
Copy link
Contributor Author

jsjoeio commented Apr 12, 2022

Friendly bump @TylerLeonhardt - do you think you'll have a chance to look at this this month?

@TylerLeonhardt
Copy link
Member

👋 @jsjoeio so sorry for the delay. Lots of stuff happened (including personally) and I wasn't able to get around to this. I really appreciate all the work you've done to achieve language pack support.

Based on your findings, I'm currently working on solving the known limitations by allowing the client to dictate what the language is so that we can avoid some of things you've pointed out.

I can speak more about that once I actually have something to show off 😅 but essentially the idea is to have navigator.language dictate the locale to use.

@jsjoeio
Copy link
Contributor Author

jsjoeio commented May 19, 2022

@TylerLeonhardt no worries at all - hope everything is okay personally! Thanks so much for the update.

I can speak more about that once I actually have something to show off 😅 but essentially the idea is to have navigator.language dictate the locale to use.

That sounds amazing! I'll keep an eye out then for an update from you 😄

@jsjoeio
Copy link
Contributor Author

jsjoeio commented Jun 9, 2022

@TylerLeonhardt now that 1.68 has core localization support, is this still needed?

@TylerLeonhardt
Copy link
Member

I think we can close this now since we went in a different direction. This wasn't thrown away though, we all learned from the work you did for sure so thank you for taking the time to contribute. It means a lot to the community!

@jsjoeio jsjoeio deleted the 82595-language-patch branch June 10, 2022 15:45
@github-actions github-actions bot locked and limited conversation to collaborators Jul 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract display language patch and submit PR upstream Web: Support for translations/language packs
2 participants