Constellation.Foundation.Globalization offers some syntax candy that allow developers to quickly ensure their content is in the correct regional context. This is a framework library designed to be expanded upon, but it is slightly opinionated. This library pre-dates the general availability of Sitecore Item Fallback within the core product, and provides an alternative way to manage “shared” content across multi-lingual sites.
- “Shared” content means content that appears on more than one Site in a Sitecore installation.
- Sitecore’s Language Fallback feature has not been turned on, and is not desirable.
- “Empty” Item Versions are not published, and are not desirable.
- Content that is regionally exclusive should be written in the local dialect.
ex: “pt-BZ” content is for Brazil audiences only, “pt-PT” content is for Portugal.
- Content designed to be shared should be written in the most generalized Language definition available.
ex: “en” content will show up on both an “en-US” and “en-UK” site but “en-US” content cannot be displayed on an “en-UK” site.
- It may be convenient for content authors if some sites in the system own the “canonical” language for content.
ex: the *.fr site owns the “fr” language, and content is authored in “fr” rather than “fr-FR”.
- If it is expected that there will be a repository of globally shared content, that content should only be maintained in the generalized version of all Languages supported by the system.
ex: Content would be authored under these language codes: de, en, es, fr, pt.
Constellation.Foundation.Globalization is managed via NuGet.
In Visual Studio, fire up the Package Manager console and install into any of your Sitecore projects:
PM> Install-Package Constellation.Foundation.Globalization
Source code available on GitHub.
All features are exposed through extension methods to common Sitecore objects.
Item Extension Methods
This method is used to ensure that the provided Item is delivered in the language that is most appropriate to the request. The following tests are performed, and the Item returned if these conditions are matched in this order:
- The current Version matches the target language argument
- A Version in the target Language is available
- A Version in the generalized Language is available
If no conditions are matched,
null is returned. When using the solution according to the assumptions described above, this call needs to wrap every Item before it is sent to the presentation layer to ensure that the appropriate language is being displayed and that Items that do not adhere to the Language rules are not included for display.
Checks to see if the Item has a Version in the target language supplied by the argument. This check can be used to ensure “empty” Items are filtered from further processing logic.
Language Extension Methods
Sitecore’s Language object doesn’t hold all of the details available on the Language Item in the Content Tree. This method will return the Language Item from the content tree.
Assumes that the Display Name for all Languages in sitecore/system/languages have been adjusted for every Language available in the system. Returns the Display Name for the language in that language.
Example: “fr” might be Named “French” to English authors, but the Display Name in “fr” will be set to “français”. When making this call from any context language, the result will always be “français”.
Use this method to create easy-to-read language pickers in your site’s navigation.
SiteInfo Extension Methods
Extends Sitecore’s SiteInfo configuration parameters. You can now supply a
supportedLanguages attribute on your
<site/> definitions. This should be a comma-delimited list of ISO codes representing which Languages are valid for that site.
You can use this to:
- Compute links for an on-site Language selection tool
- Create alternative-language links for SEO
- Restrict access to URLs based upon whether Item Versions exist in the expected Language