OP10 Localization contains extension methods and helpers to easily set up a multilingual site based on a by convention naming of the PropertyAlias. Unlike other packages, OP10 Localization does not provide a custom property editor for multilingual properties but instead maps the property to a language based on the PropertyAlias.
How to use
After installing OP10 Localization you can create localized properties by naming the property alias with an underline and the languages two letter ISO code:
For Umbraco to know the available languages, create all required languages in the Settings-Section. The first language is always the default unless the OPTEN:localization:defaultCulture appSetting is set in the web.config. The value of the setting can be the two letter ISO Code or the language name: "en" or "en-GB".
<add key="OPTEN:localization:defaultCulture" value="en-GB" />
Now you have to add hostnames to the root node. If you want to provide a site in English (default), French and German set following hostnames with associated cultures for the root node:
After everything mentioned above is set up, the user will be redirected to the relevant hostname according to their browser language if they access a page witheout the /en, /de or /fr url part.
In your Code, you can now access the multilingual property based on the current language of the request with the IPublishedContent extension method GetLocalizedValue instead of GetPropertyValue.
There is also a way to check if a multilingual Property has a value like HasValue: HasLocalizedValue
Examples
Get localized property value:
Get localized title (if the property alias is title_isoCode
Get localized Grid
Localized URLs
If you need to have localized URLs then create a new data type with the OPTEN.UrlAlias and add it to the document types which need to have localized urls (You don't have to create a property for each language).
The alias of the property needs to be optenUrlAlias.
The OPTEN.UrlAlias provides an input box for each language added in the settings section. You only have to type in a value if the url segment should differ from the default Umbraco one.
To get the localized url you can still use Umbraco's Model.Content.Url.
To get the url for a specific language you can use the extension method GetLocalizedUrl: Model.Content.GetLocalizedUrl("en")
Browser redirect
You can enable the browser language redirect in the web.config with <add key="OPTEN:localization:browserLanguageRedirect" value="true" />
Now all users that access the page without the language segment in the url will be redirected to the language based on their browser language.
Localized Controllers
To use localization in your custom API and Surface Controllers you have to to extend from LocalizedUmbracoApiController or LocalizedSurfaceController. You can also use the Attribute [Localized] on the controller.
For Localized API Controllers, you have to pass the language for the request. With jQuery you can do this like this:
$.ajaxSetup({
headers: { "accept-language": "@Request.GetCurrentUICulture().Name" }
});
Localized Error 404
To have localized Error 404 set it up according to https://our.umbraco.org/forum/developers/razor/33761-Display-404-page-from-razor-code#comment-124021 and then add <add key="OPTEN:localization:404" value="true" /> to the web.config.
Version History