Creating language files and integrating with MUI: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Fixed the solution with iconv to convert utf8 to windows locale.)
Line 8: Line 8:
== Issue ==
== Issue ==
As you know, you'll need at some time to display a message like "This application is old" but
As you know, you'll need at some time to display a message like "This application is old" but
the NSIS can't do the translation in other languages so someone else well do the translation
the NSIS can't do the translation in other languages so someone else will do the translation
for him. But the translator is not a programmer! So the only solution is to include in the script
for him. But the translator is not a programmer! So the only solution is to include in the script
only macros like LANG_MSG_APP_OLD and create language files like:
only macros like LANG_MSG_APP_OLD and create language files like:

Revision as of 20:50, 12 August 2009

Author: sunjammer (talk, contrib)


Introduction

Taken from a forum posting by rainwater in response to the following question by sealite:----I have some experience in creating multilanguage applications. The best solution, from my experience, is to create language files but it seams that NSIS does not have support for this. (I'm not reffering to standard language files).

Issue

As you know, you'll need at some time to display a message like "This application is old" but the NSIS can't do the translation in other languages so someone else will do the translation for him. But the translator is not a programmer! So the only solution is to include in the script only macros like LANG_MSG_APP_OLD and create language files like:

English.lng LANG_MSG_APP_OLD "This application is old."

Does anyone know how can we do this?

Solution

Rainwater suggested the following solution:

First create these macros in your installer:

!macro LANG_LOAD LANGLOAD
  !insertmacro MUI_LANGUAGE "${LANGLOAD}"
  !verbose off
  !include "locallang\${LANGLOAD}.nsh"
  !verbose on
  BrandingText "$(STRING_BRANDING)" ; example usage
  !undef LANG
!macroend
 
!macro LANG_STRING NAME VALUE
  LangString "${NAME}" "${LANG_${LANG}}" "${VALUE}"
!macroend
 
!macro LANG_UNSTRING NAME VALUE
  !insertmacro LANG_STRING "un.${NAME}" "${VALUE}"
!macroend

Then make your language files like:

!define LANG "ENGLISH" ; Must be the lang name define my NSIS
!insertmacro LANG_STRING STRING_BRANDING "My Setup"
!insertmacro LANG_STRING STRING_APP_OLD "This application is old."

If you create language files (ie "English.nsh") in the directory ("locallang" in this example), then in the head of your installer, you just say:

!insertmacro LANG_LOAD "English"

and it will load the MUI, NSIS, and your local language files.

Solution improved

Here is a perl tool that is based on the above solution but goes further to make the translations available in regular po files.

It is very easy to integrate it in the GNU toolchain. It uses a .desktop file as a holder for the translations. The intltool-merge tool knows how to insert translations from a po file to a .desktop file. If you don't use the intltools, you can also easily create and maintain the pseudo desktop file manually.

InstallerIsRunning=The installer is already running.
InstallerIsRunning[fr]=Le programme d'installation est déjà en cours d'exécution.
GcomprisLicenseButton=Next >
GcomprisLicenseButton[fr]=Suivant >

Once you have prepared you pseudo .desktop file, you have to add the line @INSERT_TRANSLATIONS@ in your nsis source file. Put it before you starting using your translations.

Last step is to run the script create_nsis_translations.pl. It will create all the translations file for you and update your nsis source file.

As a summary, with this tool adding a new string is done by adding a line in the pseudo .desktop file. Then the translations are done through the regular .po files.

Here is an overview of the translation process:

nsis.desktop.in  -> intltool-extract -> .po files
.po files are translated by the translation team of your project.
nsis.desktop.in + .po files -> intltool-merge -> nsis.desktop

Add the line @INSERT_TRANSLATIONS@ to you project.nsis source installer file.
Use the translations string in you source installer file.

Now you can run:
./create_nsis_translations.pl nsis.desktop project.nsis tmp_directory
And your installer is ready to be compiled with makensis.