Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix singer name translation #1071

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions OpenUtau.Core/Ustx/USinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,21 +259,22 @@ public bool IsFavourite {

private string name;

public string DisplayName { get { return Found ? name : $"[Missing] {name}"; } }

public string LocalizedName {
get {
if(LocalizedNames == null) {
return Name;
return Found ? Name : $"[Missing] {Name}";
}
string language = Preferences.Default.SortingOrder;
if(String.IsNullOrEmpty(language)){
if (language == null) {
language = Preferences.Default.Language;
}
if(LocalizedNames.TryGetValue(language, out var localizedName)){
return localizedName;
if (language == string.Empty) { // InvariantCulture
return Found ? Name : $"[Missing] {Name}";
}
if (LocalizedNames.TryGetValue(language, out var localizedName)) {
return Found ? localizedName : $"[Missing] {localizedName}";
} else {
return Name;
return Found ? Name : $"[Missing] {Name}";
}
}
}
Expand All @@ -295,7 +296,7 @@ public virtual bool TryGetMappedOto(string phoneme, int tone, string color, out
public virtual IEnumerable<UOto> GetSuggestions(string text) { return emptyOtos; }
public virtual byte[] LoadPortrait() => null;
public virtual byte[] LoadSample() => null;
public override string ToString() => Name;
public override string ToString() => LocalizedName;
public bool Equals(USinger other) {
// Tentative: Since only the singer's Id is recorded in ustx and preferences, singers with the same Id are considered identical.
// Singer with the same directory name in different locations may be identical.
Expand Down
2 changes: 0 additions & 2 deletions OpenUtau.Core/Ustx/UTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ public USinger Singer {
}
[YamlIgnore] public Phonemizer Phonemizer { get; set; } = PhonemizerFactory.Get(typeof(DefaultPhonemizer)).Create();
[YamlIgnore] public string PhonemizerTag => Phonemizer.Tag;

[YamlIgnore] public string SingerName => Singer != null ? Singer.DisplayName : "[No Singer]";
[YamlIgnore] public int TrackNo { set; get; }
public string TrackName { get; set; } = "New Track";
public string TrackColor { get; set; } = "Blue";
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau.Core/Util/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public class SerializablePreferences {
public int DiffsingerSpeedup = 50;
public int DiffSingerDepth = 1000;
public string Language = string.Empty;
public string SortingOrder = string.Empty;
public string? SortingOrder = null;
public List<string> RecentFiles = new List<string>();
public string SkipUpdate = string.Empty;
public string AdditionalSingerPath = string.Empty;
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</Application.DataTemplates>
<Application.Resources>
<ResourceDictionary>
<ResourceInclude x:Key="strings-en-US" Source="/Strings/Strings.axaml"/>
<ResourceInclude x:Key="strings-de-DE" Source="/Strings/Strings.de-DE.axaml"/>
<ResourceInclude x:Key="strings-es-ES" Source="/Strings/Strings.es-ES.axaml"/>
<ResourceInclude x:Key="strings-es-MX" Source="/Strings/Strings.es-MX.axaml"/>
Expand All @@ -24,7 +25,6 @@
<ResourceInclude x:Key="strings-zh-CN" Source="/Strings/Strings.zh-CN.axaml"/>
<ResourceInclude x:Key="strings-zh-TW" Source="/Strings/Strings.zh-TW.axaml"/>
<ResourceInclude x:Key="strings-th-TH" Source="/Strings/Strings.th-TH.axaml"/>
<ResourceInclude x:Key="strings-en-US" Source="/Strings/Strings.axaml"/>
<ResourceInclude x:Key="themes-dark" Source="/Colors/DarkTheme.axaml"/>
<ResourceInclude x:Key="themes-light" Source="/Colors/LightTheme.axaml"/>
<ResourceDictionary.MergedDictionaries>
Expand Down
1 change: 1 addition & 0 deletions OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<system:String x:Key="languages.en">English</system:String>
<system:String x:Key="languages.es">Spanish</system:String>
<system:String x:Key="languages.fr">French</system:String>
<system:String x:Key="languages.invariant">Not translating</system:String>
<system:String x:Key="languages.it">Italian</system:String>
<system:String x:Key="languages.ja">Japanese</system:String>
<system:String x:Key="languages.ko">Korean</system:String>
Expand Down
1 change: 1 addition & 0 deletions OpenUtau/Strings/Strings.ja-JP.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<system:String x:Key="languages.en">英語</system:String>
<system:String x:Key="languages.es">スペイン語</system:String>
<system:String x:Key="languages.fr">フランス語</system:String>
<system:String x:Key="languages.invariant">翻訳しない</system:String>
<system:String x:Key="languages.it">イタリア語</system:String>
<system:String x:Key="languages.ja">日本語</system:String>
<system:String x:Key="languages.ko">韓国語</system:String>
Expand Down
7 changes: 6 additions & 1 deletion OpenUtau/ViewModels/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

namespace OpenUtau.App.ViewModels {
public class CultureNameConverter : IValueConverter {
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => (value as CultureInfo)?.NativeName ?? string.Empty;
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) {
if (value is CultureInfo cultureInfo) {
return cultureInfo == CultureInfo.InvariantCulture ? ThemeManager.GetString("languages.invariant") : cultureInfo.NativeName;
}
return string.Empty;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException();
}

Expand Down
9 changes: 4 additions & 5 deletions OpenUtau/ViewModels/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,13 @@ public PreferencesViewModel() {
Languages = App.GetLanguages().Keys
.Select(lang => CultureInfo.GetCultureInfo(lang))
.ToList();
Languages.Insert(0, CultureInfo.GetCultureInfo("en-US"));
Language = string.IsNullOrEmpty(Preferences.Default.Language)
? null
: CultureInfo.GetCultureInfo(Preferences.Default.Language);
SortingOrders = Languages.ToList();
SortingOrders.Insert(1, CultureInfo.InvariantCulture);
SortingOrder = string.IsNullOrEmpty(Preferences.Default.SortingOrder)
? Language
SortingOrders.Insert(0, CultureInfo.InvariantCulture);
SortingOrder = Preferences.Default.SortingOrder == null ? Language
: Preferences.Default.SortingOrder == string.Empty ? CultureInfo.InvariantCulture
: CultureInfo.GetCultureInfo(Preferences.Default.SortingOrder);
PreRender = Preferences.Default.PreRender;
DefaultRendererOptions = Renderers.getRendererOptions();
Expand Down Expand Up @@ -218,7 +217,7 @@ public PreferencesViewModel() {
});
this.WhenAnyValue(vm => vm.SortingOrder)
.Subscribe(so => {
Preferences.Default.SortingOrder = so?.Name ?? string.Empty;
Preferences.Default.SortingOrder = so?.Name ?? null;
Preferences.Save();
});
this.WhenAnyValue(vm => vm.Theme)
Expand Down