multilingual site

Topics: General, Localization
Feb 22, 2011 at 9:20 PM

Hi Everyone,

I am creating a new site and one of my requirements is to be multilingual.

I managed to enable translation using Orchard in the widget level. Is it possible

using the dashboard and a module to do it for the hole site or I need to go to 

code level?

 

Thank you in advance

Coordinator
Feb 22, 2011 at 9:22 PM

Can you give a little more details on how exactly you want it to work?

Feb 22, 2011 at 10:33 PM
Edited Feb 22, 2011 at 10:39 PM

I would like to have  two flags( English and German) on the upper left side of the site.

By default all Title and page content will be in English. But when I press the German flag

all the page titles and the content will switch to German and all the subsequent request

of the user will be in German (may there will be a mirror German page for its of my pages

for example the Contact --> Kontact) until the user presses again the English flag..

Coordinator
Feb 22, 2011 at 10:42 PM

OK, so in order to do that, you would probably wire those flags to a controller action that sets some cookie with the chosen culture. Then you'd implement an ICultureSelector that looks at this cookie and returns the culture accordingly. The tricky part will be to filter out the navigation menu for just the current culture as I think this is not implemented yet. If you're willing to try to fix it, the hierarchical menu module might give you some ideas.

Other than that, multiple local versions of content is supported through the localization module that you can download from the gallery.

Feb 22, 2011 at 11:15 PM

Thank you for you prompt response!

Mar 2, 2011 at 7:54 PM

The same problem, and I decided to create a module for this. I took into account Bertrand`s suggestions, and here is my solution:

  1. Create a part (and widget ), that displays registered cultures and provides ability to select one of them. Once new culture is choosen, it`s being stored in the cookies. The user will be able to add the widget to the Default layer.
  2. Create class that implements ICultureSelector and processes the cookie.
  3. Introduce logic for filtering content with Localization part based on current culture. Filtering must work for front-end and for the admin panel as well (usability purposes).

The main question is where is a right place to inject filtering logic.

I`m new to Orchard, and don`t know it`s architecture very well. I hope to take some feedback and advices for this solution. Thanks.

Mar 4, 2011 at 7:08 AM

Hey, 1 & 2 is accomplished! Still not sure how to implement filtering. It seems that there is a lot of stuff need to be reimplemented. Please, help!

Mar 4, 2011 at 10:25 AM

@ermarkovich I have the very same problem. Can you share your module somewhere on codeplex so that we can join forces for filtering logic. Maybe it would be wise to fork main branch since we will probably have to touch core and framewk projects. What do you think?

Mar 4, 2011 at 3:36 PM

Hi @IPavlovi,

1. I created a project http://orchardculturepicker.codeplex.com/. Known issue: When culture is changed, module does not redirect user automatically to correct content route. Example:

current url: "/contact-us" (default culture route)
->pick culture de-DE
Expected result: current url changed accordingly to localized content route ("/contact-us-de-DE" or so).
Actual result: current url remains the same

===Any ideas how to fix it?====

2. It`s good idea to fork main Orchard branch, especially Orchard.Localization module.There is really no way to use this module (as it is today) in the real-world scenarious. I will contact you via CodePlex.

Question to the Orchard Team: is there any changes were made since 1.0.20.0 on the dev branch in order to solve this issue?

Mar 9, 2011 at 11:37 AM

Hi Everyone,

CulturePicker module v.1.0.0 released!

http://www.orchardproject.net/gallery/List/Modules/Orchard.Module.Orchard.CulturePicker

Mar 15, 2011 at 2:17 PM

I'm currently looking to localize all my orchard website, and i meet a problem concerning the HomePage...

Just one Homepage is allowed, so when you change of culture on the homepage, you loose all the widget of the HomePage Template ...

 

Have you an idea to fix this issue ?

 

thanks !

Mar 15, 2011 at 2:31 PM

