Create custom culture in ASP.NET

前端 未结 3 875
孤独总比滥情好
孤独总比滥情好 2020-11-29 08:43

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.

3条回答
  •  眼角桃花
    2020-11-29 09:30

    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;
    

    Added (updated, based on comments):

    With regards the error message:

    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/

提交回复
热议问题