Class ReroutedStringLocalizerFactory
- Namespace
- BlazOrbit.Localization.Shared
- Assembly
- BlazOrbit.Localization.Shared.dll
An Microsoft.Extensions.Localization.IStringLocalizerFactory wrapper that redirects resource lookups
from a source assembly to a sidecar *.Translations assembly.
public sealed class ReroutedStringLocalizerFactory
- Inheritance
-
objectReroutedStringLocalizerFactory
Remarks
The default Microsoft.Extensions.Localization.ResourceManagerStringLocalizerFactory resolves
IStringLocalizer<T> by reading typeof(T).Assembly and looking
for an embedded resource manifest under {T.Namespace}.{ResourcesPath}.{T.Name}.
That couples the .resx files to the same assembly that defines T.
This factory keeps the consumer-facing API identical — components still inject
IStringLocalizer<BOBCultureSelectorResources> (or any other anchor type) —
but the resource manifest is loaded from a separately versioned translations assembly.
The mapping is configured via LocalizationSettings.TranslationsAssemblies:
keys are source-assembly simple names, values are target-assembly simple names.
For an anchor type Foo.Bar.MyType in source assembly Foo.Bar mapped to
translations assembly Foo.Bar.Translations, the rewritten lookup becomes
Foo.Bar.Translations.MyType. After the inner factory adds the
Microsoft.Extensions.Localization.LocalizationOptions.ResourcesPath prefix, the final manifest name is
Foo.Bar.Translations.{ResourcesPath}.MyType — so the translations project
places its .resx under {ResourcesPath}/MyType.resx with no special pinning.
Constructors
ReroutedStringLocalizerFactory(IStringLocalizerFactory, IReadOnlyDictionary<string, string>)
public ReroutedStringLocalizerFactory(IStringLocalizerFactory inner, IReadOnlyDictionary<string, string> assemblyMap)
Parameters
innerIStringLocalizerFactoryassemblyMapIReadOnlyDictionary<string, string>
Methods
Create(string, string)
Creates an Microsoft.Extensions.Localization.IStringLocalizer.
public IStringLocalizer Create(string baseName, string location)
Parameters
baseNamestringThe base name of the resource to load strings from.
locationstringThe location to load resources from.
Returns
- IStringLocalizer
The Microsoft.Extensions.Localization.IStringLocalizer.
Create(Type)
Creates an Microsoft.Extensions.Localization.IStringLocalizer using the System.Reflection.Assembly and System.Type.FullName of the specified System.Type.
public IStringLocalizer Create(Type resourceSource)
Parameters
resourceSourceTypeThe System.Type.
Returns
- IStringLocalizer
The Microsoft.Extensions.Localization.IStringLocalizer.