Skip to content

Commit

Permalink
[add] different way of culture check using built-in invariant culture
Browse files Browse the repository at this point in the history
  • Loading branch information
i4004 committed Dec 20, 2023
1 parent b3467ef commit 7cff7e6
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/Simplify.Web/Modules/LanguageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Globalization;
using System.Threading;
using Microsoft.AspNetCore.Http;
using Simplify.System.Diagnostics;
using Simplify.Web.Settings;

namespace Simplify.Web.Modules;
Expand Down Expand Up @@ -37,7 +38,7 @@ public LanguageManager(ISimplifyWebSettings settings, HttpContext context)

if (!settings.AcceptHeaderLanguage || (settings.AcceptHeaderLanguage && !TrySetLanguageFromRequestHeader(context)))
if (!SetCurrentLanguage(settings.DefaultLanguage))
SetCurrentLanguage("iv");
SetInvariantCulture();
}

/// <summary>
Expand Down Expand Up @@ -70,17 +71,27 @@ public bool SetCurrentLanguage(string language)
{
try
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
Thread.CurrentThread.CurrentCulture = new CultureInfo(language);

Language = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;

return true;
CultureInfo.GetCultureInfo(language, true);

Check failure on line 74 in src/Simplify.Web/Modules/LanguageManager.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Argument 2: cannot convert from 'bool' to 'string'

Check failure on line 74 in src/Simplify.Web/Modules/LanguageManager.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Argument 2: cannot convert from 'bool' to 'string'

Check failure on line 74 in src/Simplify.Web/Modules/LanguageManager.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Argument 2: cannot convert from 'bool' to 'string'

Check failure on line 74 in src/Simplify.Web/Modules/LanguageManager.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Argument 2: cannot convert from 'bool' to 'string'

Check failure on line 74 in src/Simplify.Web/Modules/LanguageManager.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Argument 2: cannot convert from 'bool' to 'string'

Check failure on line 74 in src/Simplify.Web/Modules/LanguageManager.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Argument 2: cannot convert from 'bool' to 'string'

Check failure on line 74 in src/Simplify.Web/Modules/LanguageManager.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Argument 2: cannot convert from 'bool' to 'string'

Check failure on line 74 in src/Simplify.Web/Modules/LanguageManager.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Argument 2: cannot convert from 'bool' to 'string'

Check failure on line 74 in src/Simplify.Web/Modules/LanguageManager.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Argument 2: cannot convert from 'bool' to 'string'

Check failure on line 74 in src/Simplify.Web/Modules/LanguageManager.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Argument 2: cannot convert from 'bool' to 'string'

Check failure on line 74 in src/Simplify.Web/Modules/LanguageManager.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Argument 2: cannot convert from 'bool' to 'string'

Check failure on line 74 in src/Simplify.Web/Modules/LanguageManager.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Argument 2: cannot convert from 'bool' to 'string'
}
catch
{
return false;
}

Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
Thread.CurrentThread.CurrentCulture = new CultureInfo(language);

Language = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;

return true;
}

private void SetInvariantCulture()
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

Language = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
}

private bool TrySetLanguageFromCookie(HttpContext context)
Expand Down

0 comments on commit 7cff7e6

Please sign in to comment.