2009-08-20 93 views
9

我想在App_GlobalResources文件夹中为名为“shopping.en-sg.resx”的新加坡英语(en-sg)创建资源文件。在ASP.NET中创建自定义区域

编译过程中出现错误。

错误1命名空间 '资源' 已经包含了定义 '购物' C:\ WINDOWS \ Microsoft.NET \框架\ V2.0.50727 \临时 ASP.NET 文件\网络\ 2cd6afe9 \ 737b0a13 \ App_GlobalResources.vomuzavz.1.cs 26

谷歌搜索后,我发现“EN-SG”不是默认的文化,我要创建自定义的文化吧。我不知道这个的详细步骤。

我应该怎么做才能创建文化并消除编译错误?

我按照MSDN的例子中,创建一个名为 “shopping.x-EN-US-sample.resx” 文件,把下面的代码到的BasePage的功能(保护覆盖无效InitializeCulture()):

CultureAndRegionInfoBuilder cib = null; 

cib = new CultureAndRegionInfoBuilder(
    "x-en-US-sample", CultureAndRegionModifiers.None); 

CultureInfo ci = new CultureInfo("en-US"); 
cib.LoadDataFromCultureInfo(ci); 
RegionInfo ri = new RegionInfo("US"); 
cib.LoadDataFromRegionInfo(ri); 

cib.Register(); 

ci = new CultureInfo("x-en-US-sample"); 

但是,编译错误仍然存​​在。

更新:

,您可以轻松创建一个空的网站,两个文件“shopping.en-sg.resx”,并在App_GlobalResources文件夹“shopping.resx”重现该问题。

回答

15

您可以创建基于现有的文化一种新的文化:

string culture = "en-sg"; 
string name = "Singaporean English"; 

CultureInfo cultureInfo = new CultureInfo("en-GB"); 
RegionInfo regionInfo = new RegionInfo(cultureInfo.Name); 

CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder(culture, CultureAndRegionModifiers.None); 

cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(cultureInfo); 
cultureAndRegionInfoBuilder.LoadDataFromRegionInfo(regionInfo); 

// Custom Changes 
cultureAndRegionInfoBuilder.CultureEnglishName = name; 
cultureAndRegionInfoBuilder.CultureNativeName = name; 

cultureAndRegionInfoBuilder.Register(); 

补充: 刚才检查的参考文献: 我:

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Globalization; 
using System.IO; 
using System.Reflection; 
using System.Runtime.CompilerServices; 

已添加(更新的基础上,评论):

至于错误消息:

你看到的错误是某些资源命名冲突的结果。检查资源名称,这些被编译到dll中,你需要检查命名空间名称是否不冲突。您可以使用反射器工具检查:http://www.red-gate.com/products/reflector/

+0

我应该在哪里放置这段代码以避免错误? – Billy 2009-08-20 07:43:28

+0

此代码只需要在需要额外文化的机器上运行一次。因为它已经存在,也许你会得到错误? – 2009-08-20 07:46:05

+0

把代码放在global.asax中? 如果我将“en-sg”更改为“en-us”,那很好。 我只想要一段代码,我可以简单地把它放在某个地方,然后我可以使用shopping.en-sg.resx – Billy 2009-08-20 07:59:44

1
+0

我试过了,它不起作用。更多信息。被添加。 – Billy 2009-08-20 07:33:40

+1

修复链接:http://msdn.microsoft.com/en-us/library/ms172469(v=vs.100).aspx – Sprintstar 2014-05-12 09:03:25

+0

谢谢@Sprintstar:我更新了我的帖子中的链接。 – 2014-05-12 14:15:18

3

