Skip to content
Merged
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
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
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