| 1 |
/* |
| 2 |
|
| 3 |
LangFile.nsh |
| 4 |
|
| 5 |
Header file to create language files that can be |
| 6 |
included with a single command. |
| 7 |
|
| 8 |
Copyright 2008-2026 Joost Verburg, Anders Kjersem |
| 9 |
|
| 10 |
* Either LANGFILE_INCLUDE or LANGFILE_INCLUDE_WITHDEFAULT |
| 11 |
can be called from the script to include a language file. |
| 12 |
|
| 13 |
- LANGFILE_INCLUDE takes the language file name as parameter. |
| 14 |
- LANGFILE_INCLUDE_WITHDEFAULT takes as additional second |
| 15 |
parameter, the default language file to load missing strings from. |
| 16 |
|
| 17 |
* Language strings in the language file have the format: |
| 18 |
${LangFileString} LANGSTRING_NAME "Text" |
| 19 |
|
| 20 |
* There are two types of language header files: |
| 21 |
|
| 22 |
- NSIS multi-lang support; these must start with the LANGFILE macro and |
| 23 |
provide strings for features like MUI and MultiUser. If you are adding |
| 24 |
support for a new language to NSIS you should make a copy of English.nsh |
| 25 |
and translate this .nsh along with the .nlf. |
| 26 |
- Custom installer strings; these must start with the LANGFILE_EXT macro and |
| 27 |
contain translated versions of |
| 28 |
custom strings used in a particular installer. |
| 29 |
This is useful if you want to put the translations for each language in |
| 30 |
their own separate file. |
| 31 |
|
| 32 |
* Example: |
| 33 |
|
| 34 |
; Setup.nsi |
| 35 |
!include "MUI.nsh" |
| 36 |
!insertmacro MUI_PAGE_INSTFILES |
| 37 |
!insertmacro MUI_LANGUAGE "Danish" |
| 38 |
!insertmacro LANGFILE_INCLUDE "DanishExtra.nsh" |
| 39 |
!insertmacro MUI_LANGUAGE "Swedish" |
| 40 |
!insertmacro LANGFILE_INCLUDE "SwedishExtra.nsh" |
| 41 |
Section |
| 42 |
MessageBox MB_OK "$(myCustomString)" |
| 43 |
SectionEnd |
| 44 |
|
| 45 |
; SwedishExtra.nsh |
| 46 |
!insertmacro LANGFILE_EXT Swedish |
| 47 |
${LangFileString} myCustomString "Bork bork" |
| 48 |
|
| 49 |
*/ |
| 50 |
|
| 51 |
!ifndef LANGFILE_INCLUDED |
| 52 |
!define LANGFILE_INCLUDED |
| 53 |
|
| 54 |
!macro LANGFILE_INCLUDE FILENAME |
| 55 |
|
| 56 |
;Called from script: include a language file |
| 57 |
|
| 58 |
!ifdef LangFileString |
| 59 |
!undef LangFileString |
| 60 |
!endif |
| 61 |
|
| 62 |
!define LangFileString "!insertmacro LANGFILE_SETSTRING" |
| 63 |
|
| 64 |
!define LANGFILE_SETNAMES |
| 65 |
!include "${FILENAME}" |
| 66 |
!undef LANGFILE_SETNAMES |
| 67 |
|
| 68 |
;Create language strings |
| 69 |
!define /redef LangFileString "!insertmacro LANGFILE_LANGSTRING" |
| 70 |
!include "${FILENAME}" |
| 71 |
|
| 72 |
!macroend |
| 73 |
|
| 74 |
!macro LANGFILE_INCLUDE_WITHDEFAULT FILENAME FILENAME_DEFAULT |
| 75 |
|
| 76 |
;Called from script: include a language file |
| 77 |
;Obtains missing strings from a default file |
| 78 |
|
| 79 |
!ifdef LangFileString |
| 80 |
!undef LangFileString |
| 81 |
!endif |
| 82 |
|
| 83 |
!define LangFileString "!insertmacro LANGFILE_SETSTRING" |
| 84 |
|
| 85 |
!define LANGFILE_SETNAMES |
| 86 |
!include "${FILENAME}" |
| 87 |
!undef LANGFILE_SETNAMES |
| 88 |
|
| 89 |
;Include default language for missing strings |
| 90 |
!define LANGFILE_PRIV_INCLUDEISFALLBACK "${FILENAME_DEFAULT}" |
| 91 |
!include "${FILENAME_DEFAULT}" |
| 92 |
!undef LANGFILE_PRIV_INCLUDEISFALLBACK |
| 93 |
|
| 94 |
;Create language strings |
| 95 |
!define /redef LangFileString "!insertmacro LANGFILE_LANGSTRING" |
| 96 |
!include "${FILENAME_DEFAULT}" |
| 97 |
|
| 98 |
!macroend |
| 99 |
|
| 100 |
!macro LANGFILE NLFID ENGNAME NATIVENAME NATIVEASCIINAME |
| 101 |
|
| 102 |
;Start of standard NSIS language file |
| 103 |
|
| 104 |
; NLFID: Must match the name of the .nlf file |
| 105 |
; ENGNAME: English name of language, "=" if it is the same as NLFID |
| 106 |
; NATIVENAME: Native name of language. (In Unicode) |
| 107 |
; NATIVEASCIINAME: Native name of language using only ASCII, "=" if it is the same as NATIVENAME |
| 108 |
|
| 109 |
; Example: LANGFILE "Swedish" = "Svenska" = (This is the same as LANGFILE "Swedish" "Swedish" "Svenska" "Svenska") |
| 110 |
; For more examples, see French.nsh, Greek.nsh and PortugueseBR.nsh |
| 111 |
|
| 112 |
!ifdef LANGFILE_SETNAMES |
| 113 |
|
| 114 |
!ifdef LANGFILE_IDNAME |
| 115 |
!undef LANGFILE_IDNAME |
| 116 |
!endif |
| 117 |
|
| 118 |
!define LANGFILE_IDNAME "${NLFID}" |
| 119 |
|
| 120 |
; ModernUI or the .nsi can change LANGFILE_LANGDLL_FMT if desired |
| 121 |
!ifndef LANGFILE_LANGDLL_FMT |
| 122 |
!ifndef NSIS_UNICODE |
| 123 |
!define LANGFILE_LANGDLL_FMT "%ENGNAME% / %NATIVEASCIINAME%" |
| 124 |
!endif |
| 125 |
!define /ifndef LANGFILE_LANGDLL_FMT "%NATIVENAME%" |
| 126 |
!endif |
| 127 |
|
| 128 |
!ifndef "LANGFILE_${NLFID}_NAME" |
| 129 |
!if "${ENGNAME}" == "=" |
| 130 |
!define /redef ENGNAME "${NLFID}" |
| 131 |
!endif |
| 132 |
!if "${NATIVEASCIINAME}" == "=" |
| 133 |
!define /redef NATIVEASCIINAME "${NATIVENAME}" |
| 134 |
!endif |
| 135 |
|
| 136 |
!define "LANGFILE_${NLFID}_ENGLISHNAME" "${ENGNAME}" |
| 137 |
!ifdef NSIS_UNICODE |
| 138 |
!define "LANGFILE_${NLFID}_NAME" "${NATIVENAME}" |
| 139 |
!else |
| 140 |
!define "LANGFILE_${NLFID}_NAME" "${NATIVEASCIINAME}" |
| 141 |
!endif |
| 142 |
|
| 143 |
!searchreplace LANGFILE_${NLFID}_LANGDLL "${LANGFILE_LANGDLL_FMT}" %NATIVEASCIINAME% "${NATIVEASCIINAME}" |
| 144 |
!searchreplace LANGFILE_${NLFID}_LANGDLL "${LANGFILE_${NLFID}_LANGDLL}" %NATIVENAME% "${NATIVENAME}" |
| 145 |
!searchreplace LANGFILE_${NLFID}_LANGDLL "${LANGFILE_${NLFID}_LANGDLL}" %ENGNAME% "${ENGNAME}" |
| 146 |
|
| 147 |
!endif |
| 148 |
|
| 149 |
!endif |
| 150 |
|
| 151 |
!macroend |
| 152 |
|
| 153 |
!macro LANGFILE_EXT IDNAME |
| 154 |
|
| 155 |
;Start of installer language file |
| 156 |
|
| 157 |
!ifdef LANGFILE_SETNAMES |
| 158 |
|
| 159 |
!ifdef LANGFILE_IDNAME |
| 160 |
!undef LANGFILE_IDNAME |
| 161 |
!endif |
| 162 |
|
| 163 |
!define LANGFILE_IDNAME "${IDNAME}" |
| 164 |
|
| 165 |
!endif |
| 166 |
|
| 167 |
!macroend |
| 168 |
|
| 169 |
!macro LANGFILE_SETSTRING NAME VALUE |
| 170 |
|
| 171 |
;Set define with translated string |
| 172 |
|
| 173 |
!ifndef ${NAME} |
| 174 |
!define "${NAME}" "${VALUE}" |
| 175 |
!ifdef LANGFILE_PRIV_INCLUDEISFALLBACK |
| 176 |
!warning 'LangString "${NAME}" for language ${LANGFILE_IDNAME} is missing, using fallback from "${LANGFILE_PRIV_INCLUDEISFALLBACK}"' |
| 177 |
!endif |
| 178 |
!endif |
| 179 |
|
| 180 |
!macroend |
| 181 |
|
| 182 |
!macro LANGFILE_LANGSTRING NAME DUMMY |
| 183 |
|
| 184 |
;Create a language string from a define and undefine |
| 185 |
|
| 186 |
LangString "${NAME}" "${LANG_${LANGFILE_IDNAME}}" "${${NAME}}" |
| 187 |
!undef "${NAME}" |
| 188 |
|
| 189 |
!macroend |
| 190 |
|
| 191 |
!endif |