public IEnumerable<string> GetAvailableLocaleNames() { IList<string> availableLocaleNames = new List<string>(); bool success = false; if (!useOldApi) { var enumCallback = new LocaleManaged.EnumLocalesProcExDelegate( (localeName, flags, param) => { availableLocaleNames.Add(localeName); return true; }); success = LocaleManaged.EnumSystemLocalesEx(enumCallback, LocaleManaged.LOCALETYPE.LOCALE_SPECIFICDATA, 0, (IntPtr)0); } else { var enumCallback = new LocaleManaged.EnumLocalesProcDelegate( otherLocaleIdString => { var otherLocaleId = ConvertOldLocaleId(otherLocaleIdString).Value; availableLocaleNames.Add(LocaleIdToLocaleName(otherLocaleId)); return true; }); success = LocaleManaged.EnumSystemLocales(enumCallback, LocaleManaged.LCID.LCID_SUPPORTED); } if (!success) throw new InvalidOperationException("Getting system locales failed."); return availableLocaleNames; }
public uint? LocaleNameToLocaleId(string localeName) { if (!useOldApi) { var lpcData = new StringBuilder(256); lpcData.Append(localeName); int localeId = LocaleManaged.LocaleNameToLCID(lpcData, 0); if (localeId == 0) return null; return (uint)localeId; } else { uint? foundLocaleId = null; var enumCallback = new LocaleManaged.EnumLocalesProcDelegate( otherLocaleIdString => { var otherLocaleId = ConvertOldLocaleId(otherLocaleIdString).Value; if (LocaleIdToLocaleName(otherLocaleId) == localeName) { foundLocaleId = otherLocaleId; return false; } return true; }); if (!LocaleManaged.EnumSystemLocales(enumCallback, LocaleManaged.LCID.LCID_SUPPORTED)) throw new InvalidOperationException(String.Format("Getting locale ID for \"{0}\" failed.", localeName)); return foundLocaleId; } }