By Cathy Dew
How to serve up a specific language independently of the country code
In a previous article about customizing cultures with Kentico, we outlined a custom solution that provides our clients the ability to have “global” content that spans all active cultures, and still provide “firewalled” localized content to each. Today we are going to discuss a different problem with running multicultural sites – how to serve language specific content using a single culture to all appropriate language-country codes matching only by language.
There are multiple countries that speak the “same” language
One of the challenges with multi-cultural sites is serving the “same” language to different countries. With Kentico, by default, you activate each target culture (language + country) irrespective of the language spoken and if there are countries that share the same language you don’t “share” translated content between them. When you have multiple cultures activated, the page content and assets are distinct from each other – even though they share the same page / URL.
Granted even though these countries speak the same language from an internet language code perspective, the languages themselves are not 100% the same. And, therefore, you’ll want to ensure that your translations are country neutral. For example, for all Spanish language countries, the Mexican version of Spanish appears to be the most neutral for Spanish readers and is therefore the primary translation focus before idiom standardization and clean up.
That said, how do we get multiple cultures to share the same language translations without activating and managing all the cultures that share the same language and reducing our translation and page management costs?
Hacking the Culture Code Engine – not for the faint of heart
As we discussed previously, culture codes are really two codes combined: the language code and the country code. Kentico receives a paired code when the browser visits a page and requests content. Based on the culture code, Kentico serves up the culture specific page – if it exists, or provides the page requested in the default culture.
The first thing you need to decide is which culture will be the primary culture for the target language. Using our previous language example, Spanish is currently assigned to 19 countries. (Microsoft hosts a page showing the full list of language – country code pairings.) We can select anyone of these ES Language – Country pairings for activation in Kentico. To extend our example, we’ll activate ES-MX.
The next step is hijack the Alias field associated with the selected culture. Within Kentico Admin, you can edit the alias field within Localization -> Spanish -Mexico (Culture). Add “es” to the Culture Alias. Hijacking this field means you cannot use the alias for adding the language as part of the page’s URL / path. We discuss these configuration options in our Extending Kentico’s Reach series of posts:
The reason we flag our target culture (ES-MX) is we need to identify which Culture Code is identified as the default culture for Spanish requests and we don’t want to extend the Kentico Culture table and update the existing Stored Procedures and Portal Engine code. By using the Alias Culture field, we ensure that needed modifications in this area are limited to adding text to a field.
The next step is to extend the Kentico Page Request Events, and assign the Culture Code on-the-fly to ES-MX when the Spanish language is requested, irrespective of the country code. The logic flow for this decision tree is:
Designing the above code segment is not hard, but requires familiarity with Kentico Event Processing and the available Port Engine APIs to collect the Culture data needed and update the internal Preferred Culture object. The tricky part is making sure that our code executes as close to the front of the processing pyramid as possible. Too late, and many of the culture decisions have been made and can’t be switched out, therefore, we setup our code to be appended to the Begin. Execute event life cycle via the Page Init event.
What does this customization get us?
At the end of the day, this little customization allows us to serve up Spanish (via the ES-MX Culture) for all 19 different Spanish-Country codes available. We can do this for any language we want to support and has multiple countries that speak it. E.g. German – 5 Countries, French – 6 Countries, English – 13 Countries.
The simplicity of the customization means we are pretty future proof, since changes to how Kentico deals with culture are far and few between, and we can utilize the culture by-pass only when we need it. Additionally, the processing cost is very low even though this decision must be made with every page call.
2Plus2 is a Kentico Gold Partner and would love to help you get the most out of your Kentico system. Go online to schedule a free consultation with our team or call 510-652-7700 today.