Skip to content

Commit

Permalink
feat(developer): report on mismatching lang tag scripts when building…
Browse files Browse the repository at this point in the history
… keyboard-info

This went into kmc-keyboard-info because we already do a lot of
processing there against langtags.json, whereas we do not currently have
langtags.json in kmc-package.

Adds an associated unit test.

Fixes: #12752
  • Loading branch information
mcdurdin committed Dec 2, 2024
1 parent ca9ac81 commit f3191b9
Show file tree
Hide file tree
Showing 10 changed files with 5,777 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CompilerErrorNamespace, CompilerErrorSeverity, CompilerMessageSpec as m

const Namespace = CompilerErrorNamespace.KeyboardInfoCompiler;
// const SevInfo = CompilerErrorSeverity.Info | Namespace;
// const SevHint = CompilerErrorSeverity.Hint | Namespace;
const SevHint = CompilerErrorSeverity.Hint | Namespace;
// const SevWarn = CompilerErrorSeverity.Warn | Namespace;
const SevError = CompilerErrorSeverity.Error | Namespace;
const SevFatal = CompilerErrorSeverity.Fatal | Namespace;
Expand Down Expand Up @@ -61,5 +61,10 @@ export class KeyboardInfoCompilerMessages {
static Error_DescriptionIsMissing = (o:{filename:string}) => m(
this.ERROR_DescriptionIsMissing,
`The Info.Description field in the package ${def(o.filename)} is required, but is missing or empty.`);

static HINT_ScriptDoesNotMatch = SevHint | 0x0011;
static Hint_ScriptDoesNotMatch = (o:{script: string, bcp47:string, commonScript: string}) => m(
this.HINT_ScriptDoesNotMatch,
`The script '${def(o.script)}' associated with language tag '${def(o.bcp47)}' does not match the script '${def(o.commonScript)}' for the first language in the package.`);
}

10 changes: 10 additions & 0 deletions developer/src/kmc-keyboard-info/src/keyboard-info-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ export class KeyboardInfoCompiler implements KeymanCompiler {
const fontSource = [].concat(...kmpJsonData.keyboards.map(e => e.displayFont ? [e.displayFont] : []), ...kmpJsonData.keyboards.map(e => e.webDisplayFonts ?? []));
const oskFontSource = [].concat(...kmpJsonData.keyboards.map(e => e.oskFont ? [e.oskFont] : []), ...kmpJsonData.keyboards.map(e => e.webOskFonts ?? []));

let commonScript = null;

for(const bcp47 of Object.keys(keyboard_info.languages)) {
const language = keyboard_info.languages[bcp47];

Expand Down Expand Up @@ -572,6 +574,14 @@ export class KeyboardInfoCompiler implements KeymanCompiler {
` (${language.regionName})` :
''
);

if(commonScript === null) {
commonScript = tag?.script ?? undefined;
} else {
if(tag?.script !== commonScript) {
this.callbacks.reportMessage(KeyboardInfoCompilerMessages.Hint_ScriptDoesNotMatch({commonScript, bcp47, script: tag?.script}))
}
}
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015-2022 SIL International

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
khmer_angkor.js -text
Loading

0 comments on commit f3191b9

Please sign in to comment.