This is how I approached custom languages.
- Register your custom language in .net.
- Add custom language to
/AppConfig/LangauageDefinitions.config
- Add your custom language item in
sitecore/system/Languages
, u should see your custom culture info in "Choose a predefined language code" dropdown now.
Step1:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(SitecoreBlog.SitecoreCustom.Globalization.Language.RegisterLanguages), "Register")]
namespace SitecoreBlog.SitecoreCustom.Globalization.Language
{
public class RegisterLanguages
{
private class CustomCulture
{
public CustomCulture(string isoName, string fromCulture, string displayName)
{
IsoName = isoName;
FromCulture = fromCulture;
DisplayName = displayName;
}
public string IsoName { get; set; }
public string FromCulture { get; set; }
public string DisplayName { get; set; }
}
/// <summary>
/// Registers the custom languages required by the solution
/// </summary>
/// <remarks>
/// When this code runs it will need the following permissions on the host system:
/// - modify rights to "C:\Windows\Globalization" as it needs to create the .nlp file for the custom culture
/// - full control rights to the "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CustomLocale" registry path as it needs to the corresponding entry for the custom culture
///
/// If these fail then you will get an exception. If you resolve the issue and retry then the OS can get confused as the .nlp file may exist but the registery key doesn't.
/// In this situation you will need to remove the .nlp and/or the registry key so the code can start from stratch.
///
/// Once this has been run successfully, you will find that the language will appear in the list of predefined languages in Sitecore.
/// </remarks>
public static void Register()
{
//if you add new custom cultures, you need to add that in /AppConfig/LangauageDefinitions.config
var customCultures = new List<CustomCulture>() {
new CustomCulture("pt-mx", "fromCulture", "Protugese (Mexico)"),
new CustomCulture("en-mx", "fromCulture", "English (Mexico)")
//etc
};
var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
try
{
foreach (var customCulture in customCultures)
{
if (!allCultures.Any(culture => string.Equals(culture.Name, customCulture.IsoName, StringComparison.CurrentCultureIgnoreCase)))
{
var cib = new CultureAndRegionInfoBuilder(customCulture.IsoName, CultureAndRegionModifiers.None);
cib.LoadDataFromCultureInfo(new CultureInfo(customCulture.FromCulture));
cib.LoadDataFromRegionInfo(new RegionInfo(customCulture.FromCulture));
cib.CultureEnglishName = customCulture.DisplayName;
cib.CultureNativeName = customCulture.DisplayName;
cib.RegionEnglishName = customCulture.DisplayName;
cib.RegionNativeName = customCulture.DisplayName;
cib.Register();
}
}
}
catch (Exception e)
{
throw new Exception(@"Unable to register custom locales. Check app pool has modify rights to C:\Windows\Globalization directory and full control rights to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CustomLocale registry path.", e);
}
}
}
}
Make sure you have given right permissions. see comments for which
folders.
Step2:
Add a patch file like below:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<languageDefinitions>
<languages>
<language id="pt" region="mx" codepage="65001" encoding="utf-8" charset="iso-8859-1" icon="flags/16x16/XXX.PNG" />
<language id="en" region="mx" codepage="65001" encoding="utf-8" charset="iso-8859-1" icon="flags/16x16/XXX.PNG" />
</languages>
</languageDefinitions>
</sitecore>
</configuration>
t have certain languages? using your example es-br, pt-br, es-br.There are two portuguese languages(Brazil and Portugal). Using es-br assumes that site in Brazil for example should have a spanish version. Doesn
t it make sense to think in terms of languages and set which version should have a default language? In this example Brazil would have pt-br. If you want to see the spanish version just change it to es-ES for example.