meta info

Custom Resource Provider

By Ziya Mollamahmut

Resource providers are responsible for doing read/write operations for the resource files. XLocalizer has built-in support for .resx, .xml file types. Additionally it has support for DB with EF (requires XLocalizer.DB).

Extending source types

You can use any custom file/db type for storing localized strings by implementing IXResourceProvider interface for file based types (e.g.: json, csv, ...etc.) or IDbResourceProvider interface for DB sources.

File based sources

A good sample is the built-in XmlResourceProvider. All you have to do after implementing your custom provider is to register it in startup:

services.AddSingleton<IXResourceProvider, MyCustomProvider>();

services.AddRazorPages()
        .AddXLocalizer<LocSource>(...)

DB sources

You can have a look at the EFDbResourceProvider, it has been built with EF support, but you can create your own DB resource provider by implementing IDbResourceProvider and registering it in startup:

services.AddSingleton<IXDbResourceProvider, MyCustomDbProvider>();

services.AddRazorPages()
        .AddXDbLocalizer<ApplicatonDbContext, GoogleTranslateService>(...)