Thursday, July 14, 2011

How to create new language codes that's not available in Manage Website Languages

Sometimes the operating system doesn't have all the language codes that you need on the server you run your EPiServer solution. One way to solve that, is to create an console application which you run on the server with argument for the new langauge code based on one language code that already exists on the server.

Create a console application and copy this code:

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Text;
   5:  using System.Globalization;
   6:   
   7:  namespace CreateLanguage
   8:  {    
   9:      public class CreateLanguage
  10:      { 
  11:          public CreateLanguage()
  12:          {
  13:          }
  14:   
  15:          public CreateLanguage(string inputLine)
  16:          {
  17:              SetLanguage(inputLine);
  18:          }
  19:   
  20:          private void SetLanguage(string inputLine)
  21:          {
  22:              if (!String.IsNullOrEmpty(inputLine))
  23:              {
  24:                  string[] LanguageCode = inputLine.Split('_');
  25:   
  26:                  string copyLanguageId = LanguageCode[0];
  27:                  string newLanguageId = LanguageCode[1];
  28:                  string newLanguageName = LanguageCode[2];
  29:   
  30:                  //* Get the base culture and region information
  31:                  CultureInfo cultureInfo = new CultureInfo(copyLanguageId.ToString());
  32:                  RegionInfo regionInfo = new RegionInfo(cultureInfo.Name);
  33:   
  34:                  //* Create a locale 
  35:                  CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder(newLanguageId.ToString(), CultureAndRegionModifiers.None);
  36:   
  37:                  //* Load the base culture and region information
  38:                  cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(cultureInfo);
  39:                  cultureAndRegionInfoBuilder.LoadDataFromRegionInfo(regionInfo);
  40:   
  41:                  //* Set the culture name
  42:                  cultureAndRegionInfoBuilder.CultureEnglishName = newLanguageName.ToString();
  43:                  cultureAndRegionInfoBuilder.CultureNativeName = newLanguageName.ToString();
  44:   
  45:                  NumberFormatInfo nfi = cultureInfo.NumberFormat;
  46:                  
  47:                  cultureAndRegionInfoBuilder.NumberFormat = nfi;
  48:   
  49:                  //* Register with your operating system
  50:                  cultureAndRegionInfoBuilder.Register();
  51:              }
  52:          }
  53:      }
  54:  }

After compiling the code, then run a command prompt under administrative priviledges, where you type something like this: CreateLanguage.exe "en-EN" "en-RO" "English (România)"

Once you've run this program, fire up EPiServer in Admin mode, select 'Manage Web Site languages' from Config-tab, click 'Add language' and the new local will be ready to use.

PS: If you run EPiServer CMS 6 you will get a bug unless you write to EPiServer support and ask for a bug fixed EPiServer.dll. On EPiServer CMS 5 this works just fine. :-)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.