Skip to content

Commit

Permalink
chore: 언어 설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
potados99 committed Sep 18, 2023
1 parent 3898688 commit 4f7d6e5
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 6 deletions.
6 changes: 6 additions & 0 deletions FocusTimer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<setting name="ShowConcentration" serializeAs="String">
<value>True</value>
</setting>
<setting name="UpgradeRequired" serializeAs="String">
<value>True</value>
</setting>
<setting name="CultureOverride" serializeAs="String">
<value />
</setting>
</FocusTimer.Properties.Settings>
</userSettings>
</configuration>
8 changes: 7 additions & 1 deletion FocusTimer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,19 @@ protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Logger.Info("앱을 시작합니다.");


Settings.UpgradeIfNeeded();
Logger.Info("설정을 이전하였습니다.");

Modules.Initialize();
Logger.Info("의존성 주입기를 초기화하였습니다.");

Modules.Get<FocusTimerDatabaseContext>().Initialize();
Logger.Info("DB Context를 초기화하였습니다.");

Culture.OverrideForStringResources();
Logger.Info("언어를 설정하였습니다.");

Strings.Initialize();
Logger.Info("스트링 리소스를 초기화하였습니다.");

Expand Down
48 changes: 48 additions & 0 deletions FocusTimer/Library/Culture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Culture.cs
// 이 파일은 FocusTimer의 일부입니다.
//
// © 2023 Potados <song@potados.com>
//
// FocusTimer은(는) 자유 소프트웨어입니다.
// GNU General Public License v3.0을 준수하는 범위 내에서
// 누구든지 자유롭게 변경, 수정하거나 배포할 수 있습니다.
//
// 이 프로그램을 공유함으로서 다른 누군가에게 도움이 되기를 바랍니다.
// 다만 프로그램 배포와 함께 아무 것도 보증하지 않습니다. 자세한 내용은
// GNU General Public License를 참고하세요.
//
// 라이센스 전문은 이 프로그램과 함께 제공되었을 것입니다. 만약 아니라면,
// 다음 링크에서 받아볼 수 있습니다: <https://www.gnu.org/licenses/gpl-3.0.txt>

using System;
using FocusTimer.Library.Extensions;

namespace FocusTimer.Library;

public static class Culture
{
public static void OverrideForStringResources()
{
var storedCultureOverride = Settings.GetCultureOverride();
var nothingOverriden = string.IsNullOrEmpty(storedCultureOverride);
if (nothingOverriden)
{
return;
}

OverrideForStringResources(storedCultureOverride);
}

private static void OverrideForStringResources(string name)
{
try
{
Resources.strings.Culture = System.Globalization.CultureInfo.CreateSpecificCulture(name);
}
catch (Exception e)
{
e.GetLogger().Error($"주어진 이름의 Culture로 override하지 못하였습니다. 아마 [{name}]이라는 이름의 Culture가 없나봅니다.", e);
// ignored
}
}
}
22 changes: 22 additions & 0 deletions FocusTimer/Library/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ namespace FocusTimer.Library;
/// </summary>
public static class Settings
{
public static void UpgradeIfNeeded()
{
if (Properties.Settings.Default.UpgradeRequired)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UpgradeRequired = false;
Properties.Settings.Default.Save();
}
}

public static int GetFocusLockHoldDuration()
{
var got = Properties.Settings.Default.FocusLockHoldDuration;
Expand Down Expand Up @@ -62,4 +72,16 @@ public static void SetShowConcentration(bool show)

Properties.Settings.Default.Save();
}

public static string GetCultureOverride()
{
return Properties.Settings.Default.CultureOverride;
}

public static void SetCultureOverride(string culture)
{
Properties.Settings.Default.CultureOverride = culture;

Properties.Settings.Default.Save();
}
}
6 changes: 1 addition & 5 deletions FocusTimer/Library/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ public static class Strings

public static void Initialize()
{
_rm = new ResourceManager("FocusTimer.Resources.strings", typeof(FocusTimer.Resources.strings).Assembly);

//CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
//Thread.CurrentThread.CurrentCulture = culture;
//Thread.CurrentThread.CurrentUICulture = culture;
_rm = new ResourceManager("FocusTimer.Resources.strings", typeof(Resources.strings).Assembly);
}

public static string Get(string key)
Expand Down
24 changes: 24 additions & 0 deletions FocusTimer/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions FocusTimer/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
<Setting Name="ShowConcentration" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="UpgradeRequired" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="CultureOverride" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 4f7d6e5

Please sign in to comment.