Merge branch '44-bug-when-renaming-a-culture-existing-translations-must-be-renamed-accordingly' into 'main'

Resolve "Bug: When renaming a culture, existing translations must be renamed accordingly"

Closes #44

See merge request open-source/dotnet/i18n-commander!23
This commit is contained in:
Thorsten 2022-11-01 19:41:39 +00:00
commit d9ba6eeb59

View File

@ -268,6 +268,9 @@ public static class AppSettings
public static async Task SetCultureCode(int index, string code)
{
// Keep a copy of the previous name:
var previousCode = await AppSettings.GetCultureCode(index);
// Update the cache:
CACHE_CULTURES[index] = code;
@ -297,6 +300,13 @@ public static class AppSettings
// Update the list of cultures indices:
CACHE_CULTURES_INDICES.Add(index);
}
// Next, we need to rename the culture inside all translations as well:
var translations = await db.Translations.Where(n => n.Culture == previousCode).ToListAsync();
foreach (var translation in translations)
translation.Culture = code;
await db.SaveChangesAsync();
}
#endregion