Skip to content

Commit

Permalink
Don't limit LanguagePopup to neutral Culture values
Browse files Browse the repository at this point in the history
Fixes #287
  • Loading branch information
desplesda committed Dec 10, 2024
1 parent ad7ebaf commit 34c7917
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Inspector-exposed fields on `LineView` are now public.
- Fixed an issue where a `.meta` file was causing warnings to appear in Unity on import. ([@Colbydude](https://github.com/YarnSpinnerTool/YarnSpinner-Unity/pull/294))
- `YarnProjectImporter.GenerateStringsTable` is now public.
- Yarn Projects now allow choosing more specific cultures (for example 'pt-BR' and 'en-AU' rather than simply 'pt' and 'en') as their base language.

### Removed

Expand Down
20 changes: 12 additions & 8 deletions Editor/Editors/LanguagePopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ namespace Yarn.Unity.Editor
{
public static class LanguagePopup
{

static string FormatCulture(string cultureName) {

static string FormatCulture(string cultureName)
{
Culture culture = Cultures.GetCulture(cultureName);
return $"{culture.DisplayName} ({culture.Name})";
}

public static PopupField<string> Create(string label) {
var allNeutralCultures = Cultures.GetCultures().Where(c => c.IsNeutralCulture);
public static PopupField<string> Create(string label, bool onlyNeutralCultures = false)
{
var allCultures = Cultures.GetCultures().Where(c => !onlyNeutralCultures || c.IsNeutralCulture);

var defaultCulture = System.Globalization.CultureInfo.CurrentCulture;

if (defaultCulture.IsNeutralCulture == false) {
if (onlyNeutralCultures && defaultCulture.IsNeutralCulture == false)
{
defaultCulture = defaultCulture.Parent;
}

var cultureChoices = allNeutralCultures.Select(c => c.Name).ToList();
var cultureChoices = allCultures.Select(c => c.Name).ToList();

var popup = new PopupField<string>(label, cultureChoices, defaultCulture.Name, FormatCulture, FormatCulture);

Expand All @@ -34,8 +37,9 @@ public static PopupField<string> Create(string label) {
return popup;
}

public static T ReplaceElement<T>(VisualElement oldElement, T newElement) where T : VisualElement {
oldElement.parent.Insert(oldElement.parent.IndexOf(oldElement)+1, newElement);
public static T ReplaceElement<T>(VisualElement oldElement, T newElement) where T : VisualElement
{
oldElement.parent.Insert(oldElement.parent.IndexOf(oldElement) + 1, newElement);
oldElement.RemoveFromHierarchy();
return newElement;
}
Expand Down
2 changes: 2 additions & 0 deletions Editor/Importers/YarnProjectImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@ private void AddStringTableEntries(CompilationResult compilationResult, StringTa
{
if (table.LocaleIdentifier.CultureInfo != defaultCulture)
{
// There's no table for our base language, but maybe there
// is one for the parent of our base language.
var neutralTable = table.LocaleIdentifier.CultureInfo.IsNeutralCulture
? table.LocaleIdentifier.CultureInfo
: table.LocaleIdentifier.CultureInfo.Parent;
Expand Down

0 comments on commit 34c7917

Please sign in to comment.