diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index 57bcf9fdc..82e770c80 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -13,12 +13,13 @@ // Optimizations // - Add rendering limitation to the exposed area using System; -using System.Collections; using System.Collections.Generic; using System.Threading; using System.Linq; -using NStack; using System.ComponentModel; +using System.Globalization; +using System.Reflection; +using System.IO; namespace Terminal.Gui { @@ -202,6 +203,13 @@ namespace Terminal.Gui { } } + private static List supportedCultures; + + /// + /// Gets all supported cultures by the application without the invariant language. + /// + public static List SupportedCultures => supportedCultures; + static void OnQuitKeyChanged (Key oldKey) { foreach (var top in toplevels) { @@ -346,6 +354,7 @@ namespace Terminal.Gui { } Top = topLevelFactory (); Current = Top; + supportedCultures = GetSupportedCultures (); _initialized = true; } @@ -1330,5 +1339,26 @@ namespace Terminal.Gui { Top.BringSubviewToFront (top); } } + + internal static List GetSupportedCultures () + { + CultureInfo [] culture = CultureInfo.GetCultures (CultureTypes.AllCultures); + + // Get the assembly + Assembly assembly = Assembly.GetExecutingAssembly (); + + //Find the location of the assembly + string assemblyLocation = AppDomain.CurrentDomain.BaseDirectory; + + // Find the resource file name of the assembly + string resourceFilename = $"{Path.GetFileNameWithoutExtension (assembly.Location)}.resources.dll"; + + // Return all culture for which satellite folder found with culture code. + return culture.Where (cultureInfo => + assemblyLocation != null && + Directory.Exists (Path.Combine (assemblyLocation, cultureInfo.Name)) && + File.Exists (Path.Combine (assemblyLocation, cultureInfo.Name, resourceFilename)) + ).ToList (); + } } } diff --git a/Terminal.Gui/Resources/Strings.Designer.cs b/Terminal.Gui/Resources/Strings.Designer.cs new file mode 100644 index 000000000..e15a9e6a9 --- /dev/null +++ b/Terminal.Gui/Resources/Strings.Designer.cs @@ -0,0 +1,189 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Terminal.Gui.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Strings { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Strings() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Terminal.Gui.Resources.Strings", typeof(Strings).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to _Copy. + /// + internal static string ctxCopy { + get { + return ResourceManager.GetString("ctxCopy", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cu_t. + /// + internal static string ctxCut { + get { + return ResourceManager.GetString("ctxCut", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to _Delete All. + /// + internal static string ctxDeleteAll { + get { + return ResourceManager.GetString("ctxDeleteAll", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to _Paste. + /// + internal static string ctxPaste { + get { + return ResourceManager.GetString("ctxPaste", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to _Redo. + /// + internal static string ctxRedo { + get { + return ResourceManager.GetString("ctxRedo", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to _Select All. + /// + internal static string ctxSelectAll { + get { + return ResourceManager.GetString("ctxSelectAll", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to _Undo. + /// + internal static string ctxUndo { + get { + return ResourceManager.GetString("ctxUndo", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Directory. + /// + internal static string fdDirectory { + get { + return ResourceManager.GetString("fdDirectory", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to File. + /// + internal static string fdFile { + get { + return ResourceManager.GetString("fdFile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Open. + /// + internal static string fdOpen { + get { + return ResourceManager.GetString("fdOpen", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Save. + /// + internal static string fdSave { + get { + return ResourceManager.GetString("fdSave", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Save as. + /// + internal static string fdSaveAs { + get { + return ResourceManager.GetString("fdSaveAs", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Select folder. + /// + internal static string fdSelectFolder { + get { + return ResourceManager.GetString("fdSelectFolder", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Select Mixed. + /// + internal static string fdSelectMixed { + get { + return ResourceManager.GetString("fdSelectMixed", resourceCulture); + } + } + } +} diff --git a/Terminal.Gui/Resources/Strings.pt-PT.resx b/Terminal.Gui/Resources/Strings.pt-PT.resx new file mode 100644 index 000000000..c336bf7b8 --- /dev/null +++ b/Terminal.Gui/Resources/Strings.pt-PT.resx @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + _Copiar + + + Cor_tar + + + _Apagar Tudo + + + Co_lar + + + _Refazer + + + _Selecionar Tudo + + + _Desfazer + + + Diretório + + + Ficheiro + + + Guardar + + + Guardar como + + + Abrir + + + Selecione pasta + + + Selecione misto + + \ No newline at end of file diff --git a/Terminal.Gui/Resources/Strings.resx b/Terminal.Gui/Resources/Strings.resx new file mode 100644 index 000000000..734d8aed4 --- /dev/null +++ b/Terminal.Gui/Resources/Strings.resx @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + _Select All + + + _Delete All + + + _Copy + + + Cu_t + + + _Paste + + + _Undo + + + _Redo + + + Directory + + + File + + + Save + + + Save as + + + Open + + + Select folder + + + Select Mixed + + \ No newline at end of file diff --git a/Terminal.Gui/Terminal.Gui.csproj b/Terminal.Gui/Terminal.Gui.csproj index b4107cc14..1fcc53e37 100644 --- a/Terminal.Gui/Terminal.Gui.csproj +++ b/Terminal.Gui/Terminal.Gui.csproj @@ -17,6 +17,21 @@ + + + + True + True + Strings.resx + + + + + + ResXFileCodeGenerator + Strings.Designer.cs + + true diff --git a/Terminal.Gui/Windows/FileDialog.cs b/Terminal.Gui/Windows/FileDialog.cs index d078757eb..8e284dc0f 100644 --- a/Terminal.Gui/Windows/FileDialog.cs +++ b/Terminal.Gui/Windows/FileDialog.cs @@ -14,6 +14,7 @@ using System.Collections.Generic; using NStack; using System.IO; using System.Linq; +using Terminal.Gui.Resources; namespace Terminal.Gui { internal class DirListView : View { @@ -618,7 +619,7 @@ namespace Terminal.Gui { Add (this.message); var msgLines = TextFormatter.MaxLines (message, Driver.Cols - 20); - this.nameDirLabel = new Label (nameDirLabel.IsEmpty ? "Directory: " : $"{nameDirLabel}: ") { + this.nameDirLabel = new Label (nameDirLabel.IsEmpty ? $"{Strings.fdDirectory}: " : $"{nameDirLabel}: ") { X = 1, Y = 1 + msgLines, AutoSize = true @@ -635,7 +636,7 @@ namespace Terminal.Gui { }; Add (this.nameDirLabel, dirEntry); - this.nameFieldLabel = new Label (nameFieldLabel.IsEmpty ? "File: " : $"{nameFieldLabel}: ") { + this.nameFieldLabel = new Label (nameFieldLabel.IsEmpty ? $"{Strings.fdFile}: " : $"{nameFieldLabel}: ") { X = 1, Y = 3 + msgLines, AutoSize = true @@ -873,7 +874,7 @@ namespace Terminal.Gui { /// The message. /// The allowed types. public SaveDialog (ustring title, ustring message, List allowedTypes = null) - : base (title, prompt: "Save", nameFieldLabel: "Save as:", message: message, allowedTypes) { } + : base (title, prompt: Strings.fdSave, nameFieldLabel: $"{Strings.fdSaveAs}:", message: message, allowedTypes) { } /// /// Gets the name of the file the user selected for saving, or null @@ -941,8 +942,8 @@ namespace Terminal.Gui { /// The allowed types. /// The open mode. public OpenDialog (ustring title, ustring message, List allowedTypes = null, OpenMode openMode = OpenMode.File) : base (title, - prompt: openMode == OpenMode.File ? "Open" : openMode == OpenMode.Directory ? "Select folder" : "Select Mixed", - nameFieldLabel: "Open", message: message, allowedTypes) + prompt: openMode == OpenMode.File ? Strings.fdOpen : openMode == OpenMode.Directory ? Strings.fdSelectFolder : Strings.fdSelectMixed, + nameFieldLabel: Strings.fdOpen, message: message, allowedTypes) { this.openMode = openMode; switch (openMode) { diff --git a/UnitTests/ApplicationTests.cs b/UnitTests/ApplicationTests.cs index 746523a2d..2ceceefbd 100644 --- a/UnitTests/ApplicationTests.cs +++ b/UnitTests/ApplicationTests.cs @@ -1279,5 +1279,12 @@ namespace Terminal.Gui.Core { win2.MouseEvent (new MouseEvent () { Flags = MouseFlags.Button1Released }); Assert.Null (Toplevel.dragPosition); } + + [Fact, AutoInitShutdown] + public void GetSupportedCultures_Method () + { + var cultures = Application.GetSupportedCultures (); + Assert.Equal (cultures.Count, Application.SupportedCultures.Count); + } } }