This project is read-only.

Pages/Translations don't know their own language?

Topics: Core, Localization, Troubleshooting
Apr 29, 2014 at 9:11 AM
Edited Apr 29, 2014 at 9:12 AM
I'm working on a multilingual site. I create content for my main language and use the "add translation" button to create translated versions. While creating a translated version I can select the language of the translation. On the frontend I can click the available translations. Everything works find in this regard.

However: The content I'm currently viewing does not seem to know its own language!

I have a very simple Language picker for my header section. It lists all available translations just fine. I want the button that shows the list of available translations to show the current language.

In the Document.cshtml there is this part:
<html lang="@WorkContext.CurrentCulture" class="static @Html.ClassForPage()">
I tried to use WorkContext.CurrentCulture but it is the same on every page! It's always be "main" language I set in the settings menu.

I this a bug or intentional?

When I go to a page that is setup to be the swedish, hungarian, german, etc. translated version of a content page, the lang attribute has to be set to the corresponding language.

How can I do that? There must be a way for a page to know what language it uses...

Thank you
Apr 29, 2014 at 9:43 AM
We (at consider this behavior correct.

In short, we think that the CurrentCulture reflects the 'UI' culture, and is separate from the culture (or cultures) from rendered content items.

What (for example) if would create a projection that both renders a dutch AND english page? What would be the CurrentCulture then? ;)
Apr 29, 2014 at 10:04 AM
I can see your point, the ability to have access to a "UI culture" might have some uses. However the way it's currently implemented is not good in my opinion. The lang attribute is clearly stated to be an indicator for the language of the content, not the browser (the browser should use the lang information to adjust its rendering).

I try to adhere to web standards whenever possible. In this case I think it is (or should be) very simple.

So my question still stands: How can I access the language of the current page?

It's already done in the backend; Editing a translation page will give you the info:
Content Localization
This is the fr-FR variation of Your Page Title Here.
PS: In your example I think the best practice would be to use different lang attributes for each of the content blocks. The lang attribute is not limited to the who page but can (and should) be used for content blocks, too.
Apr 29, 2014 at 11:51 AM
Yeah, maybe the top lvl lang should be the UI culture still, and the content items could be rendered in containers with their own, correct language attached.

This all said, I still think that CurrentCulture should be the 'UI' culture.

If you can get the list of translations (and their url) why don't you just match the current url with the urls from the list, to 'find' the correct active one?
May 11, 2014 at 8:49 PM
Edited May 11, 2014 at 8:49 PM
Hello Konadi, I am starting with Orchard and need a similar simple "Language picker" to switch between languages in my site.
Can you tell me which one you are using ? I have tried RM.Localization & Culture.Picker but they are both giving me problems in Orchard 1.8.
May 12, 2014 at 8:06 AM
I have tried both modules you listed but they didn't seem to work in Orchard 1.8.
So I use the language tools that came with the standard installation.

I reworked my site structure to explicitly include the culture/language of the pages into the URL/permalink. for english pages, for french, etc.
I then create "fake" culture layers that check if the url contains "/en/", "/fr/", "/de/", etc.
May 12, 2014 at 11:48 AM
Thanks for your reply. I want to try your approach to localize my site.
I suppose you are using an Autoroute pattern to automatically create the URL/Permalink ? If so can you tell me what pattern you have entered ?
Also for the culture layers, what is the Layer Rule you have added ?
May 12, 2014 at 11:56 AM
Edited May 12, 2014 at 11:57 AM
My URLs/Permalinks look like this (example of 1 page + 2 translations):
http://localhost:30321/OrchardLocal/en/products/audio-cleanup/ (English, "base" page)
http://localhost:30321/OrchardLocal/fr/produis/audio-cleanup/ (French translation)
http://localhost:30321/OrchardLocal/de/produkte/audio-cleanup/ (German translation)
I fake a "culture layer" by using these layer rules:
~ is the base url of the website (in this case "http://localhost:30321/OrchardLocal"). So it checks if there is "/en/", "/fr/", or "/de/" directly after the base url. The * at the end means, that there can be anything (including nothing) and the rule will still return true.

Hope this helps.

(edit: code formatting)
May 12, 2014 at 12:17 PM
Your layer rules are helpfull but I have a question regarding the URL/Permalinks:
Do you enter these manually when creating each content item or do you use an Autoroute pattern ?
For example in the content definition for "Page" - expanding the Autoroute part allows entering a pattern. Can we place a token here to automatically add the /en/ or /fr/ cultures ? If you used this what did you enter ?
I will hand over the site to end-users and need to avoid relying on them to specify the URL/Permalink manually.
May 12, 2014 at 12:21 PM
I enter the url manually, other parts of the url are translated, too, so the effort has to be made anyway (products/produits/produkte).
I have no idea if/how to modify the autorouting to preset parts of the permalink, sorry. But maybe someone else can help.