以下是创建en-sg文化所需的步骤和代码。

  1. 创建控制台应用程序。 (C:\ Windows \ Microsoft.NET \ Framework \ v2.0.50727 \ sysglobl.dll)
  2. 添加对sysglobl(C:
  3. 以管理员身份在Web服务器和开发机器上运行它。

它会根据我发现的最接近匹配(en-au)创建一种文化。然后我重写名字等,使它独一无二。

你应该只需要运行一次。在创建它之前,它会删除所有现有的,以防您在运行后进行任何修改。

public static void Main() 
    { 
     CultureAndRegionInfoBuilder cib = null; 

     try 
     { 
      Console.Clear(); 
      Console.WriteLine("Unregister the \"en-SG\" " + "custom culture if it already exists..."); 
      CultureAndRegionInfoBuilder.Unregister("en-SG"); 
      Console.WriteLine("The custom culture was unregistered successfully."); 
     } 
     catch (Exception e) 
     { 
      Console.WriteLine("Error while unregistering..."); 
      Console.WriteLine(e); 
     } 

     try 
     { 
      cib = new CultureAndRegionInfoBuilder("en-SG", CultureAndRegionModifiers.None); 

      // Populate the new CultureAndRegionInfoBuilder object with culture information. 
      CultureInfo ci = new CultureInfo("en-AU"); 
      cib.LoadDataFromCultureInfo(ci); 

      // Populate the new CultureAndRegionInfoBuilder object with region information. 
      RegionInfo ri = new RegionInfo("SG"); 
      cib.LoadDataFromRegionInfo(ri); 

      cib.CultureEnglishName = "English (Singapore)"; 
      cib.CultureNativeName = "English (Singapore)"; 
      cib.IsMetric = true; 

      // Display some of the properties of the CultureAndRegionInfoBuilder object. 
      Console.WriteLine("CultureName:. . . . . . . . . . {0}", cib.CultureName); 
      Console.WriteLine("CultureEnglishName: . . . . . . {0}", cib.CultureEnglishName); 
      Console.WriteLine("CultureNativeName:. . . . . . . {0}", cib.CultureNativeName); 
      Console.WriteLine("GeoId:. . . . . . . . . . . . . {0}", cib.GeoId); 
      Console.WriteLine("IsMetric: . . . . . . . . . . . {0}", cib.IsMetric); 
      Console.WriteLine("ISOCurrencySymbol:. . . . . . . {0}", cib.ISOCurrencySymbol); 
      Console.WriteLine("RegionEnglishName:. . . . . . . {0}", cib.RegionEnglishName); 
      Console.WriteLine("RegionName: . . . . . . . . . . {0}", cib.RegionName); 
      Console.WriteLine("RegionNativeName: . . . . . . . {0}", cib.RegionNativeName); 
      Console.WriteLine("ThreeLetterISOLanguageName: . . {0}", cib.ThreeLetterISOLanguageName); 
      Console.WriteLine("ThreeLetterISORegionName: . . . {0}", cib.ThreeLetterISORegionName); 
      Console.WriteLine("ThreeLetterWindowsLanguageName: {0}", cib.ThreeLetterWindowsLanguageName); 
      Console.WriteLine("ThreeLetterWindowsRegionName: . {0}", cib.ThreeLetterWindowsRegionName); 
      Console.WriteLine("TwoLetterISOLanguageName: . . . {0}", cib.TwoLetterISOLanguageName); 
      Console.WriteLine("TwoLetterISORegionName: . . . . {0}", cib.TwoLetterISORegionName); 
      Console.WriteLine(); 

      // Register the custom culture. 
      Console.WriteLine("Register the custom culture..."); 
      cib.Register(); 

      // Display some of the properties of the custom culture. 
      ci = new CultureInfo("en-SG"); 

      Console.WriteLine("Name: . . . . . . . . . . . . . {0}", ci.Name); 
      Console.WriteLine("EnglishName:. . . . . . . . . . {0}", ci.EnglishName); 
      Console.WriteLine("NativeName: . . . . . . . . . . {0}", ci.NativeName); 
      Console.WriteLine("TwoLetterISOLanguageName: . . . {0}", ci.TwoLetterISOLanguageName); 
      Console.WriteLine("ThreeLetterISOLanguageName: . . {0}", ci.ThreeLetterISOLanguageName); 
      Console.WriteLine("ThreeLetterWindowsLanguageName: {0}", ci.ThreeLetterWindowsLanguageName); 

     } 
     catch (Exception e) 
     { 
      Console.WriteLine(e); 
     } 
     Console.ReadKey(); 
    } 
相关问题