Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Oracle Java Platform Extension for Visual Studio Code
Copyright (c) 2023-2025, Oracle and/or its affiliates.

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).

Oracle Java Platform Extension for Visual Studio Code
Copyright (c) 2023-2024, Oracle and/or its affiliates.

Apache NetBeans
Copyright 2017-2024 The Apache Software Foundation

Expand All @@ -14,3 +14,9 @@ The code was Copyright 1997-2016 Oracle and/or its affiliates. The Initial
Developer of the Original Software was Sun Microsystems, Inc. Portions
Copyright 1997-2006 Sun Microsystems, Inc.

---

vscode/src/localiser.ts
This file includes portions derived from the Localization tooling for Visual Studio Code
@vscode/l10n software developed at Microsoft Corporation licensed under the MIT License.
Copyright (c) Microsoft Corporation
69 changes: 38 additions & 31 deletions THIRD_PARTY_LICENSES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9448,37 +9448,6 @@ SOFTWARE.

------------------ END OF DEPENDENCY LICENSE --------------------

Dependency: VS Code tooling for localizing Visual Studio Code extensions
========================================================================

------------------ START OF DEPENDENCY LICENCE --------------------
- @vscode/l10n

MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE

------------------ END OF DEPENDENCY LICENCE --------------------


Dependency: VS Code Debug Protocol and Debug Adapter
====================================================

Expand Down Expand Up @@ -9875,3 +9844,41 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

------------------ END OF DEPENDENCY LICENSE --------------------

vscode/src/localiser.ts
=======================
Accessible at: vscode/src/localiser.ts

- @vscode/l10n
This file includes portions derived from the Localization tooling for Visual Studio Code
@vscode/l10n software developed at Microsoft Corporation licensed under the MIT License.

Derived from source at: https://github.com/microsoft/vscode-l10n/blob/57b5918f3b247a03387432037669e8ae5aff886b/l10n/src/main.ts#L222
License: MIT License

------------------ START OF DEPENDENCY LICENSE --------------------
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE

------------------ END OF DEPENDENCY LICENSE --------------------


7 changes: 0 additions & 7 deletions vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,6 @@
},
"dependencies": {
"@vscode/debugadapter": "^1.68.0",
"@vscode/l10n": "^0.0.18",
"ajv": "^8.17.1",
"jsonc-parser": "3.3.1",
"vscode-languageclient": "^9.0.1"
Expand Down
106 changes: 77 additions & 29 deletions vscode/src/localiser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2023-2024, Oracle and/or its affiliates.
Copyright (c) 2023-2025, Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -16,49 +16,97 @@

'use strict';

import * as l10nLib from '@vscode/l10n'

import * as vscode from 'vscode';
import * as fs from 'fs';
import { extConstants } from './constants';
import { FileUtils } from './utils';
import { LOGGER } from './logger';
import * as path from 'path';

const DEFAULT_LANGAUGE = "en";
const DEFAULT_BUNDLE_FILE = `l10n/bundle.l10n.${DEFAULT_LANGAUGE}.json`;

type TranslatorFn = typeof vscode.l10n.t
const DEFAULT_LANGUAGE = "en";
const DEFAULT_BUNDLE_FILE = path.join("l10n", `bundle.l10n.${DEFAULT_LANGUAGE}.json`);
const _format2Regexp = /{([^}]+)}/g;

export interface l10n {
value(key: string, placeholderMap?: Record<string, any>): string
nbLocaleCode():string
nbLocaleCode(): string
}


