-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented CookieRequestCultureStrategy & other changes:
- Updated sample to enable setting/clearing cultures via cookie - Cache CultureInfo construction as it's not built into .NET Core - Cache RequestCulture construction as they're immutable anyway and created lots per app if the middleware is running - Fix issue where by invalid culture names were not handled (it crashed) - Handle the pesky favicon.ico request from browsers - Ignore .vs folder
- Loading branch information
1 parent
ec8ede5
commit 944c84b
Showing
11 changed files
with
255 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Microsoft.AspNet.Localization/Internal/CultureInfoCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Globalization; | ||
|
||
namespace Microsoft.AspNet.Localization.Internal | ||
{ | ||
public static class CultureInfoCache | ||
{ | ||
private static readonly ConcurrentDictionary<string, CacheEntry> _cache = new ConcurrentDictionary<string, CacheEntry>(); | ||
|
||
public static CultureInfo GetCultureInfo(string name, bool throwIfNotFound = false) | ||
{ | ||
// Allow empty string values as they map to InvariantCulture, whereas null culture values will throw in | ||
// the CultureInfo ctor | ||
if (name == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var entry = _cache.GetOrAdd(name, n => | ||
{ | ||
try | ||
{ | ||
return new CacheEntry(CultureInfo.ReadOnly(new CultureInfo(n))); | ||
} | ||
catch (CultureNotFoundException ex) | ||
{ | ||
return new CacheEntry(ex); | ||
} | ||
}); | ||
|
||
if (entry.Exception != null && throwIfNotFound) | ||
{ | ||
throw entry.Exception; | ||
} | ||
|
||
return entry.CultureInfo; | ||
} | ||
|
||
private class CacheEntry | ||
{ | ||
public CacheEntry(CultureInfo cultureInfo) | ||
{ | ||
CultureInfo = cultureInfo; | ||
} | ||
|
||
public CacheEntry(Exception exception) | ||
{ | ||
Exception = exception; | ||
} | ||
|
||
public CultureInfo CultureInfo { get; } | ||
|
||
public Exception Exception { get; } | ||
} | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
src/Microsoft.AspNet.Localization/Internal/CultureUtilities.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.