2013-02-06 81 views
2

我的安裝必須適用於多種語言,但我無法完全翻譯所有消息。消息未翻譯時如何使用默認語言?未翻譯的LangString如何使用默認語言?

例如:

!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,串埋入式將使用英語翻譯,因爲沒有內嵌的中國人。

+0

恕我直言沒有意義使用回退字符串從不同的語言,你應該把所有字符串或根本不支持該語言... – Anders

回答

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 

希望它能幫助。

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