Skip to content

Commit b94af21

Browse files
override json service translation
1 parent 3349e02 commit b94af21

File tree

9 files changed

+39
-30
lines changed

9 files changed

+39
-30
lines changed

l10n/bundle.l10n.de.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"Default Value": "Standardwert",
33
"json.schema.invalidref": "$ref '{0}' in '{1}' kann nicht aufgelöst werden.",
44
"json.schema.problemloadingref": "Probleme beim Laden der Referenz '{0}': {1}",
5-
"json.schema.nocontent": "Schema von '{0}' konnte nicht geladen werden: Kein Inhalt. {1}",
6-
"json.schema.invalidFormat": "Inhalt von '{0}' konnte nicht geparst werden: {1}",
5+
"json.schema.nocontent": "Schema konnte nicht von '{0}' geladen werden: Kein Inhalt.",
6+
"json.schema.invalidFormat": "Inhalt von '{0}' konnte nicht analysiert werden: Analysefehler in Zeile {1}, Spalte {2}",
77
"colorHexFormatWarning": "Ungültiges Farbformat. Verwenden Sie #RGB, #RGBA, #RRGGBB oder #RRGGBBAA.",
88
"dateTimeFormatWarning": "Zeichenfolge ist kein RFC3339-Datum-Zeit-Wert.",
99
"dateFormatWarning": "Zeichenfolge ist kein RFC3339-Datum.",

l10n/bundle.l10n.fr.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"Default Value": "Valeur par défaut",
33
"json.schema.invalidref": "$ref '{0}' dans '{1}' ne peut pas être résolu",
44
"json.schema.problemloadingref": "Problèmes de chargement de la référence '{0}' : {1}",
5-
"json.schema.nocontent": "Impossible de charger le schéma depuis «{0}»: aucun contenu. {1}",
6-
"json.schema.invalidFormat": "Impossible d'analyser le contenu de « {0} » : {1}",
5+
"json.schema.noContent": "Impossible de charger le schéma à partir de {0}: aucun contenu.",
6+
"json.schema.invalidFormat": "Impossible danalyser le contenu de {0}: erreur d’analyse à la ligne {1}, colonne {2}",
77
"colorHexFormatWarning": "Format de couleur non valide. Utilisez #RGB, #RGBA, #RRGGBB ou #RRGGBBAA.",
88
"dateTimeFormatWarning": "La chaîne n'est pas une date-heure RFC3339.",
99
"dateFormatWarning": "La chaîne n'est pas une date RFC3339.",

l10n/bundle.l10n.ja.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"Default Value": "デフォルト値",
33
"json.schema.invalidref": "'{1}' の $ref '{0}' を解決できません。",
44
"json.schema.problemloadingref": "参照 '{0}' の読み込み中に問題が発生しました: {1}",
5-
"json.schema.nocontent": "'{0}' からスキーマを読み込めません: 内容がありません。{1}",
6-
"json.schema.invalidFormat": "'{0}' の内容を解析できません: {1}",
5+
"json.schema.nocontent": "'{0}' からスキーマを読み込めませんでした: コンテンツがありません。",
6+
"json.schema.invalidFormat": "'{0}' の内容を解析できませんでした: 行 {1}、列 {2} で解析エラーが発生しました",
77
"colorHexFormatWarning": "無効なカラー形式です。#RGB、#RGBA、#RRGGBB、または #RRGGBBAA を使用してください。",
88
"dateTimeFormatWarning": "文字列は RFC3339 の日付と時刻形式ではありません。",
99
"dateFormatWarning": "文字列は RFC3339 の日付形式ではありません。",

l10n/bundle.l10n.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"Default Value": "Default value",
33
"json.schema.invalidref": "$ref '{0}' in '{1}' can not be resolved.",
44
"json.schema.problemloadingref": "Problems loading reference '{0}': {1}",
5-
"json.schema.nocontent": "Unable to load schema from '{0}': No content. {1}",
6-
"json.schema.invalidFormat": "Unable to parse content from '{0}': {1}",
5+
"json.schema.noContent": "Unable to load schema from '{0}': No content.",
6+
"json.schema.invalidFormat": "Unable to parse content from '{0}': Parse error at line: {1} column: {2}",
77
"colorHexFormatWarning": "Invalid color format. Use #RGB, #RGBA, #RRGGBB or #RRGGBBAA.",
88
"dateTimeFormatWarning": "String is not a RFC3339 date-time.",
99
"dateFormatWarning": "String is not a RFC3339 date.",

