2009-08-20 8 views
9

में कस्टम संस्कृति बनाएं I App_GlobalResources फ़ोल्डर में "shopping.en-sg.resx" नामक सिंगापुर अंग्रेज़ी (एन-एसजी) के लिए संसाधन फ़ाइल बनाना चाहते हैं।ASP.NET

मुझे संकलन के दौरान त्रुटि मिलती है।

त्रुटि 1 नाम स्थान 'संसाधन' पहले से ही 'खरीदारी' सी के लिए एक परिभाषा में शामिल हैं: \ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ अस्थाई ASP.NET Files \ वेब \ 2cd6afe9 \ 737b0a13 \ App_GlobalResources.vomuzavz.1.cs 26

गूगल खोज के बाद, मैं पता चलता है कि "en-sg" एक डिफ़ॉल्ट संस्कृति नहीं है और मैं इसके लिए कस्टम संस्कृति का निर्माण करने की है। मुझे इसके विस्तृत कदम नहीं पता हैं।

संस्कृति बनाने और संकलन त्रुटि को हटाने के लिए मुझे क्या करना चाहिए? (संरक्षित ओवरराइड शून्य InitializeCulture())

मैं MSDN में उदाहरण का अनुसरण, एक फ़ाइल "shopping.x-en-अमेरिका-sample.resx" कहा जाता है बना सकते हैं और BasePage के समारोह में निम्न कोड डाल:

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

हालांकि, संकलन त्रुटि अभी भी मौजूद है।

UPDATED:

आप आसानी से एक खाली वेबसाइट और दो फ़ाइलों "shopping.en-sg.resx" और "shopping.resx" app_globalresources फ़ोल्डर में बनाने के द्वारा समस्या को पुन: कर सकते हैं।

उत्तर

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; 

जोड़ा गया (अद्यतन, टिप्पणी के आधार पर):

के साथ संबंध है त्रुटि संदेश:

त्रुटि आप देख रहे हैं कुछ संसाधन नामकरण संघर्ष का परिणाम है। संसाधन नामों की जांच करें, इन्हें डीएलएस में संकलित किया गया है ताकि आपको यह जांचने की आवश्यकता हो कि नामस्थान नाम संघर्ष नहीं करते हैं। आप परावर्तक उपकरण का उपयोग करके इसे देख सकते हैं: http://www.red-gate.com/products/reflector/

+0

त्रुटि से बचने के लिए मुझे यह कोड कहां रखना चाहिए? – Billy

+0

यह कोड केवल उस मशीन पर चलाने की आवश्यकता है जहां आपको अतिरिक्त संस्कृति की आवश्यकता है। हो सकता है कि आप त्रुटि प्राप्त कर रहे हैं क्योंकि यह पहले से मौजूद है? –

+0

कोड को global.asax में रखें? यदि मैं "en-sg" से "en-us" बदलता हूं, तो यह ठीक है। मैं सिर्फ कोड का एक टुकड़ा चाहता हूं जिसे मैं इसे कहीं और रख सकता हूं और उसके बाद मैं shopping.en-sg.resx – Billy

1
+0

मैंने कोशिश की है और यह काम नहीं करता है। और जानकारी। जोड़ दिया गया है। – Billy

+1

फिक्स्ड लिंक: http://msdn.microsoft.com/en-us/library/ms172469(v=vs.100).aspx – Sprintstar

+0

धन्यवाद @Sprintstar: मैंने अपनी पोस्ट में भी लिंक अपडेट किया। –

3

एन-एसजी संस्कृति बनाने के लिए आवश्यक कदम और कोड यहां दिए गए हैं।

  1. एक कंसोल ऐप बनाएं।
  2. sysglobl के लिए एक संदर्भ जोड़ें (C: \ Windows \ Microsoft.NET \ Framework \ v2.0.50727 \ sysglobl.dll)
  3. इसे करने के लिए नीचे दिए गए कोड जोड़ें।
  4. इसे वेब सर्वर (ओं) और देव मशीन पर व्यवस्थापक के रूप में चलाएं।

यह मेरे निकटतम मैच (एन-एयू) के आधार पर एक संस्कृति बनाएगा। मैंने इसे अद्वितीय बनाने के लिए नामों को ओवरराइड किया है।

आपको केवल इसे एक बार चलाने की ज़रूरत है। यदि आप इसे चलाने के बाद कोई संशोधन करना चाहते हैं तो इसे बनाने से पहले यह किसी मौजूदा व्यक्ति को हटा देता है।

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