2012-05-30 31 views
0

我想在WinForms應用程序中使用衛星程序集進行本地化。目錄結構如下:本地化衛星組件

    • 的Program.exe
      • Program.resources.dll

在程序中。這個代碼在執行方法:

Application.EnableVisualStyles(); 
Application.SetCompatibleTextRenderingDefault(false); 

Thread.CurrentThread.CurrentUICulture = new CultureInfo("de"); 

Application.Run(new Form()); 

我查了FUSLOGVW.exe輸出:

 
*** Assembly Binder Log Entry (5/30/2012 @ 5:19:37 PM) *** 

The operation failed. 
Bind result: hr = 0x80070002. The system cannot find the file specified. 

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll 
Running under executable D:\tmp\bin\Program.exe 
--- A detailed error log follows. 

=== Pre-bind state information === 
LOG: User = paulius_l 
LOG: DisplayName = Program.resources, Version=1.0.0.0, Culture=de, PublicKeyToken=... 
(Fully-specified) 
LOG: Appbase = file:///D:/tmp/bin/ 
LOG: Initial PrivatePath = NULL 
LOG: Dynamic Base = NULL 
LOG: Cache Base = NULL 
LOG: AppName = Program.exe 
Calling assembly : Program, Version=1.0.0.0, Culture=neutral, PublicKeyToken=.... 
=== 
LOG: Start binding of native image Program.resources, Version=1.0.0.0, Culture=de, PublicKeyToken=.... 
WRN: No matching native image found. 
LOG: IL assembly loaded from D:\tmp\bin\de\Program.resources.dll. 

這看起來不錯,但是字符串只是沒有得到本地化 - 從默認的Program.exe字符串仍在使用。

要獲取字符串我使用Visual Studio生成的Res類從Res.resx

我在這裏錯過了什麼?

編輯:添加完整的FUSLOGVW輸出,對於那些比我更瞭解它的人。

+0

你有沒有嘗試在Form-Constructor中設置UICulture? – Jobo

+0

是的,我有,在調用InitializeComponent()之前。效果是一樣的。那是沒有效果的。 –

+0

您是否驗證過(可能有反射器)衛星組件中有不同的字符串資源? – MerickOWA

回答

0

這是我在編寫自動構建腳本時所犯的巨大錯誤,該腳本會在外部生成附屬程序集。問題在於,在附屬程序集中生成類時,我錯過了Res類。難怪它沒有奏效。

花了很長時間,我今天早上發現了這個問題。

-1

我相信你的文化標識是錯誤的在這條線:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("de"); 

文化標識符的CultureInfo採取「語言代碼-COUNTRYCODE」的形式。例如。美國英語爲「en-US」,英國/英國英語爲「en-GB」。

嘗試「de-DE」。

有關文化標識符列表的更多信息,請參閱http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.name%28v=vs.95%29.aspxhttp://msdn.microsoft.com/en-us/goglobal/bb896001.aspx

+0

「de」是一個有效的標識符。 「德-DE」對於德國的德國人更具體。儘管如此,我已經嘗試過兩種方法 - 沒有一種可行。事實上,如果我同時擁有「de」和「de-DE」,那麼只有「de」資源會被加載,因爲據我所知,這是一個更普遍的文化標識符。 –

+0

在具有文化標識符列表的網站中,「de」也被列爲有效標識符。 –

+1

即使MSDN上的示例在其示例應用程序輸出中也提供了「en」作爲可能性。國家代碼是可選的。 – MerickOWA