-
Notifications
You must be signed in to change notification settings - Fork 36
Added string localization #293
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
base: main
Are you sure you want to change the base?
Changes from all commits
d417f2c
0fb0ffd
0a53587
3263cc5
51f9d56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| using System.Collections.Generic; | ||
| using Dalamud.Game.Text; | ||
| using TextToTalk.Localization; | ||
| using Xunit; | ||
|
|
||
| namespace TextToTalk.Tests.Localization; | ||
|
|
||
| public class ChatTypeMapTests | ||
| { | ||
| [Theory] | ||
| [InlineData(XivChatType.Say, XivChatType.GmSay)] | ||
| [InlineData(XivChatType.GmSay, XivChatType.Say)] | ||
| [InlineData(XivChatType.Party, XivChatType.GmParty)] | ||
| [InlineData(XivChatType.GmParty, XivChatType.Party)] | ||
| public void IsChatTypeEnabled_KeepsGmAndBaseChannelsSeparate( | ||
| XivChatType enabledChatType, | ||
| XivChatType receivedChatType) | ||
| { | ||
| Assert.False(ChatTypeMap.IsChatTypeEnabled( | ||
| new List<int> { (int)enabledChatType }, | ||
| enableAllChatTypes: false, | ||
| receivedChatType)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void IsChatTypeEnabled_DoesNotEnableUnrelatedChannels() | ||
| { | ||
| Assert.False(ChatTypeMap.IsChatTypeEnabled( | ||
| new List<int> { (int)XivChatType.Say }, | ||
| enableAllChatTypes: false, | ||
| XivChatType.Party)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void IsChatTypeEnabled_EnableAllAcceptsAnyChannel() | ||
| { | ||
| Assert.True(ChatTypeMap.IsChatTypeEnabled( | ||
| enabledChatTypes: null, | ||
| enableAllChatTypes: true, | ||
| XivChatType.GmLinkshell8)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| using System.Globalization; | ||
| using TextToTalk.Localization; | ||
| using TextToTalk.Resources; | ||
| using Xunit; | ||
|
|
||
| namespace TextToTalk.Tests.Localization; | ||
|
|
||
| public class LocalizerTests | ||
| { | ||
| [Theory] | ||
| [InlineData("en")] | ||
| [InlineData("fr")] | ||
| [InlineData("de")] | ||
| [InlineData("ja")] | ||
| public void UsesCultureForUiLanguage(string language) | ||
| { | ||
| var localizer = new Localizer(language); | ||
|
|
||
| Assert.Equal(CultureInfo.GetCultureInfo(language), localizer.Culture); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void UsesEnglishResourcesWhenTranslationIsUnavailable() | ||
| { | ||
| _ = new Localizer("pt"); | ||
|
|
||
| Assert.Equal("TextToTalk Configuration", Strings.Get("ConfigurationTitle")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void UsesEnumNameForLocalizedChatTypeResource() | ||
| { | ||
| _ = new Localizer("it"); | ||
|
|
||
| Assert.Equal("Dire", Strings.Get("ChatTypeSay")); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| using Dalamud.Interface.Utility.Raii; | ||
| using TextToTalk.Backends.Websocket; | ||
| using TextToTalk.Events; | ||
| using TextToTalk.Resources; | ||
| using TextToTalk.Services; | ||
| using TextToTalk.UI; | ||
|
|
||
|
|
@@ -132,13 +133,13 @@ private void DrawPortConfig() | |
| var port = this.config.MegaphonePort; | ||
| var portStr = port.ToString(); | ||
|
|
||
| var didUpdate = ImGui.InputText("Port", ref portStr, 5, ImGuiInputTextFlags.CharsDecimal); | ||
| var didUpdate = ImGui.InputText(Strings.Get("MegaphonePort"), ref portStr, 5, ImGuiInputTextFlags.CharsDecimal); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably inject
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reworked this a little bit, but the intention of
|
||
|
|
||
| if (int.TryParse(portStr, out var newPort)) | ||
| { | ||
| if (!IsValidPort(newPort)) | ||
| { | ||
| ImGui.TextColored(Red, "Port is out of range [0, 65535]"); | ||
| ImGui.TextColored(Red, Strings.Get("MegaphonePortOutOfRange")); | ||
| } | ||
| else if (didUpdate) | ||
| { | ||
|
|
@@ -149,14 +150,14 @@ private void DrawPortConfig() | |
| } | ||
| else | ||
| { | ||
| ImGui.TextColored(Red, "Unable to parse port."); | ||
| ImGui.TextColored(Red, Strings.Get("MegaphonePortInvalid")); | ||
| } | ||
| } | ||
|
|
||
| private void DrawInstallLink() | ||
| { | ||
| ImGui.TextColored(Hint, "Install the Megaphone Dalamud plugin:"); | ||
| if (ImGui.Button($"Open Install Guide##{MemoizedId.Create()}")) | ||
| ImGui.TextColored(Hint, Strings.Get("MegaphoneInstallPrompt")); | ||
| if (ImGui.Button($"{Strings.Get("MegaphoneOpenInstallGuide")}##{MemoizedId.Create()}")) | ||
| { | ||
| Dalamud.Utility.Util.OpenLink(InstallUrl); | ||
| } | ||
|
|
@@ -165,15 +166,18 @@ private void DrawInstallLink() | |
| private void DrawServerStatus() | ||
| { | ||
| var fullServiceUrl = this.wsServer.ServiceUrl + this.wsServer.ServicePath; | ||
| ImGui.TextColored(Hint, $"{(this.wsServer.Active ? "Started" : "Will start")} on {fullServiceUrl}"); | ||
| var status = this.wsServer.Active | ||
| ? Strings.Get("MegaphoneServerStarted") | ||
| : Strings.Get("MegaphoneServerWillStart"); | ||
| ImGui.TextColored(Hint, string.Format(Strings.Get("MegaphoneServerStatusFormat"), status, fullServiceUrl)); | ||
| } | ||
|
|
||
| private void DrawServerRestart() | ||
| { | ||
| using var bcAzure = ImRaii.PushColor(ImGuiCol.Button, Azure, this.dirtyConfig); | ||
| using var bcAzureHovered = ImRaii.PushColor(ImGuiCol.ButtonHovered, AzureHovered, this.dirtyConfig); | ||
| using var bcAzureActive = ImRaii.PushColor(ImGuiCol.ButtonActive, AzureActive, this.dirtyConfig); | ||
| if (ImGui.Button($"Restart server##{MemoizedId.Create()}")) | ||
| if (ImGui.Button($"{Strings.Get("MegaphoneRestartServer")}##{MemoizedId.Create()}")) | ||
| { | ||
| ImCatchServerRestart(() => | ||
| { | ||
|
|
@@ -247,4 +251,4 @@ public MegaphoneConfigProvider(PluginConfiguration config) | |
|
|
||
| public IPAddress? GetAddress() => null; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using Dalamud.Game; | ||
| using Dalamud.Game.Text; | ||
| using Dalamud.Plugin.Services; | ||
| using Lumina.Excel.Sheets; | ||
| using TextToTalk.GameEnums; | ||
| using TextToTalk.Resources; | ||
|
|
||
| namespace TextToTalk.Localization | ||
| { | ||
| internal static class ChatTypeMap | ||
| { | ||
| internal static readonly IReadOnlyDictionary<int, uint> AddonRowIds = | ||
| new Dictionary<int, uint> | ||
| { | ||
| [(int)XivChatType.Urgent] = 2251, | ||
| [(int)XivChatType.Notice] = 12874, | ||
| }; | ||
|
|
||
| internal static readonly IReadOnlyDictionary<XivChatType, XivChatType> GmBaseChatTypes = | ||
| new Dictionary<XivChatType, XivChatType> | ||
| { | ||
| [XivChatType.GmTell] = XivChatType.TellIncoming, | ||
| [XivChatType.GmSay] = XivChatType.Say, | ||
| [XivChatType.GmShout] = XivChatType.Shout, | ||
| [XivChatType.GmYell] = XivChatType.Yell, | ||
| [XivChatType.GmParty] = XivChatType.Party, | ||
| [XivChatType.GmFreeCompany] = XivChatType.FreeCompany, | ||
| [XivChatType.GmLinkshell1] = XivChatType.Ls1, | ||
| [XivChatType.GmLinkshell2] = XivChatType.Ls2, | ||
| [XivChatType.GmLinkshell3] = XivChatType.Ls3, | ||
| [XivChatType.GmLinkshell4] = XivChatType.Ls4, | ||
| [XivChatType.GmLinkshell5] = XivChatType.Ls5, | ||
| [XivChatType.GmLinkshell6] = XivChatType.Ls6, | ||
| [XivChatType.GmLinkshell7] = XivChatType.Ls7, | ||
| [XivChatType.GmLinkshell8] = XivChatType.Ls8, | ||
| [XivChatType.GmNoviceNetwork] = XivChatType.NoviceNetwork, | ||
| }; | ||
|
|
||
| internal static bool IsChatTypeEnabled(IList<int>? enabledChatTypes, bool enableAllChatTypes, XivChatType chatType) | ||
| { | ||
| return enableAllChatTypes || enabledChatTypes?.Contains((int)chatType) == true; | ||
| } | ||
|
|
||
| internal static bool TryGetResourceName(int chatType, out string name) | ||
| { | ||
| var enumName = Enum.GetName(typeof(XivChatType), (ushort)chatType) | ||
| ?? Enum.GetName(typeof(AdditionalChatType), chatType); | ||
| name = enumName is null ? string.Empty : Strings.Get($"ChatType{enumName}"); | ||
| return name.Length > 0 && !name.StartsWith("[", StringComparison.Ordinal); | ||
| } | ||
|
|
||
| internal static bool TryGetAdditionalChannelName(int chatType, out string name) | ||
| { | ||
| name = chatType switch | ||
| { | ||
| (int)XivChatType.Debug => Strings.ChatTypeDebug, | ||
| (int)XivChatType.CrossParty => Strings.ChatTypeCrossParty, | ||
| (int)XivChatType.Orchestrion => Strings.ChatTypeOrchestrion, | ||
| (int)XivChatType.TellIncoming => Strings.ChatTypeTellIncoming, | ||
| (int)XivChatType.TellOutgoing => Strings.ChatTypeTellOutgoing, | ||
| (int)AdditionalChatType.EnemyDefeatedByYou => Strings.ChatTypeEnemyDefeatedByYou, | ||
| _ => string.Empty, | ||
| }; | ||
| return name.Length > 0; | ||
| } | ||
|
|
||
| internal static bool TryGetLogFilterName(IDataManager data, ClientLanguage language, int chatType, out string name) | ||
| { | ||
| name = string.Empty; | ||
| return data.GetExcelSheet<LogFilter>(language)?.FirstOrDefault(row => | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this seem to perform fine in-game? This comes out to what I think (?) is an I think we should memoize this; if it's not really noticeable while the tab is open then it's fine for now and that can be a follow-up, otherwise we should do it here I think. Just a static
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's a good callout. in testing I did not notice issues, but I will address this |
||
| (int)row.LogKind == chatType && !string.IsNullOrWhiteSpace(row.Name.ToString())) is { } row | ||
| && !string.IsNullOrWhiteSpace(name = row.Name.ToString()); | ||
| } | ||
|
|
||
| internal static bool TryGetAddonName(IDataManager data, ClientLanguage language, int chatType, out string name) | ||
| { | ||
| name = string.Empty; | ||
| return AddonRowIds.TryGetValue(chatType, out var rowId) | ||
| && data.GetExcelSheet<Addon>(language)?.TryGetRow(rowId, out var row) == true | ||
| && !string.IsNullOrWhiteSpace(name = row.Text.ToString()); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.