Multiple sites on one installation using different cultures

This is a place to discuss how to adapt mojoPortal to the needs of different cultures. Before asking questions here please first review the localization documentation.

This thread is closed to new posts. You must sign in to post in the forums.
9/20/2007 1:18:38 AM
Gravatar
Total Posts 16
www.CodeWise.nl

Multiple sites on one installation using different cultures

Joe,

I was wondering if it is possible to do the following:

I have one provider, where I have installed mojoportal (www.CodeWise.nl) Now I wanted the site to be in two languages (Dutch and English). If I change the culture in the web.config I'll get both sites in one language, or if somebody mixes it the site will be partially German and partially English.

I am able to create dns aliasses for the site, so I was thinking to create www-en.CodeWise.nl and www.CodeWise.nl. Then the only thing that is missing is that I'm unable to force the culture for one site to be nl-NL and for the other to be en-US. This is a setting that I feel should be set per site in the database.

Do you share this opinion? Can you build this? Or can I supply a patch for this to be added to mojoportal?

Regards,

Jelle Hissink

 

 

9/20/2007 10:07:18 AM
Gravatar
Total Posts 18439

Re: Multiple sites on one installation using different cultures

Hi Jelle,

It is currently a limitation in hosting multiple sites with a single installation that they all share the same web.config so any settings there are common accross them including the globalization settings. Default settings shown here for reference:

<globalization
culture="auto:en-US"
uiCulture="auto:en"
requestEncoding="utf-8"
responseEncoding="utf-8"
fileEncoding="iso-8859-15" />

Note that in the recommended default settings "auto" means use the preferred language of the browser and the en-US after the colon means if no resource is found for the browser language, then use en-US

Using these settings ASP.NET automatically sets the culture of the executing thread to the culture of the browser.

If you specify a different culture for the default after the colon, then the file you specify must exist and must not have any missing keys vs the en-US resource file or you will get null reference exceptions when a missing resource is encountered.

It seems appropriate to me to use the browser language if possible in all sites to ensure the user can read buttons and labels though it is possible to force a specific culture for all sites by removing the auto: part. Maybe in some cases it is desirable to do this but it seems like a corner case to me and I don't recommend it. Of course the language of the content is what it is in the db.

If you really want to implement support for it I will consider adding it if you follow these guidelines.

1. use web.config settings to override not site settings. It should only be configured by server admins not site admins so it should not be offered in sitesettings. I would have one setting to enableforcedculture and then one setting for each site like site1forcedculture= , site2forcedculture= , corresponding to site ids. If not found for given site don't override.

2. the place to implement override would be in Application_BeginRequest, it could be done in global.asax.cs but ideally if it can be done in an httpmodule that would be better so it can be unplugged completely.

3. Once you have determined whether to override and what culture to use doing the logic, then its really only 1 line of code to change the culture of the executing thread.

Thread.CurrentThread.CurrentCulture = someCultureInfoobject;

Joe

9/20/2007 3:29:54 PM
Gravatar
Total Posts 16
www.CodeWise.nl

Re: Multiple sites on one installation using different cultures

Joe,

I know about the workings and the configuration in the web.config file and the CurrentCulture / CurrentUICulture properties.

As I see it there are two main roads to allow localization:

  1. Force the content to be entered in every language that you wish to support.
  2. Setup a new site per supported language.

I know from experience that it is very tedious to follow the first road. The content and page structure must be entered and available in every language, database structure will get complicated quickly. And often the sites simply aren't the same in every language. You have to consider the handling of logo's, texts, support images in the templates. This is very complicated where different cultures meet (left-to-right, right-to-left, colors have different meanings in other cultures etc.).

This is why I generally try to take road 2. The problem I have with this and the auto setting that is default in mojoportal is that if a user chooses to see the Dutch version of a page, he shouldn't see the texts like 'Subject', he should see 'Onderwerp'. I know the auto setting and the mix of the cultures is a nice feature to have, however personally I could never find my way on a Thai site when the only things I can understand are buttons like 'OK' and 'Cancel'. 

The way I vision the setup of multiple sites to work is:

  • Setup one url per culture (e.g. www.mojoportal.com/en or www-en.mojoportal.com)
  • Ensure that if one uses the specified url all the content will be shown in that language

Another possible way could be:

  • Have one url to access the site (you will have multiple sites in the database though)
  • Save the selected culture in the session

This last approach looks more promissing, it is however also more complicated. It needs multiple sites in the database to have the same url. Each site will then have a culture assigned to it. Whenever the user loads a site, the site will now be selected based on the url in combination with the culture.

