Skip to content

Commit

Permalink
Catch Localization Error
Browse files Browse the repository at this point in the history
  • Loading branch information
enkodellc committed Oct 19, 2020
1 parent e589a76 commit c3ab04c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,5 @@ healthchecksdb

/src/Server/BlazorBoilerplate.Server/Modules
/src/Server/BlazorBoilerplate.Server/Keys
/src/Server/BlazorBoilerplate.Storage/Properties/PublishProfiles/FolderProfile.pubxml
/src/Server/BlazorBoilerplate.Storage/Properties/PublishProfiles/FolderProfile1.pubxml
49 changes: 28 additions & 21 deletions src/Server/BlazorBoilerplate.Storage/DatabaseInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,38 +86,45 @@ private async Task MigrateAsync()

private async Task ImportResxLanguages()
{
if (!await _localizationDbContext.LocalizationRecords.AnyAsync())
try
{
_logger.LogInformation("Importing Resx files in db");
if (!await _localizationDbContext.LocalizationRecords.AnyAsync())
{
_logger.LogInformation("Importing Resx files in db");

var regex = new Regex(@".(\w{2}-\w{2}).resx");
var regex = new Regex(@".(\w{2}-\w{2}).resx");

foreach (var resxFile in Directory.GetFiles(@"..\..\Shared\BlazorBoilerplate.Localization", "*.resx"))
{
var m = regex.Match(resxFile);
foreach (var resxFile in Directory.GetFiles(@"..\..\Shared\BlazorBoilerplate.Localization", "*.resx"))
{
var m = regex.Match(resxFile);

var culture = Shared.SqlLocalizer.Settings.NeutralCulture;
var culture = Shared.SqlLocalizer.Settings.NeutralCulture;

if (m.Success)
culture = m.Groups[1].Value;
if (m.Success)
culture = m.Groups[1].Value;

XDocument doc = XDocument.Load(new XmlTextReader(resxFile));
XDocument doc = XDocument.Load(new XmlTextReader(resxFile));

foreach (var node in doc.Element("root").Elements("data"))
{
_localizationDbContext.Add(new LocalizationRecord()
foreach (var node in doc.Element("root").Elements("data"))
{
LocalizationCulture = culture,
Key = node.Attribute("name").Value,
Text = node.Element("value").Value,
ResourceKey = "Global"
});
_localizationDbContext.Add(new LocalizationRecord()
{
LocalizationCulture = culture,
Key = node.Attribute("name").Value,
Text = node.Element("value").Value,
ResourceKey = "Global"
});
}

await _localizationDbContext.SaveChangesAsync();
}

await _localizationDbContext.SaveChangesAsync();
SqlStringLocalizerFactory.SetLocalizationRecords(_localizationDbContext.LocalizationRecords);
}

SqlStringLocalizerFactory.SetLocalizationRecords(_localizationDbContext.LocalizationRecords);
}
catch (Exception ex)
{
_logger.LogError("Importing Resx files in db error: {0}",ex.Message);
}
}

Expand Down

0 comments on commit c3ab04c

Please sign in to comment.