Skip to content

Commit

Permalink
fix: Correct Windows specific issues : utf16, BOM
Browse files Browse the repository at this point in the history
  • Loading branch information
narze committed Jul 7, 2021
1 parent bc673cb commit c00f10e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions input/Manoonchai.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"license": "MIT",
"os": {
"windows": {
"installerName": "ThaiMnc",
"company": "Manoonchai",
"localeId": "0000041e"
}
Expand Down
17 changes: 9 additions & 8 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export async function generateKlc(
}

const lines = [
`KBD\t${layout.name}\t"${layout.language} ${layout.name} v${layout.version}"`,
`KBD\t${layout.os.windows.installerName}\t"${layout.language} ${layout.name} v${layout.version}"`,
`COPYRIGHT\t"MIT"`,
`COMPANY\t"${layout.os.windows.company}"`,
`LOCALENAME\t"${klcLocales[layout.language]}"`,
Expand All @@ -132,12 +132,13 @@ export async function generateKlc(

fs.writeFileSync(
"./output/test.klc",
[
lines.join("\r\n\r\n"),
shiftStateLines.join("\r\n"),
layoutLines.join("\r\n"),
"ENDKBD",
].join("\r\n\r\n"),
"\ufeff" +
[
lines.join("\r\n\r\n"),
shiftStateLines.join("\r\n"),
layoutLines.join("\r\n"),
"ENDKBD",
].join("\r\n\r\n"),
{
encoding: "utf16le",
}
Expand Down Expand Up @@ -434,5 +435,5 @@ export class Layout {
}

interface OSAttributes {
windows: { company: string; localeId: string }
windows: { company: string; localeId: string; installerName: string }
}
Binary file modified output/test.klc
Binary file not shown.
2 changes: 1 addition & 1 deletion test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ describe("generateKlc", () => {
.filter(Boolean)

// Assert file headers
expect(lines[0]).toEqual(`KBD\tManoonchai\t"Thai Manoonchai v1.0"`)
expect(lines[0]).toEqual(`\ufeffKBD\tThaiMnc\t"Thai Manoonchai v1.0"`)
expect(lines[1]).toEqual(`COPYRIGHT\t"MIT"`)
expect(lines[2]).toEqual(`COMPANY\t"Manoonchai"`)
expect(lines[3]).toEqual(`LOCALENAME\t"th-TH"`)
Expand Down

0 comments on commit c00f10e

Please sign in to comment.