This project is read-only.

Using RM.Localization with Orchard CMS

If you never heard about Orchard CMS, I strongly recommed you at least look at it.
All information about that you can find on official Orchard CMS site.
I suppose that you already have installed Orchard.

You have 2 ways to install this module:

  1. Easiest and right: go to ‘Dashboard > Modules’, find ‘RM.Localization’, install from feed and enable it;
  2. More affordable: clone from CodePlex module page and enable from ‘Dashboard > Modules’.

I describe first variant as more appropriate for most users.

Let’s go forward.

Little bit theory: by default, Orchard has only one ICultureSelector implementation – it’s SiteCultureSelector. It means that you can select only one culture in one time.

To fix it I implemented three additional selectors:

  1. Browser culture selector – automatically select culture from browser settings;
  2. Cookie culture selector – user can manually select current culture;
  3. Shadow culture selector – add aliases for one or more supported cultures.

Each culture selector has priority. SiteCulture Selector has lowest, BrowserCultureSelector has middle and CookieCultureSelector has high priority.

It works in following way:

  1. Get culture from CookieCultureSelector. If it returns null then no user culture selected and fallback to (2)
  2. Get culture from BrowserCultureSelector. It checks information about browser and tries to get culture. If culture is in supported list – returns it, else return null and fallback to (3)
  3. Get culture from SiteCultureSelector. It returns selected culture from site settings.

The shadow culture selector overrides CultureManager functionality and try find current culture alias from supported cultures list.

Example:

Let’s your site has 2 supported cultures: en-US (site culture) and ru-RU. For visitors from Ukraine or Belarus (almost people understand russian) would be more appropriate to show content in ru-RU. Yes, they could easialy select culture manually by picker, but it’s not so comfortable. In this case you can assign ru-RU as shadow (or fallback) culture for uk-UA (Ukraine) and be-BY (Belarus). So, BrowserCultureSelector returns uk-UA for visitor from Ukraine and ShadowCultureSelector returns ru-RU, but not en-US as default behaviour.

Move to practice.

First, you need enter on site:

img1

Go to ‘Dashboard’ and select ‘Modules’ menu:

img2

Select ‘Gallery’ tab, enter ‘localization’ into serach field and push ‘Search’ button:

img3

Install and enable ‘Localization’ module. This module is dependency of RM.Localization and needs for proper functioning:

img4

Back to ‘Modules > Gallery tab’, enter ‘rm.localization’ into search filed and push ‘Search’ button:

img5

Install ‘RM.Localization’ module and enable all features:

img6

Go to ‘Content > Content Types tab’, look for ‘Page’ content type:

img7

Click ‘Edit’ link, scroll down and look for ‘Localization’ part:

img8

If you didn’t find that, just add it by ‘Add Parts’:

img9

After, go to ‘Setting’ and follow by link ‘Add or remove supported cultures for the site’:

img10

Select culture in combobox, as example ‘ru-RU’ and click ‘Add’ button. As result, was added new supported culture:

img11

Next step, go to ‘Content > Content Items’, look for home page and click ‘+ New Translation’. For default installation it’s ‘Welcome to Orchard!’:

img12

Enter translations for all appropriate fields. Select ‘ru-RU’ in combobox. Click ‘Publish Now’ button:

img13

img14

Back to ‘Content’. Be sure that translation was added successfull:

img15

So, you are ready to test home page localization in work. Click ‘Your site’ link and see website in English.

img16

Change default browser culture settings. I show it with IE. Go to menu ‘Tools > Internet Options > Languages’ and click ‘Add…’ button:

img17

Select ‘ru-RU’ culture and move it up:

img18

Save setting by clicking ‘OK > OK’. Refresh page by F5 and see result:

img19

There you can see BrowserCultureSelector in work. Move forward and give user ability to select Language manually.

You have to add ‘Culture Picker’ on your layout. Go to ‘Dashboard > Widgets’, select appropriate ‘Zone’ and click ‘Add’:

img20

Select ‘Cookie Culture Picker’:

img21

Enter title ‘Languages’ and click ‘Save’:

img22

img23

Click ‘You Site’ link to see result:

img24

Play with selecting language. A ‘Reset’ link is needed to reset cookie and fallback to BrowserCultureSelector.

Now, look how shadow culture selector works. Click ‘Reset’ link to reset cookie.

Go to broser settings ‘Tools > Internet Options > Languages’, add uk-UA (Ukrainian):

img25

Save setting by clicking ‘OK > OK’. Refresh page by F5 and see result:

img26

But you may want to see page in Russian instead of English (default site culture).

Go to ‘Dashboard > Settings’, scrolldown page and look for ‘Shadow culture rules’:

img27

Each row contain separate assignment. Enter following text: ‘ru-RU:^uk|uk-UA$’ and click ‘Save’:

img28 

Click ‘Your Site’ link and see result:

img29

Please help me make this module perfect!

If you got bug or have idea how to improve existing functionality, please write issues or add your idea to discussions.

Thanks,

RichMaxim.

Last edited Feb 26, 2013 at 8:18 PM by richmaxim, version 6

Comments

FleXML Oct 27, 2016 at 12:14 PM 
I've now used 'en-US:^-$' so I check for a - but maybe it's not clean or ideal, but seems to work.

FleXML Oct 27, 2016 at 12:04 PM 
Hi great work, but I can't figure out how to set a fallback culture for all other languages in the world. So if a italian of polish visitor comes in, how can I give the default 'en-US' ? I don't want to add 200 rules, so more looking for a default / wildcard RegEx.

Vincent

Sennerstad Mar 24, 2014 at 9:54 AM 
Hi RM! Thanks for a great module.
I have used the module alot recently but i have encountered a problem. After installning the module i had a cached culture stored, then i temporary disabled all RM modules. Upon enabling them again i dont get the admin panel to display nor can i delete the cached culture via settings.

I have no idea what causes this.

Any tips?

robbaralla Mar 15, 2014 at 12:05 AM 
Hi RM,

What if I don't want to display the (country) behind the language link? I looked around a bit in your code but couldn't find it. Then again being able to display flags would be even better; it makes the list a bit more compact.
Thanks for a great job

robbaralla Mar 14, 2014 at 11:24 PM 
Great module, not just for functionality, but also for the clarity of explanation. works in 1.7.2 Thank you - thank you - thank you!

gkumik Mar 1, 2013 at 8:18 PM 
Very good module!