l10n/bundle.l10n.ko.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"Default Value": "기본값",
33
"json.schema.invalidref": "'{1}'의 $ref '{0}'을(를) 확인할 수 없습니다.",
44
"json.schema.problemloadingref": "'{0}' 참조를 불러오는 데 문제가 발생했습니다: {1}",
5-
"json.schema.nocontent": "'{0}'에서 스키마를 불러올 수 없습니다: 내용 없음. {1}",
6-
"json.schema.invalidFormat": "'{0}'에서 내용을 구문 분석할 수 없습니다: {1}",
5+
"json.schema.nocontent": "'{0}'에서 스키마를 불러올 수 없습니다: 내용이 없습니다.",
6+
"json.schema.invalidFormat": "'{0}' 내용을 구문 분석할 수 없습니다: {1}행 {2}열에서 구문 오류가 발생했습니다",
77
"colorHexFormatWarning": "잘못된 색상 형식입니다. #RGB, #RGBA, #RRGGBB 또는 #RRGGBBAA를 사용하세요.",
88
"dateTimeFormatWarning": "문자열이 RFC3339 날짜-시간 형식이 아닙니다.",
99
"dateFormatWarning": "문자열이 RFC3339 날짜 형식이 아닙니다.",

l10n/bundle.l10n.zh-cn.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"Default Value": "默认值",
33
"json.schema.invalidref": "在 '{1}' 中的 $ref '{0}' 无法解析。",
44
"json.schema.problemloadingref": "加载引用 '{0}' 时出现问题:{1}",
5-
"json.schema.nocontent": "无法从 '{0}' 加载模式:无内容。{1}",
6-
"json.schema.invalidFormat": "无法解析来自 '{0}' 的内容:{1}",
5+
"json.schema.nocontent": "无法从{0}”加载架构:没有内容。",
6+
"json.schema.invalidFormat": "无法解析来自{0}的内容:在第 {1} 行第 {2} 列发生解析错误",
77
"colorHexFormatWarning": "无效的颜色格式。请使用 #RGB、#RGBA、#RRGGBB 或 #RRGGBBAA。",
88
"dateTimeFormatWarning": "字符串不是 RFC3339 日期时间格式。",
99
"dateFormatWarning": "字符串不是 RFC3339 日期格式。",

l10n/bundle.l10n.zh-tw.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"Default Value": "預設值",
33
"json.schema.invalidref": "在 '{1}' 中的 $ref '{0}' 無法解析。",
44
"json.schema.problemloadingref": "載入參考 '{0}' 時出現問題:{1}",
5-
"json.schema.nocontent": "無法從 '{0}' 載入結構:無內容。{1}",
6-
"json.schema.invalidFormat": "無法解析來自 '{0}' 的內容:{1}",
5+
"json.schema.nocontent": "無法從{0}」載入結構描述:沒有內容。",
6+
"json.schema.invalidFormat": "無法解析來自{0}的內容:在第 {1} 行第 {2} 欄發生解析錯誤",
77
"colorHexFormatWarning": "無效的顏色格式。請使用 #RGB、#RGBA、#RRGGBB 或 #RRGGBBAA。",
88
"dateTimeFormatWarning": "字串不是 RFC3339 日期時間格式。",
99
"dateFormatWarning": "字串不是 RFC3339 日期格式。",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"lodash": "4.17.21",
3333
"prettier": "^3.5.0",
3434
"request-light": "^0.5.7",
35-
"vscode-json-languageservice": "4.1.8",
35+
"vscode-json-languageservice": "5.6.0",
3636
"vscode-languageserver": "^9.0.0",
3737
"vscode-languageserver-textdocument": "^1.0.1",
3838
"vscode-languageserver-types": "^3.16.0",

