在ASP.NET中创建自定义的文化 [英] Create custom culture in ASP.NET

查看:104
本文介绍了在ASP.NET中创建自定义的文化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建新加坡英语(en-SG)在App_GlobalResources文件夹命名为shopping.en-sg.resx的资源文件。

I want to create a resource file for Singaporean English (en-sg) named "shopping.en-sg.resx" in App_GlobalResources folder.

我在编译过程中出现错误。

I get error during compilation.

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

Error 1 The namespace 'Resources' already contains a definition for 'shopping' c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\web\2cd6afe9\737b0a13\App_GlobalResources.vomuzavz.1.cs 26

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

After searching Google, I discover that "en-sg" is not a default culture and I have to create custom culture for it. I don't know the detailed steps of this.

我应该怎么办创建文化和移除编译错误?

What should I do to create the culture and remove the compilation error?

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

I follow the example in MSDN, create a file called "shopping.x-en-US-sample.resx" and put the following code into BasePage's function (protected override void 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");

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

However, compilation error is still exist.

更新:

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

推荐答案

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

You can create a new culture based on an existing culture:

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();

补充:
刚检查了引用:
我有:

Added: Just checked the references: I have :

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

新增(更新的基础上,评论)

至于错误信息:

您所看到的错误是某些资源命名冲突的结果。检查资源名称,你需要检查的命名空间名称不冲突这些被编译成动态链接库。您可以检查此使用反射工具:<一href=\"http://www.red-gate.com/products/reflector/\">http://www.red-gate.com/products/reflector/

The error you're seeing is the result of some resource naming conflict. Check the resource names, these get compiled into dlls to you need to check that the namespace names dont conflict. You can check this using the reflector tool: http://www.red-gate.com/products/reflector/

这篇关于在ASP.NET中创建自定义的文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