Orchard.Localization / Tokens

Topics: Localization, Troubleshooting, Writing modules
Apr 4, 2012 at 3:17 PM

I added in tokens that allows accessing the LocalizationPart of a content item, but I ran into a problem.

The LocalizationPart is not the first time you save a new page, only after the 2nd save I get access to the part.

Can I access the LocalizationPart somehow whenever a new content item is created for the first time.

Having to save 2 times on every new page is not an option for our client.

May 24, 2012 at 10:43 AM

Anyone got an idea? This issue is starting to become relevant again for us.

May 24, 2012 at 5:36 PM

I don't understand the scenario. Can you elaborate what you are trying to accomplish ?

May 24, 2012 at 5:44 PM
Edited May 24, 2012 at 5:46 PM

I created a custom token that generates the culture prefix (as in for example /en/) based on the culture of the content.

Problem is that when I save the page for the first time, I cannot fetch the LocalizationPart.

By that I mean that .As<LocalizationPart>() returns null on the first save (or an object with no culture set, cannot remember, but I think it was 'null' the first time) but returns the actual part on the 2nd save.

Is it more clear now?

May 24, 2012 at 5:47 PM

When is this token used ? In Rules ? On what event if so ?

May 25, 2012 at 6:27 AM

In autoroute, to generate the url.


Like (example): {Content.CulturePrefix}/sometext/{Content.CultureId}


Where CulturePrefix could give '/nl' and CultureId be the id of the 'master' content ('parent' item with the default culture).

May 25, 2012 at 5:38 PM

That's clear now, thanks. Let me try to reproduce your scenario. 

Jun 14, 2012 at 2:31 PM

Hey, was this fixed?

Jun 14, 2012 at 2:48 PM

Not that I'm aware or I missed it.

Jul 6, 2012 at 2:45 PM

This should be partially fixed after this update of Orchard.Localization module is integrated. But I'm not sure if the LocalizationPart will always run (driver update method) before the culture token is resolved in the AutoroutePart.. In my installation with this module containing culture tokens it works for new items, but not when translating.

There could probably besome mechanism to prioritize content part execution... One that would enable developers to state when they want their content part drivers or handlers executed (in relation to others within a content type). LocalizationPart could have priority 1 in this case, Autoroute priority 10 (the lower the sooner). Maybe a feature request?

Jul 6, 2012 at 9:03 PM

@Dunross, there is already, first is the reference graph, then the Priority in Module.txt, for each feature.

Jul 7, 2012 at 2:09 PM
Edited Jul 7, 2012 at 2:09 PM

Well I inspected it a bit further and simply using priorities couldn't solve it because of a bug in Orchard.Localization module AdminController. I fixed it however and uploaded it to my pull request.

Oct 15, 2012 at 10:28 AM

(Dunross: I posted on your pull request comments and only now realized that maybe I should have posted here..so I'm sorry for the double-post)

I really like the idea of having translations has being the same content item instead of separate content items - it just makes more sense for me this way. 
I was trying to achieve this by making new code myself but I don't have the necessary skills with ASP.NET/Orchard yet, so I'm really grateful for your fixes..! =)

I've made all your changes on the Orchard.Localization module manually, but I'm having some trouble: when I create a content item (for example, a page) and I pick a culture for it, it still gets displayed on summary admin with "Culture: Undefined".

Do you have any idea if I'm doing something wrong or if you code still needs some fix?

Thanks in advance!

Oct 17, 2012 at 3:53 PM

I get a exception when I create a new content and try to set it's culture:

2012-10-17 16:46:45,559 [66] Orchard.ContentManagement.Drivers.Coordinators.ContentPartDriverCoordinator - ArgumentNullException thrown from IContentPartDriver by Orchard.Localization.Drivers.LocalizationPartDriverSystem.ArgumentNullException: Value cannot be null.Parameter name: virtualPath   at System.Web.VirtualPath.Create(String virtualPath, VirtualPathOptions options)   at System.Web.VirtualPathUtility.ToAppRelative(String virtualPath)   at Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy.ShapePlacementParsingStrategy.<>c__DisplayClass21.<BuildPredicate>b__15(ShapePlacementContext ctx)   at Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy.ShapePlacementParsingStrategy.<>c__DisplayClassf.<ProcessPlacementFile>b__8(ShapePlacementContext ctx)   at Orchard.DisplayManagement.Descriptors.ShapeAlterationBuilder.<>c__DisplayClass1b.<>c__DisplayClass1d.<Placement>b__1a(ShapePlacementContext ctx)   at Orchard.ContentManagement.Drivers.ContentPartDriver`1.Orchard.ContentManagement.Drivers.IContentPartDriver.UpdateEditor(UpdateEditorContext context)   at Orchard.ContentManagement.Drivers.Coordinators.ContentPartDriverCoordinator.<>c__DisplayClass10.<UpdateEditor>b__f(IContentPartDriver driver)   at Orchard.InvokeExtensions.Invoke[TEvents](IEnumerable`1 events, Action`1 dispatch, ILogger logger)

I don't know why this exception is being thrown exactly (do you guys know?) but made a "quick fix" for this: edit the placement.info and comment the following code:

    <Match Path="Admin/Localization/Translate/*">       

<Place Parts_Localization_ContentTranslations_Edit="-" />   


this way you can set the language of a content and it works. The problem is that when you click the "+ New translation", there is one extra dropdownlist on the page: 

- "This is the [ALL CULTURES]  variation of the content"

- "This is the [MISSING CULTURES] variation of CONTENT_NAME"


The first dropdown shouldn't appear but I couldn't fix this yet.

Any help on how to proceed would be appreciated! =)

Thanks in advance,


Oct 17, 2012 at 3:55 PM

Please file a bug.

Oct 17, 2012 at 4:16 PM

Done. Thanks! =)

Oct 19, 2012 at 3:23 PM
Edited Oct 19, 2012 at 3:26 PM

I made a pull request containing some of the changes of the original Dunross' pull request: only the AdminController.cs ones. Using this version you can use the module mentioned above ( https://gallery.orchardproject.net/List/Modules/Orchard.Module.Vitus.Localization ) to use tokens for autoroute. This should give you the basic stuff needed to set a website with multi language and on all my tests it was working without bugs.

Many thanks for Dunross, because the code's all from him. =)

Fork url: http://orchard.codeplex.com/SourceControl/network/forks/Jifu/localizationtokenfix