class l10Wrapper implements l10n {
private defaultTranslation: TranslatorFn;

constructor(extensionId: string, defaultBundlePath: string) {
let defaultBundleAbsoluteFsPath = FileUtils.toUri(`${vscode.extensions.getExtension(extensionId)?.extensionPath}/${defaultBundlePath}`).fsPath;
l10nLib.config({
fsPath: defaultBundleAbsoluteFsPath
});
this.defaultTranslation = l10nLib.t;
private defaultl10nMap: any;
constructor(extensionId: string, defaultBundlePath: string) {
let extnPath = vscode.extensions.getExtension(extensionId)!!.extensionPath;
let defaultBundleAbsoluteFsPath = FileUtils.toUri(path.join(extnPath,defaultBundlePath)).fsPath;
let fileContent: string = "";
try {
fileContent = fs.readFileSync(defaultBundleAbsoluteFsPath, 'utf-8');
} catch (err) {
LOGGER.logAndThrowError("error occured while reading bundle file : ", err);
}
try {
this.defaultl10nMap = JSON.parse(fileContent);
} catch (err) {
LOGGER.logAndThrowError("error occured while parsing bundle file : ", err);
}

value(key: string, placeholderMap: Record<string, any>): string {
const valueFromBundle:string = vscode.l10n.bundle ? vscode.l10n.t(key, placeholderMap) : key;
const isPresentInBundle = valueFromBundle !== key;
return isPresentInBundle ? valueFromBundle : this.defaultTranslation(key, placeholderMap);
}

value(key: string, placeholderMap: Record<string, any>): string {
const valueFromBundle: string = vscode.l10n.bundle ? vscode.l10n.t(key, placeholderMap) : key;
const isPresentInBundle = valueFromBundle !== key;
return isPresentInBundle ? valueFromBundle : this.defaultTranslation(key, placeholderMap);
}
defaultTranslation(key: string, placeholderMap: Record<string, any>): string {
let value = this.defaultl10nMap[key];
return value ? this.format(value, placeholderMap) : key;
}
nbLocaleCode() {
const vscodeLanguage = vscode.env.language;
if (!vscodeLanguage) return DEFAULT_LANGUAGE;
const localeParts = vscodeLanguage.split(/[-_]/g);
if (localeParts.length > 1) {
localeParts[1] = localeParts[1].toUpperCase();
}
nbLocaleCode(){
const vscodeLanguage = vscode.env.language;
if (!vscodeLanguage) return DEFAULT_LANGAUGE;
const localeParts = vscodeLanguage.split(/[-_]/g);
if (localeParts.length > 1) {
localeParts[1] = localeParts[1].toUpperCase();
}
var nbFormatLocale = localeParts.join(":");
return nbFormatLocale;
var nbFormatLocale = localeParts.join(":");
return nbFormatLocale;
}


//copied from:
//https://github.com/microsoft/vscode-l10n/blob/57b5918f3b247a03387432037669e8ae5aff886b/l10n/src/main.ts#L222
//original license: MIT
/*
Copyright (c) Microsoft Corporation

All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
*/
format(template: string, values: Record<string, unknown>): string {
if (!values || Object.keys(values).length === 0) {
return template;
}
return template.replace(_format2Regexp, (match, group) => (values[group] ?? match) as string);
}
}


Expand Down
10 changes: 10 additions & 0 deletions vscode/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
import { OutputChannel, window } from "vscode";
import { extConstants } from "./constants";
import { isError } from "./utils";

enum LogLevel {
INFO = 'INFO',
Expand Down Expand Up @@ -54,6 +55,15 @@ export class ExtensionLogger {
}
}

public logAndThrowError (message: string, err: unknown) {
let errMsg = "";
if (isError(err)) {
errMsg = err?.message
}
LOGGER.error(message + errMsg);
throw err;
}

public logNoNL(message: string): void {
this.outChannel.append(message);
}
Expand Down
13 changes: 12 additions & 1 deletion vscode/src/test/integration/suite/localisation/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,24 @@ import * as path from 'path';
import * as vscode from 'vscode';

import { extensions, window } from 'vscode';
import { l10n } from '../../../../localiser'
import { DEFAULT_BUNDLE_FILE_NAME, DEFAULT_PACKAGE_FILE_NAME, EXTENSION_NAME, SUPPORTED_LANGUAGES } from '../../constants';
import { checkCommandsLocalisation, checkConfigurationLocalisation, checkDebuggersLocalisation, checkL10nUsageInFiles, checkViewsLocalisation, getKeysFromJSON, matchKeys, matchValuesTemplate } from '../../testutils';


suite("Extension localisation tests", function () {
window.showInformationMessage("Starting Localisation tests");
// Check the consistency of the keys and value templates across the bundle files for the supported languages
test("localiser lib tests", async () => {
assert.equal(
l10n.value("jdk.downloader.message.downloadCompleted", { "jdkVersion": "25", "osType": "macOS", "jdkType": "OpenJDK" }),
"OpenJDK 25 for macOS download completed!"
)
assert.equal(
l10n.value("jdk.downloader.error_message.installationCleanup"),
"Error while installation cleanup"
)
})
// Check the consistency of the keys and value templates across the bundle files for the supported languages
test("Consistency of keys across bundle.l10n.lang.json files for supported languages", async () => {
const extension = extensions.getExtension(EXTENSION_NAME);
assert(extension);
Expand Down
Loading