/// <summary> /// Returns a valid culture name based on "name" parameter. If "name" is not valid, it returns the default culture "en-US" /// </summary> /// <param name="name">Culture's name (e.g. en-US)</param> public static string GetImplementedCulture(string name) { // Make sure it's not null if (string.IsNullOrEmpty(name)) { return(GetDefaultCulture()); // return Default culture } // Make sure it is a valid culture first if (!ValidCultures.Any(c => c.Equals(name, StringComparison.InvariantCultureIgnoreCase))) { return(GetDefaultCulture()); // return Default culture if it is invalid } // If it is one of our implemented cultures, accept it if (ImplementedCultures.Any(c => c.Equals(name, StringComparison.InvariantCultureIgnoreCase))) { return(name); // accept it } // Find a close match. For example, if you have "en-US" defined and the user requests "en-GB", // the function will return closest match that is "en-US" because at least the language is the same (ie English) var n = GetNeutralCulture(name); foreach (var c in ImplementedCultures) { if (c.StartsWith(n)) { return(c); } } // else // It is not implemented return(GetDefaultCulture()); // return Default culture as no match found }
protected void Application_Start() { ServiceConfig.RegisterServices(); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // --- Use implemented languages CultureHelper.SetImplementedCultures(ImplementedCultures.GetCultureCodes()); // --- Start background tasks BackgroundTaskConfig.StartBackgroundProcessing(); }