-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workflow): Add Python setup and precompile step to NSIS workflow
feat(installer): Automate language file inclusion with auto_precompile.py fix(language): Add UTF-8 BOM to zh_TW.nsh docs(gitignore): Add languages.nsh to .gitignore
- Loading branch information
Showing
5 changed files
with
90 additions
and
11 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
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 @@ | ||
languages.nsh |
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,79 @@ | ||
import re | ||
# output to languages.nsh | ||
# first, list languages/ | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
|
||
ALL_LOCALES = [ | ||
"Serbian", "Vietnamese", "Asturian", "Greek", "Turkish", "Georgian", | ||
"Norwegian", "Macedonian", "Hebrew", "Belarusian", "PortugueseBR", "Welsh", | ||
"Korean", "Japanese", "Estonian", "Afrikaans", "ScotsGaelic", "Czech", | ||
"Esperanto", "Kurdish", "Lithuanian", "Latvian", "Pashto", "Bosnian", | ||
"Croatian", "French", "Farsi", "Hindi", "Hungarian", "SerbianLatin", | ||
"Bulgarian", "SimpChinese", "Indonesian", "Slovenian", "Albanian", | ||
"Arabic", "Armenian", "Ukrainian", "German", "Catalan", "Malay", "Swedish", | ||
"Thai", "Portuguese", "Icelandic", "Luxembourgish", "Irish", "TradChinese", | ||
"Uzbek", "SpanishInternational", "Basque", "Polish", "NorwegianNynorsk", | ||
"Tatar", "Russian", "Finnish", "Breton", "Galician", "Mongolian", "Dutch", | ||
"Spanish", "Romanian", "English", "Italian", "Danish", "Slovak", "Corsican" | ||
] | ||
|
||
|
||
def auto_match_locale(name: str) -> str: | ||
if name.startswith("LANG_"): | ||
name = name[5:] | ||
|
||
for locale in ALL_LOCALES: | ||
if locale.lower() == name.lower(): | ||
return locale | ||
|
||
raise ValueError(f"Could not match locale {name}") | ||
|
||
|
||
def find_locale_identifier(path: Path) -> str: | ||
# iterate lines, find \${.+} | ||
with open(path, "r", encoding="utf-8") as f: | ||
for line in f: | ||
match = re.search(r"\${(.+?)}", line) | ||
if match: | ||
return match.group(1) | ||
raise ValueError(f"Could not find locale identifier in {path}") | ||
|
||
|
||
def auto_fix_utf8bom(path: Path): | ||
# if not bom, add it | ||
with open(path, "rb") as f: | ||
if f.read(3) != b'\xef\xbb\xbf': | ||
with open(path, "r+", encoding="utf-8") as f2: | ||
content = f2.read() | ||
f2.seek(0) | ||
f2.write('\ufeff' + content) | ||
f2.truncate() | ||
|
||
|
||
@dataclass | ||
class Locale: | ||
name: str | ||
path: Path | ||
|
||
|
||
locales: list[Locale] = [] | ||
lang_dir = Path("languages") | ||
|
||
for file in lang_dir.glob("*.nsh"): | ||
auto_fix_utf8bom(file) | ||
locales.append(Locale(file.stem, file)) | ||
|
||
with open("languages.nsh", "w", encoding="utf-8") as f: | ||
f.write("; DON'T EDIT!\n") | ||
f.write("; This file is automatically generated by auto_precompile.py\n") | ||
for locale in locales: | ||
locale_identifier = find_locale_identifier(locale.path) | ||
locale_name = auto_match_locale(locale_identifier) | ||
|
||
f.write( | ||
f'LoadLanguageFile "${{NSISDIR}}\\Contrib\\Language files\\{locale_name}.nlf"\n' | ||
) | ||
|
||
for locale in locales: | ||
f.write(f"!include \"{locale.path.as_posix().replace('/', '\\')}\"\n") |
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
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