Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1015a57
added l10n bundle for various language and translate the local strings
msivasubramaniaan Jun 23, 2025
850927c
upstream node
msivasubramaniaan Jun 23, 2025
53a15d2
upstream node
msivasubramaniaan Jun 23, 2025
3fbdc6d
update to node 18
msivasubramaniaan Jun 23, 2025
08e598b
Changed NodeJS.Timeout as per node 18
msivasubramaniaan Jun 23, 2025
b19b0ea
upstream to node 20
msivasubramaniaan Jun 23, 2025
9fb148b
updated coversall script
msivasubramaniaan Jun 23, 2025
3349e02
fixed test case
msivasubramaniaan Jun 23, 2025
b94af21
override json service translation
msivasubramaniaan Jun 26, 2025
4356f99
fixed test cases
msivasubramaniaan Jun 26, 2025
7dae881
added test cases for bundle and configuration through testhelper class
msivasubramaniaan Jun 27, 2025
3eb3626
Merge branch 'main' into added-localization-strings
msivasubramaniaan Jun 27, 2025
b9adc12
added l10n bundle for various language and translate the local strings
msivasubramaniaan Jun 23, 2025
1d5e894
upstream node
msivasubramaniaan Jun 23, 2025
ac90596
upstream node
msivasubramaniaan Jun 23, 2025
fa7b1ce
override json service translation
msivasubramaniaan Jun 26, 2025
9a3b35a
fixed test cases
msivasubramaniaan Jun 26, 2025
04f459d
added test cases for bundle and configuration through testhelper class
msivasubramaniaan Jun 27, 2025
60bdbf9
Merge branch 'added-localization-strings' of https://github.com/msiva…
msivasubramaniaan Jun 27, 2025
699f38a
Merge branch 'main' into added-localization-strings
msivasubramaniaan Jul 2, 2025
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
2 changes: 1 addition & 1 deletion l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@
"flowStyleMapForbidden": "Flow style mapping is forbidden",
"flowStyleSeqForbidden": "Flow style sequence is forbidden",
"unUsedAnchor": "Unused anchor \"{0}\"",
"unUsedAlias": "Unresolved alias \"{0}\""
"unUsedAlias": "Unresolved alias \"{0}\""
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
"clean": "rimraf out/server && rimraf lib",
"compile": "tsc -p .",
"watch": "tsc --watch -p .",
"test": "mocha --require ts-node/register --require ./scripts/setup-l10n.mjs --timeout 5000 --ui bdd ./test/*.test.ts",
"test": "mocha --require ts-node/register --timeout 5000 --ui bdd ./test/*.test.ts",
"coverage": "nyc mocha --require ts-node/register --timeout 5000 --require source-map-support/register --recursive --ui bdd ./test/*.test.ts",
"coveralls": "nyc --reporter=lcov --reporter=text mocha --timeout 5000 --require ts-node/register --require ./scripts/setup-l10n.mjs --require source-map-support/register --recursive --ui bdd ./test/*.test.ts",
"coveralls": "nyc --reporter=lcov --reporter=text mocha --timeout 5000 --require ts-node/register --require source-map-support/register --recursive --ui bdd ./test/*.test.ts",
"lint": "eslint --max-warnings 0 -c .eslintrc.js --ext .ts src test",
"lint-ci": "eslint --max-warnings 0 -c .eslintrc.js -f @microsoft/eslint-formatter-sarif -o eslint-result.sarif --ext .ts src test",
"prettier-fix": "yarn prettier --write .",
Expand Down
31 changes: 0 additions & 31 deletions scripts/setup-l10n.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion src/languageservice/parser/jsonParser07.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ function validate(
validationResult.problems.push({
location: { offset: node.offset, length: node.length },
severity: DiagnosticSeverity.Warning,
message: schema.patternErrorMessage || schema.errorMessage || format.errorMessage,
message: schema.patternErrorMessage || schema.errorMessage || l10n.t(format.errorMessage),
source: getSchemaSource(schema, originalSchema),
schemaUri: getSchemaUri(schema, originalSchema),
});
Expand Down
14 changes: 2 additions & 12 deletions src/languageservice/services/yamlSchemaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,25 +650,15 @@ export class YAMLSchemaService extends JSONSchemaService {
return requestService(schemaUri).then(
(content) => {
if (!content) {
const errorMessage = l10n.t(
'json.schema.nocontent',
"Unable to load schema from '{0}': No content. {1}",
toDisplayString(schemaUri),
unresolvedJsonSchema.errors
);
const errorMessage = l10n.t('json.schema.nocontent', toDisplayString(schemaUri), unresolvedJsonSchema.errors);
return new UnresolvedSchema(<JSONSchema>{}, [errorMessage]);
}

try {
const schemaContent = parse(content);
return new UnresolvedSchema(schemaContent, []);
} catch (yamlError) {
const errorMessage = l10n.t(
'json.schema.invalidFormat',
"Unable to parse content from '{0}': {1}.",
toDisplayString(schemaUri),
yamlError
);
const errorMessage = l10n.t('json.schema.invalidFormat', toDisplayString(schemaUri), yamlError);
return new UnresolvedSchema(<JSONSchema>{}, [errorMessage]);
}
},
Expand Down
35 changes: 21 additions & 14 deletions src/yamlServerInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Telemetry } from './languageservice/telemetry';
import { registerCommands } from './languageservice/services/yamlCommands';
import * as l10n from '@vscode/l10n';
import * as path from 'path';
import * as fs from 'fs';

export class YAMLServerInit {
languageService: LanguageService;
Expand All @@ -41,19 +42,6 @@ export class YAMLServerInit {
* The server receives the root path(s) of the workspace and the client capabilities.
*/
this.connection.onInitialize(async (params: InitializeParams): Promise<InitializeResult> => {
const l10nPath: string = params.initializationOptions?.l10nPath;
const locale: string = params.locale;
if (l10nPath) {
const bundleFile = locale === 'en' ? `bundle.l10n.json` : `bundle.l10n.${locale}.json`;
const baseBundleFile = path.join(l10nPath, bundleFile);
process.env.VSCODE_NLS_CONFIG = JSON.stringify({
locale: locale,
_languagePackSupport: true,
});
await l10n.config({
uri: URI.file(baseBundleFile).toString(),
});
}
return this.connectionInitialized(params);
});

Expand All @@ -69,6 +57,25 @@ export class YAMLServerInit {
});
}

public async setupl10nBundle(params: InitializeParams): Promise<void> {
const __dirname = path.dirname(__filename);
const l10nPath: string = params.initializationOptions?.l10nPath || path.join(__dirname, '../l10n');
const locale: string = params.locale || 'en';
if (l10nPath) {
const bundleFile = !fs.existsSync(path.join(l10nPath, `bundle.l10n.${locale}.json`))
? `bundle.l10n.json`
: `bundle.l10n.${locale}.json`;
const baseBundleFile = path.join(l10nPath, bundleFile);
process.env.VSCODE_NLS_CONFIG = JSON.stringify({
locale,
_languagePackSupport: true,
});
await l10n.config({
uri: URI.file(baseBundleFile).toString(),
});
}
}

// public for test setup
async connectionInitialized(params: InitializeParams): Promise<InitializeResult> {
this.yamlSettings.capabilities = params.capabilities;
Expand Down Expand Up @@ -111,7 +118,7 @@ export class YAMLServerInit {
);
this.registerHandlers();
registerCommands(commandExecutor, this.connection);

await this.setupl10nBundle(params);
return {
capabilities: {
textDocumentSync: TextDocumentSyncKind.Incremental,
Expand Down
71 changes: 71 additions & 0 deletions test/bundlel10n.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Red Hat. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { SettingsState } from '../src/yamlSettings';
import { TestCustomSchemaProvider, testFileSystem } from './utils/testHelper';
import { createConnection, Connection } from 'vscode-languageserver/node';
import { schemaRequestHandler, workspaceContext } from '../src/languageservice/services/schemaRequestHandler';
import { TestTelemetry } from './utils/testsTypes';
import { YAMLServerInit } from '../src/yamlServerInit';
import * as l10n from '@vscode/l10n';

describe('Bundle l10n Test', () => {
let serverInit: YAMLServerInit;

before(() => {
const yamlSettings = new SettingsState();
process.argv.push('--node-ipc');
const connection = createConnection();
const schemaRequestHandlerWrapper = (connection: Connection, uri: string): Promise<string> => {
const testSchemaProvider = TestCustomSchemaProvider.instance();
const testSchema = testSchemaProvider.getContentForSchema(uri);
if (testSchema) {
return Promise.resolve(testSchema);
}
return schemaRequestHandler(
connection,
uri,
yamlSettings.workspaceFolders,
yamlSettings.workspaceRoot,
yamlSettings.useVSCodeContentRequest,
testFileSystem
);
};
const schemaRequestService = schemaRequestHandlerWrapper.bind(this, connection);
const telemetry = new TestTelemetry(connection);
serverInit = new YAMLServerInit(connection, yamlSettings, workspaceContext, schemaRequestService, telemetry);
});

after(async () => {
await serverInit.setupl10nBundle({
locale: 'en',
processId: 0,
rootUri: '',
capabilities: undefined,
});
});

describe('l10n bundle test', function () {
it('check french locale', async () => {
await serverInit.setupl10nBundle({
locale: 'fr',
processId: 0,
rootUri: '',
capabilities: undefined,
});
assert.equal(l10n.t('Default Value'), 'Valeur par défaut');
});

it('un configured locale should return in english', async () => {
await serverInit.setupl10nBundle({
locale: 'pt-br',
processId: 0,
rootUri: '',
capabilities: undefined,
});
assert.equal(l10n.t('Default Value'), 'Default value');
});
});
});
5 changes: 5 additions & 0 deletions test/utils/testHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,16 @@ export function setupLanguageService(languageSettings: LanguageSettings): TestLa
const schemaRequestService = schemaRequestHandlerWrapper.bind(this, connection);
const telemetry = new TestTelemetry(connection);
const serverInit = new YAMLServerInit(connection, yamlSettings, workspaceContext, schemaRequestService, telemetry);
const __dirname = path.resolve(path.dirname(__filename), '..');
serverInit.connectionInitialized({
processId: null,
capabilities: ClientCapabilities.LATEST as LSPClientCapabilities,
rootUri: null,
workspaceFolders: null,
initializationOptions: {
l10nPath: path.join(__dirname, '../l10n'),
},
locale: 'en',
});
const languageService = serverInit.languageService;
const validationHandler = serverInit.validationHandler;
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1364,9 +1364,9 @@ ecc-jsbn@~0.1.1:
safer-buffer "^2.1.0"

electron-to-chromium@^1.5.173:
version "1.5.176"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.176.tgz#f4bbbd2c0a9a6a2a527c884eacc18244fa79dd88"
integrity sha512-2nDK9orkm7M9ZZkjO3PjbEd3VUulQLyg5T9O3enJdFvUg46Hzd4DUvTvAuEgbdHYXyFsiG4A5sO9IzToMH1cDg==
version "1.5.177"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.177.tgz#db730d8254959184e65320a3a0b7edcd29c54f60"
integrity sha512-7EH2G59nLsEMj97fpDuvVcYi6lwTcM1xuWw3PssD8xzboAW7zj7iB3COEEEATUfjLHrs5uKBLQT03V/8URx06g==

emoji-regex@^8.0.0:
version "8.0.0"
Expand Down Expand Up @@ -3155,9 +3155,9 @@ prettier-linter-helpers@^1.0.0:
fast-diff "^1.1.2"

prettier@^3.5.0:
version "3.6.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.6.1.tgz#cc3bce21c09a477b1e987b76ce9663925d86ae44"
integrity sha512-5xGWRa90Sp2+x1dQtNpIpeOQpTDBs9cZDmA/qs2vDNN2i18PdapqY7CmBeyLlMuGqXJRIOPaCaVZTLNQRWUH/A==
version "3.6.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.6.2.tgz#ccda02a1003ebbb2bfda6f83a074978f608b9393"
integrity sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==

process-on-spawn@^1.0.0:
version "1.1.0"
Expand Down