Based upon these assumptions I think it could be argumented that storing the culture in the site record in the database could be possible (as you have the url stored there also).

Can you give me some feedback on your view on this? (Other peoples oppinions and experiences are also participated in this discussion... Alexander maybe? )

Regards,

Jelle Hissink

 

9/20/2007 4:00:27 PM
Gravatar
Total Posts 18439

Re: Multiple sites on one installation using different cultures

Hi Jelle,

I agree with you on the second road being the way to go.

I just implemented support for forcing a specific culture per site as I suggested in my previous post. I will commit it to svn trunk in a few hours and then you can test it and let me know if it works correctly.

Once you have my updated code you will see I have added a setting in Web.config:

<add key="UseCultureOverride" value="false" />

You would set this to true, then you would need to add a setting for each of your sites like:

<add key="site1culture" value="en-US" />
<add key="site2culture" value="nl-NL" />

setting the culture to be used to a valid culture string and naming the param according to your siteids.

I don't recommend using session variables anywhere. This is easy to implement (at least in theory) and no need for session variables.

I added code to global.asax.cs Application_BeginRequest like this:

if (WebConfigSettings.UseCultureOverride)
{
SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
if ((siteSettings != null) && (siteSettings.SiteID > -1))
{
string siteCultureKey = "site" + siteSettings.SiteID.ToString(CultureInfo.InvariantCulture)
+ "culture";
if (ConfigurationManager.AppSettings[siteCultureKey]
!= null)
{
try
{
CultureInfo siteCulture
= new CultureInfo(ConfigurationManager.AppSettings[siteCultureKey]);
Thread.CurrentThread.CurrentCulture = siteCulture;
}
catch { }
}
}
}

This will be in svn trunk later this evening.

Thanks,

Joe

 

9/20/2007 4:18:50 PM
Gravatar
Total Posts 16
www.CodeWise.nl

Re: Multiple sites on one installation using different cultures

Man you are quick ;-)

That implementation would fix things for me for now, I'll just setup two sites, and add a flag icon to the template that refers to the other site.

The reason to bring up the "second road solution" is that not everybody has the luxury to setup multiple dns entries or virtual directories if you are using a hosted service.

The session variabele would then be necessary to allow the site to work from one url.

I'll be happy to test the new version. I'll look into it this weekend, as your evening will be tomorrow for me ;-)

Jelle

 

9/22/2007 12:39:21 PM
Gravatar
Total Posts 16
www.CodeWise.nl

Re: Multiple sites on one installation using different cultures

Joe,

there is a problem with the change you made, you need to set Thread.CurrentThread.CurrentUICulture also:
    CultureInfo siteCulture = new CultureInfo(ConfigurationManager.AppSettings[siteCultureKey]);
    Thread.CurrentThread.CurrentCulture = siteCulture;
    Thread.CurrentThread.CurrentUICulture = siteCulture;

With this change all is working. I will try setting up virtual directories also (instead of a new hostname).

Jelle

 

9/22/2007 1:02:16 PM
Gravatar
Total Posts 16
www.CodeWise.nl

Re: Multiple sites on one installation using different cultures

Virtual folders are working nicely ;-) I was thinking of a small change (although it might occur in a lot of places).

You have a lot of places where you put the site id in a cookie, session or cache name, e.g. logoff.aspx:

    string winliveCookieName = "winliveid" + siteSettings.SiteID.ToString(CultureInfo.InvariantCulture);

When this siteSettings.SiteID could be replaced with something like siteSettings.SiteSettingsID, it might be possible to allow for a user to stay logged in when you have multiple sites that are only setup to allow for localization. I was wondering about the effect this might have. This property could default to the SiteID.ToString(...) but it could be overridden by the web.config.

 

Jelle

PS:

I corrected some small errors in the Resources.nl.resx, I will send it to your e-mail account...

8/1/2011 8:56:26 PM
Gravatar
Total Posts 14

Re: Multiple sites on one installation using different cultures

Hello,

Is the method posted by Joe on 9/21/2007 still working. I tried and it didn't work and I am unable to find the code which  Joe was talking about in global.asax?

I think there is another alternative way to have each site its own culture

 

Regards
Tarek

8/2/2011 7:26:21 AM
Gravatar
Total Posts 18439

Re: Multiple sites on one installation using different cultures

Hi Tarek,

See Forcing a Specific Language

Hope that helps,

Joe

You must sign in to post in the forums. This thread is closed to new posts.