Skip to content

Commit

Permalink
fix: update timezone handling for language detection
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqcode committed Sep 24, 2024
1 parent e321fa8 commit daea32c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions SubRenamer/Helper/I18NHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public static class I18NHelper

public static string GetLanguageNameFromOs()
{
string timeZoneId = TimeZoneInfo.Local.Id.ToUpper();
string timeZoneId = TimeZoneInfo.Local.Id.ToLower();

var name = CultureInfo.CurrentCulture.Name;
if (string.IsNullOrWhiteSpace(name)) name = Environment.GetEnvironmentVariable("LANG");

name = name?.Trim().ToLower().Replace("_", "-") ?? "";
if (name.Contains("en") || timeZoneId == "EST" || timeZoneId == "EDT") return "en-US";
if (name.Contains("zh-hans") || name.Contains("zh-cn") || timeZoneId == "PRC") return "zh-Hans";
if (name.Contains("zh-hant") || name.Contains("zh-tw") || name.Contains("zh-hk") || timeZoneId == "ROC") return "zh-Hant";
if (name.Contains("en") || timeZoneId == "est" || timeZoneId == "edt" || timeZoneId.Contains("america")) return "en-US";
if (name.Contains("zh-hans") || name.Contains("zh-cn") || timeZoneId == "prc" || timeZoneId == "cst" || timeZoneId == "asia/shanghai") return "zh-Hans";
if (name.Contains("zh-hant") || name.Contains("zh-tw") || name.Contains("zh-hk") || timeZoneId == "roc" || timeZoneId == "hkt" || timeZoneId == "asia/hong_kong" || timeZoneId == "asia/taipei") return "zh-Hant";
if (name.Contains("zh")) return "zh-Hans";
if (name.Contains("ja") || name.Contains("jp") || timeZoneId == "JST") return "ja-JP";
if (name.Contains("ja") || name.Contains("jp") || timeZoneId == "JST" || timeZoneId == "asia/tokyo") return "ja-JP";

return DefaultLanguage;
}
Expand Down

0 comments on commit daea32c

Please sign in to comment.