我可以在Inno Setup中使用带有预处理器指令的消息使用.isl文件吗? [英] Can I use .isl files for the messages with preprocessor directives in Inno Setup?
问题描述
我已经定义了一个变量:
I have defined a variable:
#define AppVersion "5.0"
Default.isl
文件中有很多标准消息,这些消息在我脚本的[Messages]部分中被覆盖.这是一个示例:
There's a lot of standard messages from the Default.isl
file overridden in the `[Messages] section of my script. Here is an example:
[Messages]
en.WelcomeLabel1=Welcome to [name] {#AppVersion} Setup program. This program will install [name] {#AppVersion} on your computer.
en.SelectDirDesc=Where should [name] {#AppVersion} be installed?
en.SelectDirLabel3=Setup will install [name] {#AppVersion} into the following folder.
我不喜欢所有这些消息都驻留在我的脚本中的事实,我想将它们传输到相应的.isl
文件中.问题是我不能在.isl
文件中使用{#AppVersion}
,因为它被解释为简单文本.考虑到其中包含{#AppVersion}
的消息,有没有办法覆盖这些文件中的消息?
I don't like the fact that all those messages reside in my script and I would like to transfer them to the corresponding .isl
file. The problem is that I can't use {#AppVersion}
inside the .isl
file as it is interpreted as simple text. Is there a way to override those messages in the .isl
file taking into account that they contain {#AppVersion}
?
推荐答案
-
对于这种特定情况,应用程序名称和版本,有一个简单的解决方案:
如何在Inno Setup中用不同的语言重写WelcomePage的预定义消息?For this specific case, the application name and version, there's a simple solution:
How can I rewrite predefined messages for the WelcomePage in different languages in Inno Setup?如果您需要注入少量其他信息,请参见下文.
If you need to inject a small amount of other information, see below.
有关最终解决方案的信息,请参见 Inno Setup语言文件(isl)中的完整预处理器支持
For ultimate solution, see Full preprocessor support in Inno Setup language files (isl)
请注意,这一切对于自定义消息来说都是多余的.对于这些,有更简单的解决方案:如何使用带有预处理程序常量的自定义消息使用语言文件?
Note that this all would be an overkill for custom messages. For those, there are easier solutions: How can I use language files with custom messages with preprocessor constants?
如果您需要注入一些自定义信息,则可以预处理.isl文件,如下所示:
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")}
上面的示例用
Token1
和Token2
预处理器变量的值替换了所有出现的[token1]
和[token2]
.The above example replaces all occurrences of
[token1]
and[token2]
with values ofToken1
andToken2
preprocessor variables.从理论上讲,可以使用
FileRead
,StringChange
和Theoretically, it is possible to implement this fully in the preprocessor without invoking PowerShell, with use of
FileOpen
,FileRead
,StringChange
, andSaveStringToFile
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]
但是使用直接的函数方法,由于语言文件的行太多,您将达到预处理器的递归限制.可以通过每次递归读取多行来解决,但这是一个hack.
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.
使用
#sub
,它应该可以工作.但这是一团糟.With use the
#sub
, it should work. But it's a mess.这篇关于我可以在Inno Setup中使用带有预处理器指令的消息使用.isl文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!