Skip to content

Commit

Permalink
chore: Initialize LanguagePrefs.Language with OS language setting (#266)
Browse files Browse the repository at this point in the history
* chore: Initialize LanguagePrefs.Language with OS language setting

* chore: ignore SystemLanguage.Chinese case

* chore: add CHANGELOG

* chore: add stub zh-Hans language file

---------

Co-authored-by: bd_ <[email protected]>
  • Loading branch information
suzuryg and bdunderscore authored Jul 2, 2024
1 parent 565013a commit 0e4918e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- [#273] Preview system now calls `Refresh` to avoid double computation

- [#266] NDMF language defaults to being based on the system language.

### Removed
- [#277] The `ReactiveQuery` API has been removed to reduce the scope and complexity of this upcoming release

Expand Down
22 changes: 21 additions & 1 deletion Editor/UI/Localization/LanguagePrefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class LanguagePrefs
private static void Init()
{
// Exiting playmode destroys the dynamic font assets we create, so we need to recreate and reapply them.
Language = EditorPrefs.GetString(EditorPrefKey, "en-us").ToLowerInvariant();
Language = EditorPrefs.GetString(EditorPrefKey, GetSystemLanguage()).ToLowerInvariant();
EditorApplication.playModeStateChanged += evt =>
{
foreach (var fontCallback in _fontUpdateCallbacks.Values)
Expand All @@ -44,6 +44,26 @@ private static void Init()
};
}

private static string GetSystemLanguage()
{
switch (Application.systemLanguage)
{
case SystemLanguage.Japanese:
return "ja-jp";
case SystemLanguage.ChineseSimplified:
return "zh-hans";
case SystemLanguage.ChineseTraditional:
return "zh-hant";
case SystemLanguage.Korean:
return "ko-kr";
case SystemLanguage.Chinese:
// fall through - this case is ambiguous and culturally sensitive, so we'll treat this case as an
// unknown language.
default:
return "en-us";
}
}

/// <summary>
/// The currently selected language ID, e.g. "en-us".
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions Editor/UI/Localization/zh-Hans.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
msgid ""
msgstr ""
"Language: zh-Hans\n"

#: This file is kept just so the zh-Hans (chinese simplified) language is registered, so that we can safely default to
#: it. However, we do not yet have any community translations for this language.
3 changes: 3 additions & 0 deletions Editor/UI/Localization/zh-Hans.po.meta

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

0 comments on commit 0e4918e

Please sign in to comment.