Skip to content

Commit

Permalink
fix: language selection is not preserved over domain reload
Browse files Browse the repository at this point in the history
Fixes: #102
  • Loading branch information
bdunderscore committed Jan 6, 2024
1 parent 9910abd commit 41eb4fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Exposed SafeSubst and SafeSubstByKey on SimpleError (#104)

### Fixed
- Language selection is not persisted across Unity Editor restarts or domain reloads (#108)
- Exceptions leaking out of language change callbacks break subsequent callbacks (#103)
- Deregistering a language change callback while callbacks are running could skip executing some callbacks (#103)

Expand Down
9 changes: 9 additions & 0 deletions Editor/UI/Localization/LanguagePrefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using UnityEditor;
using UnityEngine;

namespace nadena.dev.ndmf.localization
Expand All @@ -11,8 +12,15 @@ namespace nadena.dev.ndmf.localization
/// </summary>
public static class LanguagePrefs
{
private const string EditorPrefKey = "nadena.dev.ndmf.language-selection";
private static string _curLanguage = "en-us";

[InitializeOnLoadMethod]
private static void Init()
{
Language = EditorPrefs.GetString(EditorPrefKey, "en-US");
}

/// <summary>
/// The currently selected language ID, e.g. "en-us".
/// </summary>
Expand All @@ -23,6 +31,7 @@ public static string Language
{
if (value == _curLanguage) return;
_curLanguage = value;
EditorPrefs.SetString(EditorPrefKey, value);
TriggerLanguageChangeCallbacks();
}
}
Expand Down

0 comments on commit 41eb4fb

Please sign in to comment.