AspNetCoreLocalization
AspNetCoreLocalization copied to clipboard
Add/Delete culture data
I have two question. In the production,
- What is the correct way to delete all your data for a culture?
- What is the right way to add new culture data? without importing csv, from the admin panel.
Hello @damienbod , are you still developing this project?
Sorry for the slow answer, busy at the day job
Hi @abircan yes, you could just use EF Core with a new context, or use the existing to create your queries to delete, add in anyway you want.
Greetings Damien
Hi , i found it much faster to do it from DB side so i created a stored procedure and i just call it from my code ,my procedure below add new culture to the site , simply copying all existing word in new language ,but no translation
Create procedure [dbo].[usp_syCreateSiteCulture]
(
@NewCulture nvarchar(15) -- new culture to be used ex 'ar-eg'
)
As
Begin
INSERT INTO [dbo].[tblLocalizationRecords]
([ResourceId]
,[ResourceKey]
,[Value]
,[LocalizationCulture]
,[UpdatedTimestamp]
,[FriendlyName])
SELECT Distinct
[ResourceId]
,[ResourceKey]
,[Value]
,@NewCulture
,GetDate()
,[FriendlyName]
FROM [dbo].[tblLocalizationRecords] Orgi
Where LocalizationCulture = 'en-US'
and NOT EXISTS (Select * from tblLocalizationRecords tb
where tb.[ResourceId] = orgi.[ResourceId]
and tb.[ResourceKey] = orgi.ResourceKey
and [LocalizationCulture] = @NewCulture )
End
Thank you @damienbod
I used StringExtendedLocalizerFactory in my solution.
var defaultLang = stringExtendedLocalizerFactory.GetLocalizationData(DateTime.MinValue, "tr-tr", $"Create for {Lang.Name} translation") as List<LocalizationRecord>;
List<LocalizationRecord> newRecords = new List<LocalizationRecord>();
foreach (var item in defaultLang)
{
LocalizationRecord r = new LocalizationRecord
{
Key = item.Key,
LocalizationCulture = Lang.Code,
ResourceKey = item.ResourceKey,
Text = item.Key
};
newRecords.Add(r);
}
stringExtendedLocalizerFactory.AddNewLocalizationData(newRecords, "Copy from default language");
stringExtendedLocalizerFactory.ResetCache();
Thank you @damienbod
I used StringExtendedLocalizerFactory in my solution.
var defaultLang = stringExtendedLocalizerFactory.GetLocalizationData(DateTime.MinValue, "tr-tr", $"Create for {Lang.Name} translation") as List<LocalizationRecord>; List<LocalizationRecord> newRecords = new List<LocalizationRecord>(); foreach (var item in defaultLang) { LocalizationRecord r = new LocalizationRecord { Key = item.Key, LocalizationCulture = Lang.Code, ResourceKey = item.ResourceKey, Text = item.Key }; newRecords.Add(r); } stringExtendedLocalizerFactory.AddNewLocalizationData(newRecords, "Copy from default language"); stringExtendedLocalizerFactory.ResetCache();
Hocam 3.1 sürümünde denedinizmi çalışıyormu ?
@borahanarslan şu an production da ASP .NET Core 3.1 projesi ile kullanıyorum.
I am using AspNetCoreLocalization with ASP .NET Core 3.1 project.