AspNetCoreLocalization icon indicating copy to clipboard operation
AspNetCoreLocalization copied to clipboard

Add/Delete culture data

Open abircan opened this issue 5 years ago • 6 comments

I have two question. In the production,

  1. What is the correct way to delete all your data for a culture?
  2. What is the right way to add new culture data? without importing csv, from the admin panel.

abircan avatar Feb 28 '20 09:02 abircan

Hello @damienbod , are you still developing this project?

abircan avatar Mar 05 '20 11:03 abircan

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

damienbod avatar Mar 05 '20 11:03 damienbod

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

aliramadan8 avatar Mar 05 '20 12:03 aliramadan8

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(); 

abircan avatar Mar 05 '20 13:03 abircan

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 avatar Apr 17 '20 20:04 borahanarslan

@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.

abircan avatar Apr 18 '20 04:04 abircan