This happens because your TheHomePage layer rule is url "~/". When you change culture, the HomePage url becomes another and layer is no longer active. It`s expected behaviour. For example, you may want to provide localizations for you widgets as well.

I would suggest you creating a new layer for localized url and copying all widgets to it.

Mar 15, 2011 at 3:33 PM

Yeah it work great !

And what about the home link ? actually I'm using : @Href("~/")

but when i change of language, i need to change the generation of this link or i will every time be redirected to default language page ....

i dont  want to make a big algorithm which will slow my pages ....

Mar 15, 2011 at 4:04 PM

Could you clarify please, where do you use @Href("~/")?

Mar 15, 2011 at 4:09 PM

I use it in my header which is not connected to sitemap or main menu.

 

more over, the first link of my main menu is a  home link and lead to the root (empty url)

but if i change the current culture, this one wont change his link,. (hope i will avoid that with the next version of the hierarchical menu which will be localized)

 

so i have several issue like that :S.

 

I dont understand why culture management is not a orchard core function...

Mar 16, 2011 at 8:11 PM

Unfortunately, using @Href("~/") on the multilingual website causes inconsistent behaviour. I realized that I have the same issue on my website. Will try to provide some workaround for this in the forthcoming release of the CulturePicker.

Mar 17, 2011 at 10:17 AM

Works great!

But, what about localization for widgets? Somewhere on forum was an empty branch with it... And I've got the same problem. Is there any solution without coding?- only UI modifications.

Thanks!

(Sorry for my English)

Mar 17, 2011 at 10:52 AM

You need to create a new layer, that will contain localized versions of your widgets.

Layer rule must specify the localized route. Example: url "~/products-de-DE".

Mar 18, 2011 at 9:46 AM

Solved! Thanks!

Mar 18, 2011 at 3:11 PM

I'm currently trying to change localisation

 

my module inherit from FilterProvider, IActionFilter.

 

When i go on my website with /home/en url, i would like to check culture (it work fine) and to change it if the current culture is not the same as the culture from the url.

Inspiring myself from Culturepicker, i update the cookie which contains the current culture, but, it don't change my website culture even if i have implemented an ICultureSelector with public CultureSelectorResult GetCulture(HttpContextBase context) using my cookie...

I think it's due to the operation order but ...

 

an idea ?

Mar 18, 2011 at 3:31 PM

What the priority do you assign to the returning CultureSelectorResult ?

Mar 18, 2011 at 3:34 PM

i've just put the same as your culture picker

because it will use the same cookie

Mar 18, 2011 at 4:00 PM

You don`t need to implement ICultureSelector, if you are already using CulturePicker. All that you need to do is just to save a cookie with proper name and format, that CookieCultureSelector will be able to process.

Or I don`t understand you correctly?

Mar 18, 2011 at 4:02 PM

no i think you are right but it just dont work, does the cookie need specific culture like en-US to work  or i can use two letter iso code like en ?

perhaps the mistake come from this.

Mar 18, 2011 at 4:08 PM

I`m not sure, but would recommend you to use full culture name like "en-US".

Mar 18, 2011 at 4:31 PM
Edited Mar 18, 2011 at 4:47 PM

Ok i will test it.

 

Thanks !

oh i have another question ;

if i set this type of link for my article :

mypage/en & mypage/fr

