如何不翻译LangString可以使用默认语言?

时间:2013-02-06 11:45:44

标签: nsis

我的安装必须适用于多种语言,但我无法完全翻译所有消息。如果邮件尚未翻译,我如何使用默认语言?

例如:

!insertmacro MUI_LANGUAGE "English" 
!insertmacro MUI_LANGUAGE "Spanish" 
!insertmacro MUI_LANGUAGE "TradChinese" 
!insertmacro MUI_LANGUAGE "SimpChinese"


LangString EMBEDED ${LANG_ENGLISH} "Installation single user" 
LangString EMBEDED ${LANG_SPANISH} "Instalación usuario único"

我想如果安装在TradChinese中,EMBEDED字符串将使用英文翻译,因为没有EMBEDED中文。

2 个答案:

答案 0 :(得分:0)

我在NSIS论坛上问了同样的问题没有成功。最后,我创建了一个小的Perl脚本,它解析我的NSIS代码并检测包含的语言和所有Langstrings,检测缺失的翻译,并创建初始化为默认语言的Langstrings:

#!/usr/bin/perl
#
# filltranslationgaps.pl 

# Get list of included languages
my $tmp = uc(`grep "^!insertmacro MUI_LANGUAGE" installer.nsi |grep -v ";" |cut -f2 -d\\"`);
my @lang = split(/\n/, $tmp);
my $DEFAULTLANGUAGE = $lang[0];

# Get langstrings
open( $fh, "<installer.nsi");
while (<$fh>) {
        if (/LangString *(.*?) *\${LANG_(.*?)} *\"(.*)\"/)  {
                $phrases{$1}{$2}=$3;
        }
}
close $fh;

# Foreach Langstring, check if it's defined in all included languages.
foreach my $k (keys %phrases) {
        foreach my $j (@lang) {
                if (not defined $phrases{$k}{$j}) {
                        #print "MISSING PAIR: $k\t$j\n";
                        print "LangString $k \${LANG_$j} \"$phrases{$DEFAULTLANGUAGE}{$j}\"\n";
                }
        }
}

我的编译脚本:

#/bin/sh
perl filltranslationgaps.pl >missingphrases.nsi
makensis installer.nsi

在installer.nsi中,我需要包含生成的nsi:

!include  missingphrases.nsi

希望它有所帮助。

答案 1 :(得分:0)

LangFile.nsh包含帮助代码,用于创建具有后备支持的语言文件(由MUI等使用),但每种语言必须位于单独的.nsh文件中。

如果您想保留.nsi中的所有翻译,您必须制作自己的自定义宏:

!macro MyLangInit lnam nlf
!ifndef MYLANG
    !define MYLANG ${lnam}
    !ifndef MYLANG_${lnam}
        !define MYLANG_${lnam}
        LoadLanguageFile "${NSISDIR}\Contrib\Language files\${nlf}.nlf"
        !ifndef LANG_${lnam}
            !define LANG_${lnam} ${LANG_${nlf}}
        !endif
    !endif
!endif
!macroend
!define MyLangInit "!insertmacro MyLangInit "
!macro MyLangSet mode nam str
!ifndef MYLANG_${MYLANG}_${nam}
    !define MYLANG_${MYLANG}_${nam} "${str}"
!else
    !if ${mode} != 0
        !ifdef MYLANG_${MYLANG}_${nam}
            LangString ${nam} "" "${MYLANG_${MYLANG}_${nam}}"
            !undef MYLANG_${MYLANG}_${nam}
        !endif
    !endif
!endif
!macroend
!macro MyLangLoad lnam
!define MyLangSet "!insertmacro MyLangSet 0 "
!insertmacro ${lnam}
!insertmacro ${MYLANG_FALLBACK}
!undef MyLangSet
!define MyLangSet "!insertmacro MyLangSet 1 "
!insertmacro ${lnam}
!insertmacro ${MYLANG_FALLBACK}
!undef MyLangSet
!undef MYLANG
!macroend

!macro English
${MyLangInit} English English
${MyLangSet} foo "bar"
${MyLangSet} bar "baz"
!macroend

!macro Bork
${MyLangInit} Bork Swedish ; Based on Swedish
${MyLangSet} foo "bork"
; Missing: ${MyLangSet} bar "barkz"
!macroend

!macro Danish
${MyLangInit} Danish Danish
; All strings are missing!
!macroend


!define MYLANG_FALLBACK English ; Language to use for missing strings
!insertmacro MyLangLoad Bork
!insertmacro MyLangLoad Danish
!insertmacro MyLangLoad English

Function .onInit
StrCpy $LANGUAGE ${LANG_BORK} ; TODO: Use LangDLL or some algorithm to select the language here
FunctionEnd

Section
SetDetailsView show
DetailPrint LangId=$LANGUAGE
DetailPrint "$(foo)"
DetailPrint "$(bar)"
SectionEnd