Skip to content

Conversation

sadasant
Copy link
Contributor

@sadasant sadasant commented Jun 8, 2022

This PR adds vscode-nls as a dependency, following the guidelines to make use of this tool to bring the standard VS Code localization to the vscode-jupyter extension.

For more information:

IMPORTANT CONSIDERATIONS:
Given that vscode-nls does not yet support the web environment, I haven't removed the existing localization approach, I have slightly changed it to support vscode-nls's API. The localize function will be using vscode-nls on Node.js, but on the web the custom approach we have been using so far is kept functionally intact.

Once vscode-nls supports the web, I will be able to remove the non-standard localization tool we currently have. I have made an issue to follow up: #10367

If this PR is merged:
Fixes #9676

@sadasant sadasant self-assigned this Jun 8, 2022
@sadasant sadasant requested a review from a team as a code owner June 8, 2022 03:46
@@ -77,25 +80,28 @@ export namespace GitHubIssue {
'Please provide a descriptive title summarizing your issue.'
);
export const titlePlaceholder = localize(
'GitHubIssue.titlePlaceholder',
{ key: 'GitHubIssue.titlePlaceholder', comment: ['{Locked="kernel"}'] },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am assuming we want to keep kernel as is and not change it from language to language.

'E.g.: Unable to start a local kernel session'
);
export const pleaseFillThisOut = localize(
'GitHubIssue.pleaseFillThisOut',
'Please fill this section out and delete this comment before submitting an issue!'
);
export const missingFields = localize(
'GitHubIssue.missingFields',
{ key: 'GitHubIssue.missingFields', comment: ['{Locked="Issue"}'] },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am assuming we want to keep the uppercase Issue as is and not change it from language to language.

}

