Note that there are some explanatory texts on larger screens.

plurals
  1. POAsp.net Globalization gone crazy
    text
    copied!<p>I've built a website that has 6 different language support. And whole language system gone crazy. It either opens with the requested language or half of requested and half of another one orrrr completely another one.</p> <p>Here is a describe for how i built the system.</p> <p>In global.asax i've done this;</p> <pre><code>protected void Application_AcquireRequestState(object sender,EventArgs e) { //just to show my point if(RouteData.Values["language"] =! null){ switch(RouteData.Values["language"].toString()) { case "en-us": // at this point i'm changing the value of static enum that i've already defined in another class , // just to reach it from other pages. You'll see what i mean in a second. Statics.Language = LanguageEnum.EN; break; } // Here is the culture changing codes. ConvertToCulture method is a custom method to get ISO code for language from LanguageEnum System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(ConvertToCulture(Statics.Language)); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(ConvertToCulture(Statics.Language)); } </code></pre> <p>This is the global.asax file. And i have extension methods on every entity ( by the way , i'm using Entity Framework) to get the string for given language.</p> <p>Of course you may wonder why i've wrote extensions methods on entities. In my database none of the strings are in the same table. I mean like this ; </p> <p>for "Products" table i have [ ID(int),Name(int) ] columns.</p> <p>for "LanguageStrings" table i have [ ID(int) , EN(string) , FR(string)] columns.</p> <p>And the "Name" column on the products is referenced to the ID column on the LanguageStrings table.</p> <p>Here is an extension method sample ;</p> <pre><code> public static string GetName(this Product pr) { try { return pr.LanguageStrings.GetType(). GetProperty(Statics.Language.ToString()). GetValue(pr.LanguageStrings, null).ToString(); } catch (Exception ex) { return "null"; } } </code></pre> <p>In every page on my website , i'm reaching the names,descriptions,tech infos with these extensions. And also i have method to get strings from ".resx" files , which is :</p> <pre><code> public static string ResGet(string key) { return Resources.Strings.ResourceManager.GetString(key); } </code></pre> <p>To the point ; </p> <p>For example when default page requested , it sometimes comes all in english. Sometimes hall of the page is english , half of the page is french. Sometimes its all french. </p> <p>Either whole page open with the language that requested , or half of requested and half of another one or completely another one. I mean its either 2 or 1 language appears...</p> <p>It really is driving me crazy. And its happens randomly. I couldn't figured it out.</p> <p>It'd really be great if you guys help me !</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload