If you need to inject some custom piece of information, you can preprocess .isl files like this:
#define Token1 "value1"
#define Token2 "value2"
#define PreprocessLanguage(Path) \
Local[0] = GetEnv("TEMP") + "\" + ExtractFileName(Path), \
Local[1] = \
"-ExecutionPolicy Bypass -Command """ + \
"$contents = Get-Content '" + CompilerPath + "\" + Path + "'; " + \
"$contents = $contents -replace '[token1]', '" + Token1 +"'; " + \
"$contents = $contents -replace '[token2]', '" + Token2 +"'; " + \
"Set-Content -Path '" + Local[0] + "' -Value $contents;" + \
"""", \
Exec("powershell.exe", Local[1], , , SW_HIDE), \
Local[0]
[Languages]
Name: "en"; MessagesFile: {#PreprocessLanguage("Default.isl")}
Name: "nl"; MessagesFile: {#PreprocessLanguage("Languages\Dutch.isl")}
The above example replaces all occurrences of [token1]
and [token2]
with values of Token1
and Token2
preprocessor variables.
Theoretically, it is possible to implement this fully in the preprocessor without invoking PowerShell, with use of FileOpen
, FileRead
, StringChange
, and SaveStringToFile
functions.
#define Token1 "value1"
#define Token2 "value2"
#define PreprocessLanguageLines(Handle, OutPath) \
!FileEof(Handle) ? \
Local[0] = FileRead(Handle), \
Local[0] = StringChange(Local[0], "[token1]", Token1), \
Local[0] = StringChange(Local[0], "[token1]", Token2), \
SaveStringToFile(OutPath, Local[0] + NewLine, 1, 0), \
PreprocessLanguageLines(Handle, OutPath) \
: ""
#define PreprocessLanguage(Path) \
Local[0] = GetEnv("TEMP") + "\" + ExtractFileName(Path), \
SaveStringToFile(Local[0], "", 0, 0), \
Local[1] = FileOpen(CompilerPath + "\" + Path), \
PreprocessLanguageLines(Local[1], Local[0]), \
FileClose(Local[1]), \
Local[0]
But with the straightforward functional approach, you will hit recursion limit of the preprocessor as the language files have too many lines. It can get solved by reading multiple lines per recursion, but that's a hack.
With use of the #sub
, it should work. But it's a mess.