//- deletes custom culture for country identified by EIDSS country ID
        public static void UnRegister(string cultureCode, long countryID)
        {
            if (!CountryCodes.ContainsKey(countryID))
            {
                throw new Exception(string.Format("\'{0}\' - Unsupported country ID.", countryID));
            }
            if (!CultureExists(cultureCode, countryID))
            {
                throw new Exception(string.Format("Unsupported pair culture name - country ID."));
            }

            // unregister only earlier registered cultures
            string cultureName = FormCustomCultureName(cultureCode, countryID);

            try
            {
                if (IsCultureRegistered(cultureName))
                {
                    CultureAndRegionInfoBuilder.Unregister(cultureName);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("can't unregister custom culture {0}", cultureName);
                Debug.WriteLine("error: {0}", e);
            }
        }
 //- returns country abbreviation defined by countryID, null for incorrect (unsupported) countryID
 public static string GetCountryNameByID(long countryID)
 {
     if (CountryCodes.ContainsKey(countryID))
     {
         return(CountryCodes[countryID]);
     }
     return(null);
 }
        //- deletes all custom cultures intended for country identified by EIDSS country ID
        public static void UnRegister(long countryID)
        {
            if (!CountryCodes.ContainsKey(countryID))
            {
                throw new Exception(string.Format("\'{0}\' - Unsupported country ID.", countryID));
            }

            UnRegister(Core.SupportedLanguages.lngEn, countryID);
            UnRegister(Core.SupportedLanguages.lngRu, countryID);
        }
        //- creates all custom cultures intended for country identified by EIDSS country ID. Currently we should create en culture for each country and ru culture for Kazakhstan. This can be updated later
        public static void Register(long countryID)
        {
            if (!CountryCodes.ContainsKey(countryID))
            {
                throw new Exception(string.Format("\'{0}\' - Unsupported country ID.", countryID));
            }

            foreach (Tuple <string, long> cult in SupportedCustomCultures.FindAll(t => t.Item2 == countryID))
            {
                Register(cult.Item1, countryID);
            }
        }
 private static string ExtractCountryCode(ref string s, int digits)
 {
     if (s == "" || digits < 1)
     {
         return("");
     }
     if (s.Length < digits)
     {
         return(ExtractCountryCode(ref s, s.Length));
     }
     try {
         var n = s.Substring(0, digits).AsInt();
         if (CountryCodes.ContainsKey(n))
         {
             s = s.Substring(digits);
             return(n.ToString());
         }
     }
     catch { }
     return(ExtractCountryCode(ref s, digits - 1));
 }
        //- creates custom culture for country identified by EIDSS country ID
        public static void Register(string lang, long countryID)
        {
            if (!CountryCodes.ContainsKey(countryID))
            {
                throw new Exception(string.Format("\'{0}\' - Unsupported country ID.", countryID));
            }
            if (!CultureExists(lang, countryID))
            {
                throw new Exception(string.Format("Unsupported pair culture name - country ID."));
            }
            try
            {
                string cultureName = FormCustomCultureName(lang, countryID);
                if ((!IsCultureRegistered(cultureName)) && Core.SupportedLanguages.All.ContainsKey(lang))
                {
                    string oldCultureName           = Core.SupportedLanguages.All[lang];
                    CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder(cultureName,
                                                                                      CultureAndRegionModifiers.None);
                    // Populate the new CultureAndRegionInfoBuilder object with culture information.
                    CultureInfo ci = new CultureInfo(oldCultureName);
                    cib.LoadDataFromCultureInfo(ci);

                    // Populate the new CultureAndRegionInfoBuilder object with region information.
                    RegionInfo ri = new RegionInfo(oldCultureName);
                    cib.LoadDataFromRegionInfo(ri);
                    cib.CultureEnglishName = GetRegistrationCultureName(lang, countryID); //"English (Georgia)";
                    cib.CultureNativeName  = GetRegistrationCultureName(lang, countryID);
                    cib.RegionNativeName   = GetRegistrationCultureName(lang, countryID);
                    cib.RegionEnglishName  = GetRegistrationCultureName(lang, countryID);
                    cib.Parent             = ci;
                    cib.Register();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("can't register custom culture {0}-{1}", lang, countryID);
                Debug.WriteLine("error: {0}", e);
            }
        }