and i use the culture picker (when i'm on this page)

i'm redirected to : mypage/ChangeCulture with an 404 error.

How can i fix it because using only link like this : mypage-en ... is very painful for users

 

 

 

 

(in some page i have this when i use the culturePicker :

Value cannot be null.
Parameter name: serviceKey

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: serviceKey

Source Error:

Line 15:         bool TryResolve<T>(WorkContext workContext, object serviceKey, out T instance ) {
Line 16: if (workContext != null) {
Line 17: var key = new KeyedService(serviceKey, typeof (T));
Line 18: object value;
Line 19: if (workContext.Resolve<ILifetimeScope>().TryResolve(key, out value)) {


Source File: C:\Projects\HelpWebSite\src\Orchard\Mvc\OrchardControllerFactory.cs    Line: 17)

 

EDIT: i've test two letter iso and specific, and it work fine with specific (not with two letter iso code)

the problem is the page need a refresh to use the good culture (if a change is needed after cookie update)

i think i have to update the cookie earlier but how and where ? (i'm currently doing it in my module which inherit from FilterProvider, IActionFilter

Mar 18, 2011 at 5:28 PM
Edited Mar 19, 2011 at 10:38 AM
OlinCamber wrote:

Ok i will test it.

 

Thanks !

oh i have another question ;

if i set this type of link for my article :

mypage/en & mypage/fr

and i use the culture picker (when i'm on this page)

i'm redirected to : mypage/ChangeCulture with an 404 error.

How can i fix it because using only link like this : mypage-en ... is very painful for users

Could you please submit this issue to the CulturePicker issue tracker?

 

Regarding 

Value cannot be null.
Parameter name: serviceKey

I`m not sure that this is related to CulturePicker. Seems to be a very popular problem with Orchard.

UPD

I`ve tested it. ArgumentNullException is also caused by CulturePicker. Will be fixed.

Mar 21, 2011 at 10:56 AM

thanks for the fix !

 

still one problem

 

my filter module (inheriting from FilterProvider, IActionFilter) try change culture if the current culture is different from the language token in the url (by updating culture cookie from the culture picker)

my problem is : the cookie is updated as i want  but  i need to refresh one more time before the displayed culture change because i think my module is executed too late in the orchard process.

 

Where can i do this action to make my page working great ?

thanks !!

Mar 21, 2011 at 12:12 PM

If you update culture cookie, it will have an effect ony for the next web request.

What I would suggest you to do, is to create another culture selector (by inheriting from the ICultureSelector), that will return culture based on language token in the request URL. Please note that Priority of the CultureSelectorResult should be greater, than Priority of the CookieCultureSelector.

Mar 21, 2011 at 3:51 PM

Hello all,

First of all I'm new in orchard. :p

I'm trying to create a multilingual site but having some problems on how to filter the main menu by language (culture).

My site will have pt-PT (default) and (en-US)

Can you bring me some light on how to create my menu?

Thanks in advance

Mar 21, 2011 at 4:33 PM

CulturePicker module provides the main menu filtering. However, there were some bugs detected for the several scenarios. New release (1.1.x) with bugfixes will be available in a next few days.

Mar 29, 2011 at 1:30 PM
ermakovich wrote:

If you update culture cookie, it will have an effect ony for the next web request.

What I would suggest you to do, is to create another culture selector (by inheriting from the ICultureSelector), that will return culture based on language token in the request URL. Please note that Priority of the CultureSelectorResult should be greater, than Priority of the CookieCultureSelector.

It work just fine :)

 

thanks a lot ;)

Mar 30, 2011 at 9:35 AM
Edited Mar 30, 2011 at 9:39 AM

Hello i have another question concerning multi lingual orchard website:

 

I want to make a fallback on the implemented language

for example if i call the following page:

/home/pt

(which do not exist)

i want to be redirected on home/en (for example)

 

Is their a way to make an handler in  my plugin to manage it ? (I'm currently looking at route class and httpasyncHandler class)

thanks !!

Coordinator
Mar 30, 2011 at 11:24 PM

You can implement IRouteProvider.

Mar 31, 2011 at 12:01 PM
Edited Mar 31, 2011 at 12:12 PM

Is it possible to alter the route to include the culture rather than having it in a cookie etc?

Rather than having the culture on the end of the url e.g.

path/tocontent/item-de-DE

We could have:

de-DE/path/tocontent/item

I know there are comments similar in the thread already, but does anyone have a full 'noddy' guide for how to implement the UI culture picker (drop-down or images), localizing the menus/system items and the routing...a nice web blog would be great ;)

Mar 31, 2011 at 12:35 PM
Edited Mar 31, 2011 at 12:59 PM

currently i use the both

use the culturepicker for the drop down list with cultures

to use culture in url, i currently use a class inheriting from : ICultureSelector

where i check the culture in the url and return the new culture.

 

but if the page in this culture, or the culture do not exist, you will get a 404 error that's why i'm trying to make new routes.

Apr 1, 2011 at 9:31 AM

Hi all, as I said earlier ,I'm trying to make a routelike the following:

new RouteDescriptor {
                    Priority = -100,
                    Route = new Route(
                        "{culture}/{*path}",
                        new RouteValueDictionary {
                            {"area", "AvpAuthenticationProvider"},
                            {"controller", "CultureRedirect"},
                            {"action", "RedirectFromCulture"}
                        },
                        new RouteValueDictionary {
                            {"path", _cultureRoutablePathConstraint}
                        },
                        new RouteValueDictionary {
                            {"area", "Routable"}
                        },
                        new MvcRouteHandler())
                }

if no route is used, i want to use this route (so priority -100) and i want to make a constraint where i look for my url with one of the _cultureManager.GetSiteCulture();

if it match i will redirect the page on the first valid page with valid culture,

else i will redirect on the main page with a route which will manage 404 error.

 

My problem is : i was trying to inherit from IRoutablePathConstraint and i was using the _path generated by SetPaths where i was making my different possible url.

but if I inherit from, IRoutablePathConstraint my constraint will be used where IRoutablePathConstraint in other orchard route and not just in my route like i want.

 

So i'm trying to inherit from IRouteConstraint but i dont want to generate every time i come in my route the list of available path

 private readonly IRepository<RoutePartRecord> _repository;
  var slugs = _repository.Fetch(r => r.ContentItemVersionRecord.Published && r.Path != "" && r.Path != null).Select(r => r.Path);

So how can i do to get all the available path in my IRouteConstraint and am I going in the right direction to make my route and my constraint ?

 

 

Thanks !

Apr 1, 2011 at 10:22 AM

Have a look at the Orchard.Core.Routable module and the way the RoutablePathConstraint stores a dictionary of paths; and the RoutablePathConstraintUpdator also uses a background process to keep the list up-to-date.

A lot of this is repeated in Orchard.Blogs for the BlogPathConstraint etc.

Those should give you an idea of "best practice" for this kind of thing.

Apr 1, 2011 at 10:25 AM

Yes after posting i've done this search and i'm currently trying to use the same implementation than the blog module.

now without result , but i try to don't loose hope :p

does my route will break (set a  breakpoint on it) every time the request dont match the other routes ? or there is a cache system ?

Apr 1, 2011 at 10:32 AM

I'm not sure what you're saying isn't working.

I'd have thought your route constraint should breakpoint every time.

Hmm ... shouldn't a negative priority mean your route always gets hit before any other routes? (Not just when no other route is found)

Apr 1, 2011 at 10:48 AM
Edited Apr 1, 2011 at 11:29 AM

i've try many things and i think i have a little problem in my code:

i've try to set priority to -100 , 0 , 1 , 100 or to remove the priority parameter and my breakpoint is always hit at the first call to a page.

so i think orchard load all available routes first to be faster at every request.

 

When The Match method of my RouteConstraint is hit, it return true, but my route action controller is never hit ...

and this action is a redirect action so the call fail and return an error ...

 

An idea ?

 

PS : thanks for helping me !

 

 

 

EDIT: now it work great ! :)

but i dont know how does priority on RouteDescriptor work.

Can anybody can explain it ?

 

because after my route is used and redirect to the new url (which is normaly a valid orchard item url)

my Match in my route constraint is hit another time (0_0) so I'm forced to make a trick ...

So i would like to correct it with clean route

 

thanks!

Apr 20, 2011 at 1:42 PM

Do you have downloadable code so that I can see what you've done? I'm still missing knowledge on the concepts of Orchard routing and localization... :(

May 5, 2011 at 6:34 PM

Sorry, about dumb question... But:

I've got a problem, several pages created with "subroute" like:

1.   /en/content/page1

2.   /content/page1

The problem is, if I change culture  from (/content/page1 ) it switches to (/en/content/page1) like a charm, but fail when I need to switch back...

Any ideas?

Thanks!

May 5, 2011 at 7:06 PM
makozlov wrote:

Sorry, about dumb question... But:

I've got a problem, several pages created with "subroute" like:

1.   /en/content/page1

2.   /content/page1

The problem is, if I change culture  from (/content/page1 ) it switches to (/en/content/page1) like a charm, but fail when I need to switch back...

Any ideas?

Thanks!

Seems that you use old version of the Culture Picker module. The similar issue was fixed in the v 1.1.2.

May 9, 2011 at 4:07 PM

Yeap, you was right. Forgot to update it. Thanks.

Editor
Jul 20, 2011 at 4:09 AM
Edited Jul 20, 2011 at 4:13 AM

I am experiencing the problem spoken about on this thread concerning the culture picker not always redirecting to the proper url. Sometimes it works...sometimes it doesn't. Any thoughts? For example, /products-services/news-es-es and I change the culture to french, it processes the culture change but the url remains the same.

CulturePickerVersion: 1.1.3.1
OrchardVersion: 1.1.30

Thoughts?

Oct 3, 2011 at 2:02 PM
OlinCamber wrote:

Ok i will test it.

 

Thanks !

oh i have another question ;

if i set this type of link for my article :

mypage/en & mypage/fr

and i use the culture picker (when i'm on this page)

i'm redirected to : mypage/ChangeCulture with an 404 error.

How can i fix it because using only link like this : mypage-en ... is very painful for users

I'm using Orchard 1.2.41 and CulturePicker 1.1.3.1 and I'm having excatly the same problems as described above. What should I do?

I appologize if this has already been answered but I'm under huge time preasure and I'm reading this thread over and over again and don't see the solution. 

Coordinator
Oct 3, 2011 at 6:32 PM

Did you try contacting the author of CulturePicker through the gallery?

Oct 3, 2011 at 10:17 PM

It's weird that you are experiencing exactly the same issue, since this bug was fixed in the past. Please, provide some more details (exact steps, urls) and submit this issue to the http://orchardculturepicker.codeplex.com issue tracker. I will try to help.

Nov 16, 2011 at 9:37 AM

Hello! I've installed CulturePicker and now, in my website, my users can choose one of the three language I've selected. I don't understand how I can translate the content of the page; now I can change the language but the content page is the same. Do I need to change some parts of the code? Which ones? Do I need other modules after I've installed CulturePicker?

Thanks

fre

Nov 16, 2011 at 9:47 AM
Edited Nov 16, 2011 at 9:48 AM
Hi,

You should translate your pages as you regularly do it with the Localization module. So, Localization module need to be installed.

You can take a look at this screencast: http://www.screenr.com/q1y (Localization and Culture Picker modules already installed)
Nov 16, 2011 at 11:14 AM

Ok, thanks. Now I have another problem: I have a list of books and the Menu Text is "Books available"; when I enabled the 4 features of "Picker Culture" into modules, my list of books disappears! Furthermore disappears also my content type called Event (in which I inserted a map), in these page I can't see anything, I've introduced in them: tags, body part...but really, there's nothing!!! when I disable the 4 features of "picker culture" my list of books and my event return with their tags, comments, bodyparts... How is it possible? How can I see my entire contents when picker culture is enable?

thanks

fre

Nov 16, 2011 at 3:20 PM

You will see only content that belongs to the current culture.

Nov 16, 2011 at 3:23 PM

If you use widgets and url-based layer rules, please make sure that your layer with widgets does not become inactive when you are switching to a different culture.

Nov 16, 2011 at 3:32 PM
Edited Nov 16, 2011 at 4:05 PM

and how can I see what culture belong my contents? How can I add other cultures to them? Furthermore you said  "please make sure that your layer with widgets does not become inactive when you are switching to a different culture." but how can I make sure? in which part of my dashboard can I see widget active/inactive with the culture choise?

thanks again

fre

Nov 17, 2011 at 11:00 AM

Ok, I solve my problems: I needed to add "+ New translation" at every content I would to see in my website. Furthermore I had to add "+ New translation" at every part of the content type for example at every post of the blog, not only at the blog content type.

bye fre

Jan 2, 2012 at 2:56 PM

Hi Everyone,
I'm studying this topic how to create multilingual menu - the goal is having one menu which redirects you to proper translation of page. I've read above that culture picker can display only menu items with current culture. I created new menu and filled it with "Fill menu with existing items" button, but after changing the culture all of them were in my menu. I'm sitting on it form hours and cannot find a solution. Does anybody have any idea?

Thank you in advance

Jan 2, 2012 at 3:40 PM

Please, make sure that you are not using Advanced Menu module. It's not compatible with Culture Picker currently.

Jan 3, 2012 at 2:54 PM

Yes, indeed. I used it, but now I'm not.
But there's one more issue to solve. After delete Advanced Menu modules (deleting, not only disabling) the "show on main menu" option disappeared - during creating new page I cannot show it there. I've tried the same situation on new, testing project. The navigation works good up to installing Advanced Menu module... After removing it nothing's repaired.

Feb 17, 2012 at 12:51 PM

If you add "Culture Layer" - AdvancedMenu will work with CulturePicker.

Feb 24, 2012 at 9:25 AM
makozlov wrote:

If you add "Culture Layer" - AdvancedMenu will work with CulturePicker.

Can you explain how it's working with CulturePicker?