Skip to content

Commit 19682d3

Browse files
committed
removing l10n lib and adding required changes .
1 parent f5b738d commit 19682d3

File tree

13 files changed

+282
-82
lines changed

13 files changed

+282
-82
lines changed

NOTICE

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
Oracle Java Platform Extension for Visual Studio Code
2+
Copyright (c) 2023-2025, Oracle and/or its affiliates.
3+
14
This product includes software developed at
25
The Apache Software Foundation (http://www.apache.org/).
36

4-
Oracle Java Platform Extension for Visual Studio Code
5-
Copyright (c) 2023-2024, Oracle and/or its affiliates.
6-
77
Apache NetBeans
88
Copyright 2017-2024 The Apache Software Foundation
99

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

17+
---
18+
19+
vscode/src/localiser.ts
20+
This file includes portions derived from the Localization tooling for Visual Studio Code
21+
@vscode/l10n software developed at Microsoft Corporation licensed under the MIT License.
22+
Copyright (c) Microsoft Corporation

THIRD_PARTY_LICENSES.txt

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9448,37 +9448,6 @@ SOFTWARE.
94489448

94499449
------------------ END OF DEPENDENCY LICENSE --------------------
94509450

9451-
Dependency: VS Code tooling for localizing Visual Studio Code extensions
9452-
========================================================================
9453-
9454-
------------------ START OF DEPENDENCY LICENCE --------------------
9455-
- @vscode/l10n
9456-
9457-
MIT License
9458-
9459-
Copyright (c) Microsoft Corporation.
9460-
9461-
Permission is hereby granted, free of charge, to any person obtaining a copy
9462-
of this software and associated documentation files (the "Software"), to deal
9463-
in the Software without restriction, including without limitation the rights
9464-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9465-
copies of the Software, and to permit persons to whom the Software is
9466-
furnished to do so, subject to the following conditions:
9467-
9468-
The above copyright notice and this permission notice shall be included in all
9469-
copies or substantial portions of the Software.
9470-
9471-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9472-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9473-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9474-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9475-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9476-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
9477-
SOFTWARE
9478-
9479-
------------------ END OF DEPENDENCY LICENCE --------------------
9480-
9481-
94829451
Dependency: VS Code Debug Protocol and Debug Adapter
94839452
====================================================
94849453

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

98779846
------------------ END OF DEPENDENCY LICENSE --------------------
9847+
9848+
vscode/src/localiser.ts
9849+
=======================
9850+
Accessible at: vscode/src/localiser.ts
9851+
9852+
- @vscode/l10n
9853+
This file includes portions derived from the Localization tooling for Visual Studio Code
9854+
@vscode/l10n software developed at Microsoft Corporation licensed under the MIT License.
9855+
9856+
Derived from source at: https://github.com/microsoft/vscode-l10n/blob/57b5918f3b247a03387432037669e8ae5aff886b/l10n/src/main.ts#L222
9857+
License: MIT License
9858+
9859+
------------------ START OF DEPENDENCY LICENSE --------------------
9860+
MIT License
9861+
9862+
Copyright (c) Microsoft Corporation.
9863+
9864+
Permission is hereby granted, free of charge, to any person obtaining a copy
9865+
of this software and associated documentation files (the "Software"), to deal
9866+
in the Software without restriction, including without limitation the rights
9867+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9868+
copies of the Software, and to permit persons to whom the Software is
9869+
furnished to do so, subject to the following conditions:
9870+
9871+
The above copyright notice and this permission notice shall be included in all
9872+
copies or substantial portions of the Software.
9873+
9874+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9875+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9876+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9877+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9878+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9879+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
9880+
SOFTWARE
9881+
9882+
------------------ END OF DEPENDENCY LICENSE --------------------
9883+
9884+

vscode/package-lock.json

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vscode/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,6 @@
953953
},
954954
"dependencies": {
955955
"@vscode/debugadapter": "^1.68.0",
956-
"@vscode/l10n": "^0.0.18",
957956
"ajv": "^8.17.1",
958957
"jsonc-parser": "3.3.1",
959958
"vscode-languageclient": "^9.0.1"

vscode/src/localiser.ts

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2023-2024, Oracle and/or its affiliates.
2+
Copyright (c) 2023-2025, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -16,49 +16,97 @@
1616

1717
'use strict';
1818

19-
import * as l10nLib from '@vscode/l10n'
20-
2119
import * as vscode from 'vscode';
20+
import * as fs from 'fs';
2221
import { extConstants } from './constants';
2322
import { FileUtils } from './utils';
23+
import { LOGGER } from './logger';
24+
import * as path from 'path';
2425

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

3030
export interface l10n {
3131
value(key: string, placeholderMap?: Record<string, any>): string
32-
nbLocaleCode():string
32+
nbLocaleCode(): string
3333
}
3434

3535

3636
class l10Wrapper implements l10n {
37-
private defaultTranslation: TranslatorFn;
38-
39-
constructor(extensionId: string, defaultBundlePath: string) {
40-
let defaultBundleAbsoluteFsPath = FileUtils.toUri(`${vscode.extensions.getExtension(extensionId)?.extensionPath}/${defaultBundlePath}`).fsPath;
41-
l10nLib.config({
42-
fsPath: defaultBundleAbsoluteFsPath
43-
});
44-
this.defaultTranslation = l10nLib.t;
37+
private defaultl10nMap: any;
38+
constructor(extensionId: string, defaultBundlePath: string) {
39+
let extnPath = vscode.extensions.getExtension(extensionId)!!.extensionPath;
40+
let defaultBundleAbsoluteFsPath = FileUtils.toUri(path.join(extnPath,defaultBundlePath)).fsPath;
41+
let fileContent: string = "";
42+
try {
43+
fileContent = fs.readFileSync(defaultBundleAbsoluteFsPath, 'utf-8');
44+
} catch (err) {
45+
LOGGER.logAndThrowError("error occured while reading bundle file : ", err);
46+
}
47+
try {
48+
this.defaultl10nMap = JSON.parse(fileContent);
49+
} catch (err) {
50+
LOGGER.logAndThrowError("error occured while parsing bundle file : ", err);
4551
}
4652

47-
value(key: string, placeholderMap: Record<string, any>): string {
48-
const valueFromBundle:string = vscode.l10n.bundle ? vscode.l10n.t(key, placeholderMap) : key;
49-
const isPresentInBundle = valueFromBundle !== key;
50-
return isPresentInBundle ? valueFromBundle : this.defaultTranslation(key, placeholderMap);
53+
}
54+
55+
value(key: string, placeholderMap: Record<string, any>): string {
56+
const valueFromBundle: string = vscode.l10n.bundle ? vscode.l10n.t(key, placeholderMap) : key;
57+
const isPresentInBundle = valueFromBundle !== key;
58+
return isPresentInBundle ? valueFromBundle : this.defaultTranslation(key, placeholderMap);
59+
}
60+
defaultTranslation(key: string, placeholderMap: Record<string, any>): string {
61+
let value = this.defaultl10nMap[key];
62+
return value ? this.format(value, placeholderMap) : key;
63+
}
64+
nbLocaleCode() {
65+
const vscodeLanguage = vscode.env.language;
66+
if (!vscodeLanguage) return DEFAULT_LANGUAGE;
67+
const localeParts = vscodeLanguage.split(/[-_]/g);
68+
if (localeParts.length > 1) {
69+
localeParts[1] = localeParts[1].toUpperCase();
5170
}
52-
nbLocaleCode(){
53-
const vscodeLanguage = vscode.env.language;
54-
if (!vscodeLanguage) return DEFAULT_LANGAUGE;
55-
const localeParts = vscodeLanguage.split(/[-_]/g);
56-
if (localeParts.length > 1) {
57-
localeParts[1] = localeParts[1].toUpperCase();
58-
}
59-
var nbFormatLocale = localeParts.join(":");
60-
return nbFormatLocale;
71+
var nbFormatLocale = localeParts.join(":");
72+
return nbFormatLocale;
73+
}
74+
75+
76+
//copied from:
77+
//https://github.com/microsoft/vscode-l10n/blob/57b5918f3b247a03387432037669e8ae5aff886b/l10n/src/main.ts#L222
78+
//original license: MIT
79+
/*
80+
Copyright (c) Microsoft Corporation
81+
82+
All rights reserved.
83+
84+
MIT License
85+
86+
Permission is hereby granted, free of charge, to any person obtaining a copy
87+
of this software and associated documentation files (the "Software"), to deal
88+
in the Software without restriction, including without limitation the rights
89+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
90+
copies of the Software, and to permit persons to whom the Software is
91+
furnished to do so, subject to the following conditions:
92+
93+
The above copyright notice and this permission notice shall be included in all
94+
copies or substantial portions of the Software.
95+
96+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
97+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
98+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
99+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
100+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
101+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
102+
SOFTWARE
103+
*/
104+
format(template: string, values: Record<string, unknown>): string {
105+
if (!values || Object.keys(values).length === 0) {
106+
return template;
61107
}
108+
return template.replace(_format2Regexp, (match, group) => (values[group] ?? match) as string);
109+
}
62110
}
63111

64112

vscode/src/logger.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
import { OutputChannel, window } from "vscode";
1717
import { extConstants } from "./constants";
18+
import { isError } from "./utils";
1819

1920
enum LogLevel {
2021
INFO = 'INFO',
@@ -54,6 +55,15 @@ export class ExtensionLogger {
5455
}
5556
}
5657

58+
public logAndThrowError (message: string, err: unknown) {
59+
let errMsg = "";
60+
if (isError(err)) {
61+
errMsg = err?.message
62+
}
63+
LOGGER.error(message + errMsg);
64+
throw err;
65+
}
66+
5767
public logNoNL(message: string): void {
5868
this.outChannel.append(message);
5969
}

vscode/src/test/integration/suite/localisation/extension.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,24 @@ import * as path from 'path';
2727
import * as vscode from 'vscode';
2828

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

3334

3435
suite("Extension localisation tests", function () {
3536
window.showInformationMessage("Starting Localisation tests");
36-
// Check the consistency of the keys and value templates across the bundle files for the supported languages
37+
test("localiser lib tests", async () => {
38+
assert.equal(
39+
l10n.value("jdk.downloader.message.downloadCompleted", { "jdkVersion": "25", "osType": "macOS", "jdkType": "OpenJDK" }),
40+
"OpenJDK 25 for macOS download completed!"
41+
)
42+
assert.equal(
43+
l10n.value("jdk.downloader.error_message.installationCleanup"),
44+
"Error while installation cleanup"
45+
)
46+
})
47+
// Check the consistency of the keys and value templates across the bundle files for the supported languages
3748
test("Consistency of keys across bundle.l10n.lang.json files for supported languages", async () => {
3849
const extension = extensions.getExtension(EXTENSION_NAME);
3950
assert(extension);

0 commit comments

Comments
 (0)