Languages and LanguageIds

From ISXKB

Revision as of 14:39, 2 January 2011 by Ath (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

By support request in the Inno Setup Newsgroups, I created a script to link Language names with their Language Id's. I polished the code a little, and publish it here for all to benefit.

The complete project can be downloaded from this Blog post

The to be included languageidmacro.iss contains this code:

// Here are the languageIdAndMessagefile, languageIdAndMessagefileDefault and languageIdAndMessagefileUnofficial macros, 
// they deliver a name like ln<languageId> such as ln1043 for Dutch, or ln1031 for German, taken from the original LanguageId parameter from the .isl file, located in {pf}\Inno Setup 5\Languages, {pf}\Inno Setup 5 and {pf}\Inno Setup 5\Languages\Unofficial 
// and also sets the (required) MessagesFile: parameter to that .isl file
// usage: Name: {#languageIdAndMessagefile('Dutch')} <additional parameters>
// usage: Name: {#languageIdAndMessagefileDefault('Default')} <additional parameters>
// usage: Name: {#languageIdAndMessagefileUnofficial('Chinese (Simpl)')} <additional parameters>
// Only names of existing Inno Setup language-files can be used, of course, and Inno Setup should be installed in its default location
// macro languageIdAndMessagefileDefault currently only accepts 'Default' as a valid parameter
// There's also a supportfunction in [Code] called getNumericOnly() that strips any non-numeric characters from a string, so it can be easily stored in the [Registry] section 
#define languageIdAndMessagefile(str L) "ln"+Str(Int(ReadIni(GetEnv('ProgramFiles') + '\Inno Setup 5\Languages\' + L + '.isl','LangOptions','LanguageID','-1'))) + "; MessagesFile: compiler:Languages\" + L + ".isl" 
#define languageIdAndMessagefileDefault(str L) "ln"+Str(Int(ReadIni(GetEnv('ProgramFiles') + '\Inno Setup 5\' + L + '.isl','LangOptions','LanguageID','-1'))) + "; MessagesFile: compiler:" + L + ".isl" 
#define languageIdAndMessagefileUnofficial(str L) "ln"+Str(Int(ReadIni(GetEnv('ProgramFiles') + '\Inno Setup 5\Languages\Unofficial\' + L + '.isl','LangOptions','LanguageID','-1'))) + "; MessagesFile: compiler:Languages\Unofficial\" + L + ".isl"

[Code]

// Remove all non-numeric characters from a string
function getNumericOnly(nam : String) : String;
var i : Integer;
    s : String;
Begin
    s := nam;
    For i := 1 to Length(s) do
    Begin
        if (Copy(s,1,1) < '0') or (Copy(s,1,1) > '9') then
            s := Copy(s,2,Length(s) - 1);
    End;
    Result := s;
End;

The demo-script languageId.iss looks like this:

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "SetupLanguageIdTest"
#define MyAppVersion "2.0"
#define MyAppVerName MyAppName + " " + MyAppVersion
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "MyProg.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppID={{0CCAAD43-4A2F-46BB-9A44-0922370B9A2A}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setupLanguageIdTest
Compression=lzma/Max
SolidCompression=true

#include "languageidmacro.iss"

[Languages]
Name: {#languageIdAndMessagefileDefault('Default')}
Name: {#languageIdAndMessagefile('Dutch')}
Name: {#languageIdAndMessagefile('German')}
Name: {#languageIdAndMessagefile('French')}
Name: {#languageIdAndMessagefileUnofficial('Chinese (Simpl)')}

[Tasks]
Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}; Flags: unchecked; 

[Files]
Source: {#GetEnv('ProgramFiles')}\Inno Setup 5\Examples\{#MyAppExeName}; DestDir: {app}; Flags: ignoreversion;
Source: readme-english.txt; DestDir: {app}; DestName: readme.txt; Languages: ln1033;
Source: readme-dutch.txt; DestDir: {app}; DestName: readme.txt; Languages: ln1043
Source: readme-german.txt; DestDir: {app}; DestName: readme.txt; Languages: ln1031
Source: readme-french.txt; DestDir: {app}; DestName: readme.txt; Languages: ln1036
Source: readme-chinese-simpl.txt; DestDir: {app}; DestName: readme.txt; Languages: ln2052
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Registry]
Root: HKCU; SubKey: {#MyAppPublisher}\{#MyAppName}; ValueType: dword; ValueName: languageId; ValueData: {code:getNumericOnly|{language})}; Flags: UninsDeleteValue; 
Root: HKCU; SubKey: {#MyAppPublisher}\{#MyAppName}; ValueType: string; ValueName: languageIdCode; ValueData: {code:getNumericOnly|{language})}; Flags: UninsDeleteValue; 

[Icons]
Name: {group}\{#MyAppName}; Filename: {app}\{#MyAppExeName}; 
Name: {commondesktop}\{#MyAppName}; Filename: {app}\{#MyAppExeName}; Tasks: desktopicon; 

[Run]
Filename: {app}\{#MyAppExeName}; Description: {cm:LaunchProgram,{#StringChange(MyAppName, "&", "&&")}}; Flags: nowait postinstall skipifsilent; 

#expr SaveToFile(AddBackslash(SourcePath) + "Preprocessed"+MyAppVerName+".iss")

Links and References

Personal tools
Ads: