33
44using System . Diagnostics . CodeAnalysis ;
55using System . Globalization ;
6- using System . Linq ;
76using System . Runtime . InteropServices . JavaScript ;
87
98namespace Microsoft . AspNetCore . Components . WebAssembly . Hosting ;
@@ -63,7 +62,7 @@ public virtual async ValueTask LoadCurrentCultureResourcesAsync()
6362 throw new PlatformNotSupportedException ( "This method is only supported in the browser." ) ;
6463 }
6564
66- var culturesToLoad = GetCultures ( CultureInfo . CurrentCulture ) . Union ( GetCultures ( CultureInfo . CurrentUICulture ) ) . ToArray ( ) ;
65+ var culturesToLoad = GetCultures ( CultureInfo . CurrentCulture , CultureInfo . CurrentUICulture ) ;
6766
6867 if ( culturesToLoad . Length == 0 )
6968 {
@@ -73,25 +72,34 @@ public virtual async ValueTask LoadCurrentCultureResourcesAsync()
7372 await WebAssemblyCultureProviderInterop . LoadSatelliteAssemblies ( culturesToLoad ) ;
7473 }
7574
76- internal static string [ ] GetCultures ( CultureInfo cultureInfo )
75+ internal static string [ ] GetCultures ( CultureInfo ? cultureInfo , CultureInfo ? uiCultureInfo = null )
7776 {
7877 var culturesToLoad = new List < string > ( ) ;
7978
79+ if ( uiCultureInfo == null )
80+ {
81+ uiCultureInfo = cultureInfo ;
82+ }
83+
8084 // Once WASM is ready, we have to use .NET's assembly loading to load additional assemblies.
8185 // First calculate all possible cultures that the application might want to load. We do this by
8286 // starting from the current culture and walking up the graph of parents.
8387 // At the end of the the walk, we'll have a list of culture names that look like
8488 // [ "fr-FR", "fr" ]
85- while ( cultureInfo != null && cultureInfo != CultureInfo . InvariantCulture )
89+ while ( ( cultureInfo != null && cultureInfo != CultureInfo . InvariantCulture ) || ( uiCultureInfo != null && uiCultureInfo != CultureInfo . InvariantCulture ) )
8690 {
87- culturesToLoad . Add ( cultureInfo . Name ) ;
91+ if ( cultureInfo != null && cultureInfo != CultureInfo . InvariantCulture )
92+ {
93+ culturesToLoad . Add ( cultureInfo . Name ) ;
94+ }
8895
89- if ( cultureInfo . Parent == cultureInfo )
96+ if ( uiCultureInfo ? . Name != cultureInfo ? . Name && uiCultureInfo != null && uiCultureInfo != CultureInfo . InvariantCulture )
9097 {
91- break ;
98+ culturesToLoad . Add ( uiCultureInfo . Name ) ;
9299 }
93100
94- cultureInfo = cultureInfo . Parent ;
101+ cultureInfo = cultureInfo ? . Parent ;
102+ uiCultureInfo = uiCultureInfo ? . Parent ;
95103 }
96104
97105 return culturesToLoad . ToArray ( ) ;
0 commit comments