您的位置:首页 > 其它

HOWTO: 使用命令行方式导入导出多语言String Tables

2011-02-14 18:01 876 查看
在多语言软件的打包中,我们常常需要将大量的string tables导出,翻译,导入。使用UI界面来操作比较费时。在InstallShield中,提供了Automation Interface使用VBScript来帮助我们使用命令行的方式批量处理这样操作。
打开InstallShield的帮助文档,搜索“Importing and Exporting String Tables Using the Automation Interface“,可以看到一段示例代码。以下以InstallShield 10.5为例。

'BEGIN ImportExportStrings.vbs
'
'  InstallShield (R)
'  (c) 2001 - 2004  InstallShield Software Corporation
'  All Rights Reserved.
'
'
'  This utility was designed to assist in the importing and exporting of string tables
'
'
'  File Name:  ImportExportStrings.vbs
'
'  Description:  Sample VBScript file imports or exports a string table text file
'
'  Usage:  To use the objects in this script, make sure you have the following
'          items in place on your system:
'          1. InstallShield must be installed so
'             the end-user automation is available
'          2. You must have Windows Scripting Host installed.(Wscript.exe)
'          3. The script expects the following command-line arguments, in
'             this order:
'             a. The fully qualified path to an existing .ism file.
'             b. The fully qualified path to a text file for the string table entries
'             c. Decimal language identifier
'             d. Import or Export
'
'/////////////////////////////////////////////////////////////////////////////

If Wscript.Arguments.Count < 1 Then
Wscript.Echo "InstallShield Subfolder Utility" & _
vbNewLine & "1st argument is the full path to the .ism file" & _
vbNewLine & "2nd argument is the full path to the string table text file" & _
vbNewLine & "3rd argument is the decimal language identifier" & _
vbNewLine & "4th argument is either E or I for Export or Import"
Wscript.Quit 1
End If
' Create the end-user automation object
Dim ISWIProject
Set ISWIProject = CreateObject("IswiAuto1050.ISWiProject"): CheckError
' Open the project specified at the command line
ISWIProject.OpenProject Wscript.Arguments(0): CheckError
if(Wscript.Arguments(3)="E")then
StringsExport ISWIProject,Wscript.Arguments(1),Wscript.Arguments(2)
elseif(Wscript.Arguments(3)="I")then
StringsImport ISWIProject,Wscript.Arguments(1),Wscript.Arguments(2)
end if
' Save and close the project
ISWIProject.SaveProject: CheckError
ISWIProject.CloseProject: CheckError
'/////////////////////////////////////////////////////////////////////////////
' Export the string table
Sub StringsExport(byref p,byval path, byval language)
p.ExportStrings path, Date , language
Wscript.Echo "Exported String table for language " & language & " to " & path
End Sub
'/////////////////////////////////////////////////////////////////////////////
' Import the string table
Sub StringsImport(byref p,byval path, byval language)
p.ImportStrings path, language
Wscript.Echo "Imported String table for language " & language & " from " & path
End Sub
'/////////////////////////////////////////////////////////////////////////////
Sub CheckError()
Dim message, errRec
If Err = 0 Then Exit Sub
message = Err.Source & " " & Hex(Err) & ": " & Err.Description
Wscript.Echo message
Wscript.Quit 2
End Sub
'END ImportExportStrings.vbs


使用这段代码进行导入是可以正确运行的,但是导出代码时,无论如何修改语言的language identifier,都得到一样的结果。在帮助文档中查询代码中使用到的ExportStrings函数,提示说如果想要导出别的语言的string tables,需要将工程的默认语言修改为目的语言,执行导出代码之后再改回去。工程的默认语言属性是ActiveLanguage,因此,我们需要在导出string tables的代码之前先修改属性ActiveLanguage,这样就能正确导出所需要的语言的string table。代码如下:

'/////////////////////////////////////////////////////////////////////////////
'BEGIN ImportExportStrings.vbs
'
'  InstallShield (R)
'  (c) 2001 - 2004  InstallShield Software Corporation
'  All Rights Reserved.
'
'
'  This utility was designed to assist in the importing and exporting of string tables
'
'
'  File Name:  ImportExportStrings.vbs
'
'  Description:  Sample VBScript file imports or exports a string table text file
'
'  Usage:  To use the objects in this script, make sure you have the following
'          items in place on your system:
'          1. InstallShield must be installed so
'             the end-user automation is available
'          2. You must have Windows Scripting Host installed.(Wscript.exe)
'          3. The script expects the following command-line arguments, in
'             this order:
'             a. The fully qualified path to an existing .ism file.
'             b. The fully qualified path to a text file for the string table entries
'             c. Decimal language identifier
'             d. Import or Export
'
'/////////////////////////////////////////////////////////////////////////////

If Wscript.Arguments.Count < 1 Then
Wscript.Echo "InstallShield Subfolder Utility" & _
vbNewLine & "1st argument is the full path to the .ism file" & _
vbNewLine & "2nd argument is the full path to the string table text file" & _
vbNewLine & "3rd argument is the decimal language identifier" & _
vbNewLine & "4th argument is either E or I for Export or Import"
Wscript.Quit 1
End If
' Create the end-user automation object
Dim ISWIProject
Set ISWIProject = CreateObject("IswiAuto1050.ISWiProject"): CheckError
' Open the project specified at the command line
ISWIProject.OpenProject Wscript.Arguments(0): CheckError
Dim proActiveLanguage
proActiveLanguage=ISWIProject.ActiveLanguage
ISWIProject.ActiveLanguage=CInt(Wscript.Arguments(2))
if(Wscript.Arguments(3)="E")then
StringsExport ISWIProject,Wscript.Arguments(1),Wscript.Arguments(2)
elseif(Wscript.Arguments(3)="I")then
StringsImport ISWIProject,Wscript.Arguments(1),Wscript.Arguments(2)
end if
ISWIProject.ActiveLanguage=proActiveLanguage
' Save and close the project
ISWIProject.SaveProject: CheckError
ISWIProject.CloseProject: CheckError
'/////////////////////////////////////////////////////////////////////////////
' Export the string table
Sub StringsExport(byref p,byval path, byval language)
p.ExportStrings path, Date , language
Wscript.Echo "Exported String table for language " & language & " to " & path
End Sub
'/////////////////////////////////////////////////////////////////////////////
' Import the string table
Sub StringsImport(byref p,byval path, byval language)
p.ImportStrings path, language
Wscript.Echo "Imported String table for language " & language & " from " & path
End Sub
'/////////////////////////////////////////////////////////////////////////////
Sub CheckError()
Dim message, errRec
If Err = 0 Then Exit Sub
message = Err.Source & " " & Hex(Err) & ": " & Err.Description
Wscript.Echo message
Wscript.Quit 2
End Sub
'END ImportExportStrings.vbs


同时,需要注意的是,每个版本的InstallShield其ISWiProject对象的建立名称都是不一样的,一般与版本号有关(代码2第42行)。

Set ISWIProject = CreateObject("IswiAuto1050.ISWiProject"): CheckError


即其中的IswiAuto1050需要根据不同的版本进行修改,具体可以在帮助文档中查询Importing and Exporting String Tables Using the Automation Interface得到。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: