Changing language by domain (localization/globalization) - localization

I have a webforms website that needs to be set either to danish (DK) or swedish (SE) language depending on the domain (.se/.dk). Theres both some global and local resources. Mostly local. The language needs to be set once, global for the entire application, once the clients lands on the page (session start).
The auto settings in web.config will not be sufficient, cause some of the users will have english settings on their browsers, launching the default resources (which is danish). Not optimal if youre a swedish user with english settings.
If i run an overrided method of InitializeCulture() on for example default.aspx and ask for host/domain and set the langauge from that, the culture will be reset to the default resources as soon as I leave the default page. Setting the culture in Session_Start in global.asax will do the same thing. Works on landing page, resets on sub page.
Whats the right way to do this?
I guess the question comes down to: Do I really have to call InitializeCulture() on every single page?

Apparently yes - I have to call InitializeCulture on every single page:
InitializeCulture() on every single page necessary?

Related

Specifying language for Umbraco members

I'm creating an internal CMS blog site using Umbraco 7. We need to show the content based on member's language preferences. Every member has to login to the site to view the blog content. Therefore I'm using Umbraco member functionality to cater that scenario.
I noticed there is a language selection while creating users for the back-office. Also, I'm aware of creating multiple site contents to support each language.
I went though https://our.umbraco.com/documentation/tutorials/multilanguage-setup/ article. But this is not what I'm looking for.
Are there any other way to specify Mermeber's language preference and show the content based on that after login to the system?
Or any other thoughts?
You could add a "Preferred Language" property to your Member type (just a Content Picker I guess). Then you would have to do something in the front-end as well, perhaps like this: https://24days.in/umbraco-cms/2014/razor-language-switcher/ . You'd also have to add code that updates the member property to whichever start node whenever a new one is selected, as well as a redirect mechanism so whenever a member enters the site they'd end up on the correct site.
If you're asking if all this exists already - in a package or something - I don't think so :-/

How to perform dynamic URL rewrite...in code

I am being asked if I can setup a way to - on the fly - dynamically do a URL rewrite.
My experience with URL rewriting has been primarily using essentially static web.config files where I knew ahead of time what the conditions were I was supporting. But in this case, I'm working with a partner who is sending me data about their clients and when a user of my site gets sent to one of those pages, they'd like me to rewrite the URL so that it looks like their client's URL and not mine.
Example: the search my site for Jim's auto shop, when I display my (their) content about Jim's auto shop, the URL wouldn't appear to be on my site, it would show "www.JimsAutoShop.com" when it's really on "wwww.mysite.com/JimsAutoShop"
I suppose every time our partner pushes we data where this is needed, I could rewrite the web.config file adding a section for that case, but I really don't know that that's a good idea. is there a way to essentially do this dynamically via code, where when I query my db from a search and see I need to mask the URL, I could do that?
Tech wise, i do not have access to IIS, I'm on a shared server running IIS and my primary application stack is Coldfusion10. Thanks
I don't believe this is possible. By the time your server side language gets the code, everything has been processed on the web server. There is nothing to rewrite. You could technically do this with Javascript but it would just be visually, it wouldn't actually be changing the URL. (Not sure you could visually change the domain, but I don't see why not. I've done it before with other parts of the URL). Here is how you would do that essentially: https://developer.mozilla.org/en-US/docs/Web/API/History_API
If this needs to be done though, the web.config route is the way to go. I had an application where when data was updated using certain forms in the app, I would grab the web.config and edit one of the rewrite maps.
But I'm not so sure that is what you need. If you want the domain www.JimsAutoShop.com to just pull files form your server, just edit the DNS to point to your server. Rewriting/Redirecting isn't needed. That is how sites are supposed to work.

Global i18n for social app in Rails

I'm creating a social app that may have different languages. I don't want to follow the pattern described in the Rails manual that makes use of different URL parameters for different languages. For example:
http://example.com/pt/books
I want to set things like this:
When an user enters the site (not registered), the locale is automatically defined by the browser language profile. (Probably the current locale will be saved in a cookie). If there isn't a language that matches the browser language then the default will be english.
When the user fills the registration form, the current language provided by the browser will be saved in the database in the users table, so even if the browser's default language is different from the logged user's default language, the last will be the main language. This time the locale won't be saved in the cookies.
The LOGGED user will have the option to change the language in a configuration page. This will affect the database entry.
The VISITOR user will have the option to change the language in the home page. This will affect the cookie. There will be probably a route to change this option, like:
http://example.com/changelanguage/en
So, what's the best and simpler way to create something like this?
Check out the locale_setter gem, it should do exactly what you're after.

Multiple languages in an ASP.NET MVC 3 (Razor) application

In my current project, on the main page I can switch language (FR|NL|UK).
All the texts are in ressources (.resx) files. The language code (FR, NL, UK) I need to use is in myMode.
How can I do to set all the : #HTML.Label( ....)
Thanks,
When you change language you need to change the current UI culture. You also need to track the user language preferences somewhere (route, cookie, session, ...). Here's a nice guide that I would recommend you reading.
I agree with the previous answer, that you have to change the current UI culture. On drop down change, you can store the language in cookie. And then using this cookie you can set the current UI culture. Depending on the culture, the application will pick up text from resource files depending on language selection.

Why is my language switching automatically in ASP.NET 2.0?

I am working on an ASP.NET 2.0 web solution which currently runs en-GB and zh-HK languages as the 2 current languages for the site. Others will be added at a later date.
One of the requirements is that the user can choose to override the language displayed to another language. Therefore users in Hong Kong can view the site in English and vice versa.
My 2 resource files are
Resources.resx (for English - default translations)
Resources.zh-HK.resx (for Chinese)
The site performs this logic
Load user details
Check if user has overridden the preferred language
If they have, set the Thread.CurrentThread.CurrentUICulture to this language.
If they haven't, use the browsers default.
This is implemented in the following code:
//This method is written in a base page, which all pages in the site derive from
protected override void InitializeCulture()
{
User user = /*Load custom user object...*/;
string threadLanguage = Thread.CurrentThread.CurrentUICulture.IetfLanguageTag;
//If the browser is using a different language,
//but the has chosen a preferred language,
//change the CurrentUICulture over.
if (!threadLanguage.Equals(user.Language, StringComparison.OrdinalIgnoreCase))
{
CultureInfo userLanguageCulture = CultureInfo.CreateSpecificCulture(user.Language);
Thread.CurrentThread.CurrentUICulture = userLanguageCulture;
}
base.InitializeCulture();
}
I have also configured the web.config to pick up the uiCulture automatically with
<globalization uiCulture="auto"/>
For some very very odd reason, some users (even en-GB users) are finding the language is switching over the zh-HK for no reason whatsoever - sometimes between pages! I have added some debugging code to these pages which should reveal more information in the coming days. All it has revealed so far is that users are not necessarily from zh-HK, some are from zh-CN or zh-TW. Although this might help, because en-GB users are seeing zh-HK I think it is just a red herring.
What I have noticed is that the switch over occurs on page content (those inheriting from the base page, which the IntializeCulture() method exists). The custom user controls I have written do not experience this problem and appear in the correct language configured by the user. Therefore a page would have combinations of both English and Chinese content - eek!
Can anyone give guidance as to if I am coding this correctly, or an alternative way of approaching the requirements.
Thanks in advance,
Dominic
P.S. This is an intermittent problem and not a permanent. There seems to be no common action that replicates this issue. It just - happens.
P.P.S Here is an image of the problem in action:
Update 23 Sep 09:
After trying to change it to Page.Culture, I am still having more intermittent problems.
I have a couple of ideas at why this could possibly be occurring, but am unable to justify my 'hypothesis':
We are using IIS 5.0 Isolation Mode, meaning only aspnet_wp.exe is running and not w3wp.exe for each IIS instance.
Reporting Services is also running on the server, generating reports for Hong Kong.
The fault occurs more frequently when the site was under heavy load - I assume due to large reports being generated.
Apart from that, I do not know what else could cause the problem. I would show another screenshot, but the problem is identical and did appear in the same place as the previous screenshot showed.
Update 25 Sep 09:
I think we I might have solved it. In our Web.config, there is a tag that was configured as follows:
<globalization uiCulture="auto" culture="auto"/>
After removing that, after initial testing, it has yet to turn up!
Update 13 Oct 09:
The problem has turned up again :-(
Update 26 Oct 09:
It seems that if another user of the site changes their preferred language, it affects all other users on the site! Although their preferred language is set, somehow someone else's language switch affects the other users of the site!
Shouldn't it be using Page.Culture, not Thread?
After a long, long time I finally worked out why this problem occurred.
The site started off as a frameset.asp, hosting 3 .NET frames - top, middle, bottom. What I noticed, is that .NET generated 3 sessions, and therefore any changes only affected one frame.
In a way, it doesn't completely explain why only parts of the page were working, but it has resolved quite a few issues regarding some of the odd Repsonse.Redirects we were going.
In summary, the frameset.asp, was replated with a frameset.aspx, which generates a single cookie / Session ID for all frames.

Resources