本文介绍了Inno Setup语言文件(ISL)中的全面预处理程序支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在安装程序中使用三种语言,此刻我正在执行脚本中的所有替代操作.这是一个示例:

I use three languages with my installer and at the moment I'm doing all the overrides inside my script. Here's an example:

[Messages]
en.SetupWindowTitle=Setup - %1 {#AppVersion}
ru.SetupWindowTitle=Установка - %1 {#AppVersion}
ua.SetupWindowTitle=Встановлення - %1 {#AppVersion}
en.SetupAppRunningError=Setup has detected that {#SetupSetting('VersionInfoOriginalFileName')} is currently running.%n%nPlease close all instances of it now, then click OK to continue, or Cancel to exit.
ru.SetupAppRunningError=Обнаружен запущенный экземпляр {#SetupSetting('VersionInfoOriginalFileName')}.%n%nПожалуйста, закройте все экземпляры приложения, затем нажмите «OK», чтобы продолжить, или «Отмена», чтобы выйти.
ua.SetupAppRunningError=Виявлено запущений екземпляр {#SetupSetting('VersionInfoOriginalFileName')}.%n%nБудь ласка, закрийте всі копії програми та натисніть «OK» для продовження, або «Скасувати» для виходу.
[CustomMessages]
en.AppRunningError=Setup has detected that {#AppExeName} is currently running.%n%nPlease, close the {#AppExeName} application, then click «OK» to continue or «Cancel» to exit. 
ru.AppRunningError=В памяти находится {#AppExeName}.%n%nЗавершите работу {#AppExeName} и нажмите «OK», чтобы продолжить, или «Отмена», чтобы выйти. 
ua.AppRunningError=В пам'яті знаходиться {#AppExeName}.%n%nЗавершіть роботу {#AppExeName} та натисніть «OK» для продовження, або «Скасувати» для виходу. 

我在脚本中覆盖了许多消息.考虑到已使用预处理器指令{#...},我想知道将所有这些替代传输到.isl文件中的最有效方法是什么.我可以使用FmtMessage(...),但这意味着我必须在每封邮件中都包含FmtMessage(...).

I have lots of messages overridden inside the script. I would like to know what is the most effective way to transfer all those overrides into the .isl files taking into account that I have preprocessor directives {#...} used. I could use FmtMessage(...), but that means that I would have to include FmtMessage(...) for every single message.

推荐答案

请先检查一些侵入性较小的解决方案是否不能满足您的需求:
我可以在Inno Setup中使用带有预处理器指令的消息使用.isl文件吗?

First check, if some of the less invasive solutions might not cover your needs:
Can I use .isl files for the messages with preprocessor directives in Inno Setup?

如果要在.isl文件中完全支持预处理器,可以将它们传递给实际的Inno Setup预处理器:

If you want a full preprocessor support in .isl files, you can pass them through the actual Inno Setup preprocessor:

  • 具有所有变量定义(和一些支持代码)的因素输出通用包含文件(defines.iss):

// Definitions
#define AppVersion "1.2.3"
// more definitions ...

// Support code
#define PreprocessedTranslationFile GetEnv("TEMP") + "\lang.isl"
#define SavePreprocessedTranslation() SaveToFile(PreprocessedTranslationFile)

  • 在.iss和所有.isl的开头包含该文件:

  • Include that file at the beginning of your .iss and all your .isl's:

    #include "defines.iss"
    

  • 在所有.isl文件的末尾致电SavePreprocessedTranslation:

    #expr SavePreprocessedTranslation()
    

  • 对修改后的.isl文件进行预处理程序调用iscc.当然,它将失败,因为.isl不是有效的.iss,但是iscc的预处理器部分应完成并创建经过预处理的.isl文件.

  • Make the preprocessor call iscc on the modified .isl files. It will of course fail, as the .isl is not a valid .iss, but the preprocessor part of iscc should complete and create the preprocessed .isl file.

    #define DebugPreprocessLanguage 0
    
    #define PreprocessLanguage(Path) \
      Local[0] = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe", \
      DeleteFileNow(PreprocessedTranslationFile), \
      Local[1] = DebugPreprocessLanguage ? SourcePath + "\islpreprocess.log" : "nul", \
      Local[2] = "/C """"" + Local[0] + """ """ + Path + """ " + \
                 ">> " + Local[1] + " 2>&1 """, \
      Exec("cmd", Local[2], SourcePath, , SW_HIDE), \
      (FileExists(PreprocessedTranslationFile) || \
        Error(Path + " failed to preprocess")), \
      Local[3] = GetEnv("TEMP") + "\" + ExtractFileName(Path), \
      CopyFile(PreprocessedTranslationFile, Local[3]), \
      DeleteFileNow(PreprocessedTranslationFile), \
      Local[3]
    

  • 并使用[Languages]部分中经过预处理的.isl文件.

  • And use the preprocessed .isl files in the [Languages] section.

    [Languages]
    Name: "en"; MessagesFile: {#PreprocessLanguage("Default.isl")}
    Name: "nl"; MessagesFile: {#PreprocessLanguage("Dutch.isl")}
    

  • 如果遇到问题,请将DebugPreprocessLanguage设置为1以查看.isl预处理程序输出.

    If you have problems, set DebugPreprocessLanguage to 1 to see the .isl preprocessor output.

    您甚至可以通过在调用iscc之前使预处理器将#include "defines.iss"#expr SavePreprocessedTranslation()自动添加到.isl中来改善过程.

    You can even improve the process by making the preprocessor add the #include "defines.iss" and #expr SavePreprocessedTranslation() automatically to the .isl's before calling the iscc.

    这篇关于Inno Setup语言文件(ISL)中的全面预处理程序支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    10-19 17:35