2008-11-20 61 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文章可能对您有用。