I'm working on a project that has a web application module that generates localized emails upon request. The app requires html templates localization for several languages. I decided to go with asp.net resource files since the email layout is not likely to change and the amount of keys needed was relatively small.
I'm using Global Resources and have around 15 different resource files for the required locales. I have my default resource file in English ("EmailTemplates.resx") and then several localized resource files ("EmailTemplates.ru-RU.resx", "EmailTemplates.zh-CN.resx", "EmailTemplates.it-IT.resx", "EmailTemplates.id-ID.resx", etc).
Among the resource files, I have two arabic ones: "EmailTemplates.ar-AE.resx" which is actually in English and "EmailTemplates.ar-SA.resx" which is in Arabic.
All the emails for non Arabic locales work perfectly. The app picks up the required locale and uses the corresponding resource files. But when I try to request the Arabic ones, it always fall back to the default resource file.
The way I'm setting up the culture is based on the data requested, and not the browser settings:
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
While debugging I can see that the CultureInfo is properly set to "ar-SA" or "ar-AE" but when the app retrieves the corresponding resource value, it always picks up the default one.
I have entered Arabic data in the default resource file for testing purposes, and the Arabic text displays just fine, so I'm sure that it is not a font or HTML layout issue.
I have searched all around the Internet, proved different approaches, and no luck. The "ar-SA" and "ar-AE" are valid CultureInfo values and the app compiles without issues, but it seems that whenever I request the Arabic emails, the app can't find the Arabic resource files.
Any ideas? I'd really appreciate any hits and help !
Cheers!
Please use the language without the culture info
Eg. EmailTemplates.ar.resx
because the browser you are using might not have the Arabic in different cultures as i checked with my chrome .or try adding the language with that culture.example ar-AE ar-SA etc,But anyway it has the Arabic language without culture and it works.
Related
I recently was asked to transfer a multilingual site from working with languages based on cookies, to removing the cookie containing the language in the URL, for better SEO, while keeping the default language without the "prefix".
So instead of "mysite.com/page", I would have "mysite.com/{language}/page" for every language except for the default.
And so I updated the routing in the project to include the "{language}/URL" in an additional MapPageRoute for each URL.
The issue now is with relative paths for scripts and images etc.
When I am not in default language, the URL of these requests contains an additional "/en" or "/fr" or something, and of course there is no such folder.
Is there any workaround for this? I really don't want to have to replace close to thousand paths with absolute, or check for language before declaring them.
I'm working on multilingual website where I want to get language resource from SQL db table. Resource Table column is already set to nvarchar though It's completely strange behavior get junk character when it's getting rendered in MVC View.
û rendered as û
However, It's working fine in my local machine but problem occurs on production environment only. Don't know why!!!
Static & Resource file content of different languages are rendered perfectly fine but the problem occurs only for resources retrieved from SQL table.
Tried setting meta tag with utf-8 charset in page & globalization with request response encoding to utf-8 in web.config but couldn't resolve my problem.
Should it be problem of IIS or Entity Framework is converting it to junk characters? Really confused.....
I'm using MVC4 with Entity Framework.
Any help will be greatly appreciated.
I am contracted to support a legacy ASP.net WebForms application. It's a commercial web site, and it's quite old.
Yesterday, I received a trouble-ticket that seemed to defy everything I know about web applications.
The trouble-ticket indicated that a certain URL sometimes returned an HTTP 404 error. The submitter also swears that the problem only occurs when browsing the site with Chrome. The web application is available in English and French, but the trouble-ticket says that the problem only occurs on the French version of the web application.
The URL looks like this:
http://www.example.com/promotion/mg_547/SpecialOffer.search
I tried navigating to the page in my development environment: http://www.example.dev/promotion/mg_547/SpecialOffer.search. It seemed to work fine.
Although these URLs are fictionalized, "mg_547" is an actual directory name in the URL.
I decided to navigate to the file in Windows Explorer to see if there is something unusual about the file. That's when things became surreal.
When I navigated to the "promotion" directory, I found that there is no "mg_547" directory (and besides, what meaning could such a name have?). My understanding is that in an ASP.net WebForms application, URLs corresponding to files on a physical disk, but here, there is not file; there is no directory!
I checked that there isn't an "mg_547" virtual directory in IIS.
I carefully checked that there isn't an MVC controller hiding somewhere in the application and I reviewed the global.asax.cs file to see if there could be some unusual routing set up. I couldn't find anything that would explain what I'm seeing.
I decided that the text of the page must appear in my code base somewhere, so I selected some text from the page (being sure that it didn't contain HTML-encodings) and searched for the text in the code-base; no matches!
Therefore, as far as I can tell, it seems as if the IIS server is just making up this page with Satanic Black Magic!
I believe that I've found the answer. #EdSF's comment was very helpful.
There is a .net class called PageHandlerFactory which is overidden in the web application. Specifically, this class overrides the PageHandlerFactory.GetHandler method. The mg_547 directory name is parsed in this overridden method and maps the URL to a different file on disk.
As for the original trouble-ticket that started all of this, perhaps there could be a bug in this method that causes the 404 error.
This is just as I expected. This is a corner of ASP.net I've not yet become familiar with.
ASP.NET has build-in functionality to automatically load the correct language resource file based on the browser's preferred language.
For example, if a visitor has Danish (da) as his/her preferred language, and the website has a *.da.resx file, then that resource is used. When the preferred resource file is not available, ASP.NET falls back to the basic/default resource file (*.resx).
Now, browsers allow for more than one preferred languages to be specified. If the visitor would speak Danish, but added Norwegian as a second language to the browsers preferences (written Norwegian is 95% identical to Danish), then the browser would send "da,no;q=0.9" to the web server. However, it seems this secondary language is not supported by ASP.NET; *.no.resx will not be loaded if *.da.resx is not available.
Does anybody know how to support secondary languages?
Note that ASP.NET only automatically processes the first entry in the accept-languages header field to determine which culture to use if enableClientBasedCulture is enabled in the web.config file.
If you wish to extend this and examine other language entries (if any) in the accept-languages list to see if you have a match, you will have to do it programmatically and set the Thread.CurrentThread.CurrentUICulture(which the ResourceManager uses to find the appropriate localized resources) and Thread.CurrentThread.CurrentCulture (which will control how locale-aware datatypes will be presented and processed). This is explained here.
My Android app connects to a asp.net web service to register the user. When the user is registered I send a welcome email from the server to the user. As we have customers in many countries the email need to be translated into the right language. I use the following code (C#) on the server to get the body of the email:
string mailbody = (string)HttpContext.GetGlobalResourceObject("Resource", "mailbody");
In my App_GlobalResources-folder I have a file containing the English translation called Resource.resx and for the Swedish translation Resource.sv.resx.
Many English users are now complaining about that they get the Swedish translation sent instead of the English translation. Every time I test this on my Android phones I get the right translation so it is hard for me to track this error down. Also this has been working great when connected from iPhone. Any ideas what can be wrong? Have anyone seen a problem like this?
The behavior you describes seem pretty odd. It seems to be related to Culture detection in your web service and of course web.config might play a role here.
However, setting culture and uiCulture to "auto" should detect the most desired culture from web browser, that is I don't think it should be Swedish for English user... I would suspect some strange fall-back rule.
Are you really sure your neutral-culture resources (Resource.resx) are in English (just to double check that)?
Maybe you have some overrides in Global.asax?
If the answer for both question is "it's OK", maybe try to modify settings to uiCulture="auto:en-US" so that language falls back directly to English (United States). With no other resources and neutral culture resources in English, it should, but...