export namespace Logging {
export const currentWorkingDirectory = localize('Logging.CurrentWorkingDirectory', 'cwd:');
export const currentWorkingDirectory = () => 'cwd:';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am assuming cwd: never changes.

'DataScienceRendererExtension.installingExtension',
{
key: 'DataScienceRendererExtension.installingExtension',
comment: ['{Locked="Notebook Renderers"}']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am assuming we want to keep Notebook Renderers as is and not change it from language to language.

@@ -162,7 +183,7 @@ export namespace ExtensionSurveyBanner {
export namespace DataScience {
export const installingModule = localize('products.installingModule', 'Installing {0}');
export const warnWhenSelectingKernelWithUnSupportedPythonVersion = localize(
'DataScience.warnWhenSelectingKernelWithUnSupportedPythonVersion',
{ key: 'DataScience.warnWhenSelectingKernelWithUnSupportedPythonVersion', comment: ['{Locked="kernel"}'] },
'The version of Python associated with the selected kernel is no longer supported. Please consider selecting a different kernel.'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am assuming we want to keep kernel as is and not change it from language to language.

'DataScience.checkingIfImportIsSupported',
'Checking if import is supported'
{ key: 'DataScience.checkingIfImportIsSupported', comment: ['{Locked="import"}'] },
'Checking if "import" is supported'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am assuming we want to keep import as is and not change it from language to language.

'Validating kernel dependencies'
);
export const performingExport = localize('DataScience.performingExport', 'Performing Export');
export const convertingToPDF = localize('DataScience.convertingToPDF', 'Converting to PDF');
export const exportNotebookToPython = localize(
'DataScience.exportNotebookToPython',
{ key: 'DataScience.exportNotebookToPython', comment: ['{Locked="Notebook"}'] },
Copy link
Contributor Author

@sadasant sadasant Jun 8, 2022

Choose a reason for hiding this comment

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

I am assuming we want to keep uppercase Notebook as is and not change it from language to language.

However, I am also assuming that sometimes it's ok to translate notebook, since it might help with context.

Let me know if I should keep all of the notebook instances as Locked.

'Raw kernel process exited before connecting.'
);
export const unknownMimeTypeFormat = localize(
'DataScience.unknownMimeTypeFormat',
{ key: 'DataScience.unknownMimeTypeFormat', comment: ['{Locked="Mime type"}'] },
'Mime type {0} is not currently supported'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would not assume Mime type needs to be translated.

@@ -362,39 +398,48 @@ export namespace DataScience {
export const jupyterSelfCertClose = localize('DataScience.jupyterSelfCertClose', 'No, close the connection');
export const pythonInteractiveHelpLink = localize(
'DataScience.pythonInteractiveHelpLink',
'See [https://aka.ms/pyaiinstall] for help on installing jupyter.'
'See <https://aka.ms/pyaiinstall> for help on installing jupyter.'
Copy link
Contributor Author

@sadasant sadasant Jun 8, 2022

Choose a reason for hiding this comment

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

The older one seemed to be prone to bugs, in my opinion.

);
export const markdownHelpInstallingMissingDependencies = localize(
'DataScience.markdownHelpInstallingMissingDependencies',
'See [https://aka.ms/pyaiinstall](https://aka.ms/pyaiinstall) for help on installing Jupyter and related dependencies.'
'See <https://aka.ms/pyaiinstall> for help on installing Jupyter and related dependencies.'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems equivalent for me.

@@ -319,7 +355,7 @@ export namespace DataScience {
);
export const jupyterInstall = localize('DataScience.jupyterInstall', 'Install');
export const currentlySelectedJupyterInterpreterForPlaceholder = localize(
'Datascience.currentlySelectedJupyterInterpreterForPlaceholder',
'DataScience.currentlySelectedJupyterInterpreterForPlaceholder',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took the liberty to do some small improvements. Feedback appreciated!

export const svgFilter = localize('DataScience.svgFilter', 'SVG');
export const pdfFilter = () => 'PDF';
export const pngFilter = () => 'PNG';
export const svgFilter = () => 'SVG';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think these should be localized. Am I wrong?

if (typeof key !== 'string') {
key = key.key;
}
return getString(key as string, defaultValue);
Copy link
Contributor Author

@sadasant sadasant Jun 8, 2022

Choose a reason for hiding this comment

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

This does add a small performance impact, however it should be just constant, since the vscode-nls localize function is constant, as far as I understand.

{ key: 'DataScience.importDialogTitle', comment: ['{Locked="Notebook"}'] },
'Import Jupyter Notebook'
);
export const importDialogFilter = () => 'Jupyter Notebooks';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm assuming this would never change.

Copy link
Contributor

Choose a reason for hiding this comment

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

If Jupyter cannot change here, then it should be locked everywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think Jupyter needs to be locked since it's an alteration, not a real word. It's also a subject name. I would assume it will be obvious that it shouldn't be translated.

@codecov-commenter
Copy link

codecov-commenter commented Jun 8, 2022

Codecov Report

Merging #10361 (e05f2f5) into main (00c6329) will decrease coverage by 0%.
The diff coverage is 33%.

@@           Coverage Diff           @@
##            main   #10361    +/-   ##
=======================================
- Coverage     69%      69%    -1%     
=======================================
  Files        479      479            
  Lines      29453    29727   +274     
  Branches    5037     5040     +3     
=======================================
+ Hits       20544    20652   +108     
- Misses      7008     7175   +167     
+ Partials    1901     1900     -1     
Impacted Files Coverage Δ
...s-message-coordination/commonMessageCoordinator.ts 68% <0%> (+7%) ⬆️
src/kernels/jupyter/launcher/notebookProvider.ts 75% <0%> (ø)
.../raw/finder/localKnownPathKernelSpecFinder.node.ts 89% <ø> (ø)
src/platform/common/utils/localize.ts 76% <ø> (-22%) ⬇️
src/platform/errors/errorUtils.ts 75% <ø> (ø)
src/platform/messageTypes.ts 100% <ø> (ø)
...ide/dataviewer/dataViewerDependencyService.node.ts 86% <100%> (ø)
src/kernels/common/delayedFutureExecute.ts 53% <0%> (-8%) ⬇️
src/notebooks/outputs/tracebackFormatter.ts 93% <0%> (-7%) ⬇️
... and 6 more

package.nls.json Outdated
@@ -62,11 +62,11 @@
"jupyter.command.jupyter.runLinting.title": "Run Linting",
"jupyter.command.jupyter.runFileInteractive.title": "Run Current File in Interactive Window",
"jupyter.command.jupyter.debugFileInteractive.title": "Debug Current File in Interactive Window",
"jupyter.command.jupyter.runallcells.title": "Run All Cells",
"jupyter.command.jupyter.runAllCells.title": "Run All Cells",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is camel case required? Wondering why these changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll unchanged them, it just seemed like a good improvement to me. But it's not necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

I found plenty of others that you hadn't changed e.g. the line below the above one wasn't updated. If chaning I'd change it everywhere, or leave as is - or change in a seprate PR with a linter to ensure we are consistent (which I know we aren't)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make an issue to make these consistent!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue: #10381

@@ -111,3 +112,4 @@ typings/**
types/**
test-results*
*.zip
!**/*nls.*.json
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the challenges I had was that the *nls.*.json files were missing in the final .VSIX. This change, and another change in the gulpfile.js were the solution.

@@ -1251,7 +1251,7 @@ No properties for event
[src/notebooks/controllers/notebookControllerManager.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/notebooks/controllers/notebookControllerManager.ts)
```typescript
}
// We know that this fails when we have xeus kernels installed (untill that's resolved thats one instance when we can have duplicates).
// We know that this fails when we have xeus kernels installed (until that's resolved thats one instance when we can have duplicates).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took the liberty to fix some typos.

@@ -22,6 +22,8 @@ resources:
extends:
template: azure-pipelines/extension/pre-release.yml@templates
parameters:
locTsConfigs: $(Build.SourcesDirectory)/tsconfig.json
locBundleDestination: $(Build.SourcesDirectory)/out
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a reminder for future reviews of this PR, this should match the output path: in the webpack config: https://github.com/microsoft/vscode-jupyter/blob/main/build/webpack/webpack.extension.node.config.js#L142

@@ -18,6 +18,8 @@ extends:
template: azure-pipelines/extension/stable.yml@templates
parameters:
publishExtension: true
locTsConfigs: $(Build.SourcesDirectory)/tsconfig.json
locBundleDestination: $(Build.SourcesDirectory)/out
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a reminder for future reviews of this PR, this should match the output path: in the webpack config: https://github.com/microsoft/vscode-jupyter/blob/main/build/webpack/webpack.extension.node.config.js#L142

options: {
base: constants.ExtensionRootDir
}
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll need to add this in the web webpack once there's web support.

@@ -143,7 +143,7 @@ gulp.task('output:clean', () => del(['coverage']));

gulp.task('clean:cleanExceptTests', () => del(['clean:vsix', 'out', '!out/test']));
gulp.task('clean:vsix', () => del(['*.vsix']));
gulp.task('clean:out', () => del(['out/**', '!out', '!out/client_renderer/**']));
gulp.task('clean:out', () => del(['out/**', '!out', '!out/client_renderer/**', '!**/*nls.*.json']));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the challenges I had was that the *nls.*.json files were missing in the final .VSIX. This change, and another change in the .vscodeignore were the solution.

'Common.clickHereForMoreInfoWithHtml',
"Click <a href='{0}'>here</a> for more info."
);
export const bannerLabelYes = () => localize('Common.bannerLabelYes', 'Yes');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed these to be functions to allow keeping the old behavior in the browser. At first, I had this change within a replacement of the localize function itself, but that broke the matching mechanism used by vscode-nls-dev. I've got to allow the Node logic to assume localize is unchanged, and thus to keep the signature in the other files, these properties now are lambdas.

I will fix this once vscode-nls supports the web.

@@ -1262,6 +1436,8 @@ function getString(key: string, defValue?: string) {
collection = loadedCollection;
}
let result = collection[key];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
result = (result as any)?.message || result;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since package.nls.json now can return objects, we should retrieve the message from those objects in such cases.

@sadasant
Copy link
Contributor Author

@rchiodo , @DonJayamanne This PR is ready 😆 fully tested. One last review appreciated 🙏

@sadasant
Copy link
Contributor Author

I'm getting some weird errors in the build, like:

  • FAILED TEST NAME: DataScience - VSCode Notebook - (Conda Execution) (slow) Acitvate conda environment using conda run and activation commands.
  • FAILED TEST NAME: DataScience - VSCode Notebook - Restart/Interrupt/Cancel/Errors (slow) Interrupt and running cells again should only run the necessary cells.

Investigating...

@@ -110,7 +110,7 @@ suite('DataScience - VSCode Notebook - (Conda Execution) (slow)', function () {
);
verifyVariables(envVarsOurselves!, '(ourselves)');
});
test('Acitvate conda environment using conda run and activation commands', async () => {
test('Activate conda environment using conda run and activation commands', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could this typo fix be affecting a recording or a CI setting of some sort?

Copy link
Member

@IanMatthewHuff IanMatthewHuff Jun 13, 2022

Choose a reason for hiding this comment

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

I wouldn't think so. Have you checked some recent runs from main / other PRs to see if that test is failing in them?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah this is a common failure. I'm trying to fix this here:
#10429

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oooh

@sadasant sadasant merged commit 039cf29 into microsoft:main Jun 13, 2022
@sadasant sadasant deleted the debt/9676 branch June 13, 2022 16:27
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.

Localize using vscode-loc
6 participants