src/languageservice/services/yamlSchemaService.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import * as l10n from '@vscode/l10n';
2020
import { convertSimple2RegExpPattern } from '../utils/strings';
2121
import { SingleYAMLDocument } from '../parser/yamlParser07';
2222
import { JSONDocument } from '../parser/jsonParser07';
23-
import { parse } from 'yaml';
2423
import * as path from 'path';
2524
import { getSchemaFromModeline } from './modelineUtil';
2625
import { JSONSchemaDescriptionExt } from '../../requestTypes';
2726
import { SchemaVersions } from '../yamlTypes';
2827

28+
import * as Json from 'jsonc-parser';
2929
import Ajv, { DefinedError } from 'ajv';
3030
import Ajv4 from 'ajv-draft-04';
3131
import { getSchemaTitle } from '../utils/schemaUtils';
@@ -643,31 +643,33 @@ export class YAMLSchemaService extends JSONSchemaService {
643643
// If the YAML file starts with %YAML 1.x or contains a comment with a number the schema will
644644
// contain a number instead of being undefined, so we need to check for that too.
645645
if (
646-
unresolvedJsonSchema.errors &&
647-
(unresolvedJsonSchema.schema === undefined || typeof unresolvedJsonSchema.schema === 'number')
646+
unresolvedJsonSchema.errors ||
647+
unresolvedJsonSchema.schema === undefined ||
648+
typeof unresolvedJsonSchema.schema === 'number'
648649
) {
649650
return requestService(schemaUri).then(
650651
(content) => {
651652
if (!content) {
652-
const errorMessage = l10n.t('json.schema.nocontent', toDisplayString(schemaUri), unresolvedJsonSchema.errors);
653+
const errorMessage = l10n.t('json.schema.noContent', toDisplayString(schemaUri), unresolvedJsonSchema.errors);
653654
return new UnresolvedSchema(<JSONSchema>{}, [errorMessage]);
654655
}
655-
656-
try {
657-
const schemaContent = parse(content);
658-
return new UnresolvedSchema(schemaContent, []);
659-
} catch (yamlError) {
660-
const errorMessage = l10n.t('json.schema.invalidFormat', toDisplayString(schemaUri), yamlError);
661-
return new UnresolvedSchema(<JSONSchema>{}, [errorMessage]);
656+
const jsonErrors: Json.ParseError[] = [];
657+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
658+
const schemaContent = Json.parse(content, jsonErrors);
659+
let errorMessage = '';
660+
if (jsonErrors.length) {
661+
const { offset } = jsonErrors[0];
662+
const { line, column } = getLineAndColumnFromOffset(content, offset);
663+
errorMessage = l10n.t('json.schema.invalidFormat', toDisplayString(schemaUri), line, column);
662664
}
665+
return new UnresolvedSchema(<JSONSchema>{}, [errorMessage]);
663666
},
664-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
665-
(error: any) => {
667+
(error: unknown) => {
666668
let errorMessage = error.toString();
667-
const errorSplit = error.toString().split('Error: ');
669+
const errorSplit = error.toString().split('vscode/content');
668670
if (errorSplit.length > 1) {
669671
// more concise error message, URL and context are attached by caller anyways
670-
errorMessage = errorSplit[1];
672+
errorMessage = l10n.t('json.schema.noContent', toDisplayString(schemaUri));
671673
}
672674
return new UnresolvedSchema(<JSONSchema>{}, [errorMessage]);
673675
}
@@ -731,3 +733,10 @@ function toDisplayString(url: string): string {
731733
}
732734
return url;
733735
}
736+
737+
function getLineAndColumnFromOffset(text: string, offset: number): { line: number; column: number } {
738+
const lines = text.slice(0, offset).split(/\r?\n/);
739+
const line = lines.length; // 1-based line number
740+
const column = lines[lines.length - 1].length + 1; // 1-based column number
741+
return { line, column };
742+
}

0 commit comments

Comments
 (0)