You can get the current culture 2 letter notation by doing Umbraco.CultureDictionary.Culture.TwoLetterISOLanguageName
Wrapped into an extension method so that the it language returns no path
public static class UmbracoHelperExtenstion
{
public static string CurrentLanguagePath(this UmbracoHelper umbracoHelper)
{
var currentLanguage = umbracoHelper.CultureDictionary.Culture.TwoLetterISOLanguageName.ToLower();
switch (currentLanguage)
{
case "it":
return null;
default:
return currentLanguage;
}
}
}
You can replace <a href="/product/0001">product</a> by <a href="@Umbraco.CurrentLanguagePath()/product/0001">product</a> And always have the product in the current language.
In your resolveRootByLocale you set the linked PublishedContent to the node based on the locale.
If my assumption is correct, this is the general productpage relative to your language
You can use this to generate the Full Url
<a href="@(Model.Content.Url)/0001">product</a>
Model.Content.Url generates the Url with a / at the end.
If this works, you don't need the hacky extension method I supplied earlier. (Might not work because of of the umbracoHideTopLevelNodeFromPath, not sure)
Href to Localized Content
Hi Everyone,
I Currently have a multilingual website with the following root nodes:
I chose to keep this setting:
in order to get the default root in italian, and access the english root by adding "en" to the site address, let say:
This, causes the issue when redirecting via anchor the the product page. How do I know what root to get?
What I did so far is: register the route handler for both, localized and non localized url, and resolve the correct path:
where 'resolveRootByLocale' is defined as follows:
Now, when redirecting to the product page, I have to prefix in html the localized root of the site I intend to use, let say:
or
I want to avoid prefexing the root locale. Do you guys have any clue on how to do this?
Hi and welcome to the Umbraco community!
You can get the current culture 2 letter notation by doing
Umbraco.CultureDictionary.Culture.TwoLetterISOLanguageName
Wrapped into an extension method so that the
it
language returns no pathYou can replace
<a href="/product/0001">product</a>
by<a href="@Umbraco.CurrentLanguagePath()/product/0001">product</a>
And always have the product in the current language.sweet! Thank you
No problem
I think I found an even beter solution today.
In your
resolveRootByLocale
you set the linked PublishedContent to the node based on the locale.If my assumption is correct, this is the general productpage relative to your language
You can use this to generate the Full Url
<a href="@(Model.Content.Url)/0001">product</a>
Model.Content.Url
generates the Url with a/
at the end.If this works, you don't need the hacky extension method I supplied earlier. (Might not work because of of the umbracoHideTopLevelNodeFromPath, not sure)
is working on a reply...