-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const MUI = require('@nsis/mui-language-strings'); | ||
const NLF = require('@nsis/nlf'); | ||
const fs = require('fs'); | ||
const globby = require('globby'); | ||
const rimraf = require('rimraf'); | ||
const sortKeys = require('sort-keys'); | ||
const { basename, extname, join } = require('path'); | ||
const { nsisDir } = require('makensis'); | ||
const { promisify } = require('util'); | ||
|
||
const readFile = promisify(fs.readFile); | ||
const writeFile = promisify(fs.writeFile); | ||
const rimrafAsync = promisify(rimraf); | ||
const mkdir = promisify(fs.mkdir); | ||
|
||
(async () => { | ||
try { | ||
await rimrafAsync('./data'); | ||
await mkdir('./data'); | ||
await mkdir('./data/languages'); | ||
} catch(e) { | ||
throw new Error(e); | ||
} | ||
|
||
const output = {}; | ||
const languageDir = join(await nsisDir(), 'Contrib', 'Language files'); | ||
let languageFiles = await globby(`${languageDir}/*.nlf`); | ||
|
||
languageFiles = languageFiles.sort(); | ||
|
||
for (languageFile of languageFiles) { | ||
const langExtname = extname(languageFile); | ||
const langBasename = basename(languageFile, langExtname); | ||
|
||
const nlfFile = await readFile(`${languageDir}/${langBasename}.nlf`, 'utf8'); | ||
const nlfContent = NLF.parse(nlfFile); | ||
|
||
|
||
const nshFile = await readFile(`${languageDir}/${langBasename}.nsh`, 'utf8'); | ||
const nshContent = await MUI.parse(nshFile, { looseQuotes: true }); | ||
|
||
output[nshContent.file] = { | ||
id: nlfContent.id, | ||
code_page: nlfContent.codepage, | ||
rtl: nlfContent.rtl, | ||
english: nshContent.english, | ||
native: nshContent.native, | ||
native_ascii: nshContent.nativeASCII, | ||
}; | ||
|
||
try { | ||
await writeFile(`data/languages/${nshContent.file}.json`, JSON.stringify(nlfContent, null, 2), 'utf8'); | ||
} catch (e) { | ||
throw new Error(e); | ||
} | ||
} | ||
|
||
try { | ||
await writeFile(`data/languages/${nshContent.file}.json`, JSON.stringify(nlfContent, null, 2), 'utf8'); | ||
} catch (e) { | ||
await writeFile('data/meta.json', JSON.stringify(output, null, 2), 'utf8'); | ||
} | ||
})(); |