Closed morgrowe closed 3 years ago
Hi @morgrowe ,
I know I have to work more on documentations, but it is time matter :)
There is different variations for .AddXDbLocalizer<...>
:
// Add XLocalizer with database support using the default built-in entity models
.AddXDbLocalizer<TContext>( ops => { ... });
// Add XLocalizer with database support using the default built-in entity models,
// and use defined translation service type
.AddXDbLocalizer<TContext, TTranslator>(ops => { ... });
// Add XLocalizer with database support using customized entity models,
// and use defined translation service type
.AddXDbLocalizer<TContext, TTranslator, TResource>(ops => { ... });
First two methods will use the default entity model (defautl db set) which is XDbResource
. But if you want to use custom db set you have to use the latest method.
.AddXDbLocalizer<DashboardDbContext, MyTranslationService, DomainLocalizationResource>((opts) =>
{
opts.UseExpressMemoryCache = false;
});
IStringLocalizer
it will search for localized values inside the default db set. When you don't define the default db set in startup it will be XDbResource
by default, but when you specify any custom db set in startup it will be used.// In this case IStringLocalizer will search for localized values in XDbResource
.AddXDbLocalizer<TContext>( ops => { ... });
// In this case IStringLocalizer will search for localized values in XDbResource
.AddXDbLocalizer<TContext, TTranslator>(ops => { ... });
// In this case IStringLocalizer will search for localized values in TResource
.AddXDbLocalizer<TContext, TTranslator, TResource>(ops => { ... });
IStringLocalizer<T>
it will search for localized values inside the db set of type T directly.No problem. I really appreciate all the time and effort you've put into this tool. The documentation answers the grand majority of my queries, too. :)
I changed my .AddDbLocalizer to:
.AddXDbLocalizer<DashboardDbContext, ITranslator, DomainLocalizationResource>((opts) =>
{
opts.UseExpressMemoryCache = false;
});
And now my page renders without an exception. Thank you!
I'm not using the ITranslator feature at the moment. I tried passing null
as the second parameter but it didn't like it. Is it ok to just pass ITranslator
?
Thank you very much!
Morgan
You are welcome @morgrowe
Instead of passing ITranslator
you can use the already available DummyTranslator
and set auto translate to false:
.AddXDbLocalizer<DashboardDbContext, DummyTranslator, DomainLocalizationResource>((opts) =>
{
ops.AutoTranslate = false;
opts.UseExpressMemoryCache = false;
});
The dummy translator will throw an exception if auto translate is set to true.
You have thought of everything. That's perfect, thank you very much. :)
Morgan
Hi Ziya
This exception (pasted at the end) is thrown whenever I use an EditorTemplate. For example:
I think it's saying it can't find the
XDbResource
entity in myDbContext
. I'm not using theXDbResource
entity directly, I've created my own classes that implementIXDbResource
. This has worked perfectly when using theIStringLocalizer
in my controllers.My DbContext looks like this:
In my Startup.cs:
Any idea what's going on? I've probably misconfigured XLocalizer. Maybe XLocalizer look specifically for the XDbResource DbSet when attempting to localize EditorTemplates?
Thanks, as always. Morgan