mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-18 07:47:23 +01:00
* Add sessions support to translation resources and update related logic Fixes https://github.com/microsoft/vscode/issues/300278 * update to track new format of import * fix failures
71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import * as eslint from 'eslint';
|
|
import { TSESTree } from '@typescript-eslint/utils';
|
|
import { readFileSync } from 'fs';
|
|
import { createImportRuleListener } from './utils.ts';
|
|
|
|
|
|
export default new class TranslationRemind implements eslint.Rule.RuleModule {
|
|
|
|
private static NLS_MODULE = 'vs/nls';
|
|
|
|
readonly meta: eslint.Rule.RuleMetaData = {
|
|
messages: {
|
|
missing: 'Please add \'{{resource}}\' to ./build/lib/i18n.resources.json file to use translations here.'
|
|
},
|
|
schema: false,
|
|
};
|
|
|
|
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
|
|
return createImportRuleListener((node, path) => this._checkImport(context, node, path));
|
|
}
|
|
|
|
private _checkImport(context: eslint.Rule.RuleContext, node: TSESTree.Node, path: string) {
|
|
|
|
if (path !== TranslationRemind.NLS_MODULE && !path.endsWith('/nls.js')) {
|
|
return;
|
|
}
|
|
|
|
const currentFile = context.getFilename();
|
|
const matchService = currentFile.match(/vs\/workbench\/services\/\w+/);
|
|
const matchPart = currentFile.match(/vs\/workbench\/contrib\/\w+/);
|
|
const matchSessionsPart = currentFile.match(/vs\/sessions\/contrib\/\w+/);
|
|
if (!matchService && !matchPart && !matchSessionsPart) {
|
|
return;
|
|
}
|
|
|
|
const resource = matchService ? matchService[0] : matchPart ? matchPart[0] : matchSessionsPart![0];
|
|
let resourceDefined = false;
|
|
|
|
let json;
|
|
try {
|
|
json = readFileSync('./build/lib/i18n.resources.json', 'utf8');
|
|
} catch (e) {
|
|
console.error('[translation-remind rule]: File with resources to pull from Transifex was not found. Aborting translation resource check for newly defined workbench part/service.');
|
|
return;
|
|
}
|
|
const parsed = JSON.parse(json);
|
|
const resources = [...parsed.workbench, ...parsed.sessions];
|
|
|
|
resources.forEach((existingResource: any) => {
|
|
if (existingResource.name === resource) {
|
|
resourceDefined = true;
|
|
return;
|
|
}
|
|
});
|
|
|
|
if (!resourceDefined) {
|
|
context.report({
|
|
loc: node.loc,
|
|
messageId: 'missing',
|
|
data: { resource }
|
|
});
|
|
}
|
|
}
|
|
};
|
|
|