2008-11-20 40 views
1

我正在開發SharpDevelop中開發的本地化應用程序。根據tutorial我遇到了一個錯誤:使用SharpDevelop進行本地化

Could not find any resources appropriate for the specified culture (or the neutral culture) on disk. baseName:

我使用項目創建的ressource文件|添加|新項目分別爲「空資源文件」(我找不到「Assembly Resource file」)。此外,我已將「Build action」設置爲「EmbeddedResource」。

在節目我有一類執行以下操作

// load the resource file once 
resourceManager = ResourceManager.CreateFileBasedResourceManager(file, filePath, null); 

// depending on user selection, I set the CultureInfo in the code behind the form, i.e. 
Thread.CurrentThread.CurrentUICulture = locales[0]; // which contains "en" 

// and that's the method of the same class used to lookup the values 
public string getValue (string key) 
{ 
    return resourceManager.GetString(key); 
} 

的SharpDevelop 3.0.0.3437 .NET版本2.0.50727.3053

通過評論雖然經過精心準備和谷歌上搜索了很久,我無法找到一個例子或解決方案。因此,問題:

  • 如何將文化添加到資源文件本身?
  • 你能提供一個例子或鏈接嗎?

非常感謝!

回答

1

CreateFileBasedResourceManager將只處理二進制.resources文件(不是.resx文件)。

如果您堅持從外部文件加載資源而不是將資源嵌入到程序集中,您需要運行resgen命令行實用程序來生成.resources文件。 所以,如果你還沒有這樣做,爲每個支持的文化生成一個。

否則它看起來沒問題。

但是,如果您寧願將資源嵌入到程序集中,請在屬性窗口中將生成操作設置爲嵌入式資源。

如果你想也想產生一個強類型的類把所有的瑣碎工作, 設置的自定義工具上基本文件只(不變的)到ResXFileCodeGenerator, 或PublicResXFileCodeGenerator如果你需要的是(在創建衛星組件時很好)。

然後你不需要照顧自己加載本地化的資源。 生成的類爲你做這一切。

對於資源中的每個鍵,生成的類中會生成一個靜態屬性,您只需調用該屬性即可,它非常乾淨並且是迄今爲止最簡單的方法。

除非有特殊原因需要從.resources文件加載資源,否則我總是建議將它們嵌入到程序集中。

0

我不確定您使用的是什麼版本的.NET,但是此上的MSDN文章可能對您有用。