Skip to content

Commit

Permalink
Merge pull request #228 from hargata/Hargata/translation.helper
Browse files Browse the repository at this point in the history
added try catch to translation layer for translation files error.
  • Loading branch information
hargata authored Feb 4, 2024
2 parents 57dc976 + ff255e8 commit 7c97aa7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Helper/TranslationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ public string Translate(string userLanguage, string text)
entry.SlidingExpiration = TimeSpan.FromHours(1);
if (File.Exists(translationFilePath))
{
var translationFile = File.ReadAllText(translationFilePath);
var translationDictionary = JsonSerializer.Deserialize<Dictionary<string, string>>(translationFile);
return translationDictionary ?? new Dictionary<string, string>();
try
{
var translationFile = File.ReadAllText(translationFilePath);
var translationDictionary = JsonSerializer.Deserialize<Dictionary<string, string>>(translationFile);
return translationDictionary ?? new Dictionary<string, string>();
} catch (Exception ex)
{
return new Dictionary<string, string>();
}
}
else
{
Expand Down

0 comments on commit 7c97aa7

Please sign in to comment.