damienbod / AspNetCoreLocalization

Localization.SqlLocalizer & ASP.NET Core MVC Localization Examples
http://damienbod.com/2015/10/21/asp-net-5-mvc-6-localization/
MIT License
251 stars 101 forks source link

Add/Delete culture data #69

Open abircan opened 4 years ago

abircan commented 4 years ago

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 commented 4 years ago

Hello @damienbod , are you still developing this project?

damienbod commented 4 years ago

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

aliramadan8 commented 4 years ago

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
abircan commented 4 years ago

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(); 
borahanarslan commented 4 years ago

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 ?

abircan commented 4 years ago

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