diff --git a/Commands/CommandsMediaInfo.cs b/Commands/CommandsMediaInfo.cs index e062550..3a0aec5 100644 --- a/Commands/CommandsMediaInfo.cs +++ b/Commands/CommandsMediaInfo.cs @@ -12,8 +12,6 @@ using System.ComponentModel.Design; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Resources; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; using QMediaVSIX.i18n; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index b45f9ec..cce945a 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -41,7 +41,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.2.0")] -[assembly: AssemblyFileVersion("0.1.2.0")] +[assembly: AssemblyVersion("0.1.3.0")] +[assembly: AssemblyFileVersion("0.1.3.0")] [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] \ No newline at end of file diff --git a/QMediaVSIX.csproj b/QMediaVSIX.csproj index 10bc1c8..989e669 100644 --- a/QMediaVSIX.csproj +++ b/QMediaVSIX.csproj @@ -115,8 +115,12 @@ Menus.ctmenu - - + + true + + + true + PreserveNewest true diff --git a/QMediaVSIXPackage.cs b/QMediaVSIXPackage.cs index 27e8629..0c29622 100644 --- a/QMediaVSIXPackage.cs +++ b/QMediaVSIXPackage.cs @@ -12,12 +12,8 @@ using System.ComponentModel; using System.Runtime.InteropServices; using System.Threading; - using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Threading; - using QMediaVSIX.Commands; - using Task = System.Threading.Tasks.Task; #endregion @@ -40,12 +36,7 @@ namespace QMediaVSIX { /// To get loaded into VS, the package must be referred by <Asset Type="Microsoft.VisualStudio.VsPackage" ...> in .vsixmanifest file. /// /// - [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true), - Guid(PackageGuidString), - ProvideMenuResource("Menus.ctmenu", 1), - ProvideOptionPage(typeof(OptionPageGrid_English), "QMediaVSIX", "English", 0, 0, true), - ProvideOptionPage(typeof(OptionPageGrid_Japanese), "QMediaVSIX", "日本語", 0, 0, true) - ] + [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)][Guid(PackageGuidString)][ProvideMenuResource("Menus.ctmenu", 1)][ProvideOptionPage(typeof(OptionPageGrid_English), "QMediaVSIX", "English", 0, 0, true)][ProvideOptionPage(typeof(OptionPageGrid_Japanese), "QMediaVSIX", "日本語", 0, 0, true)] public sealed class QMediaVSIXPackage : AsyncPackage { /// /// QMediaVSIXPackage GUID string. @@ -111,9 +102,7 @@ public abstract class OptionPageGrid_i18n : DialogPage { } public class OptionPageGrid_English : OptionPageGrid_i18n { - [Category("English"), - DisplayName("Fallback Delay"), - Description("The delay before the extension falls back to media keys.\nIf controlling a media source fails, the extension waits for some time to ensure it wasn't just lagging, and then manually invokes keyboard media keys (which may control the wrong media source by accident.)\n\nSet to '0' to use exclusively media keys, and any negative values to disable the fallback entirely.")] + [Category("English")][DisplayName("Fallback Delay")][Description("The delay before the extension falls back to media keys.\nIf controlling a media source fails, the extension waits for some time to ensure it wasn't just lagging, and then manually invokes keyboard media keys (which may control the wrong media source by accident.)\n\nSet to '0' to use exclusively media keys, and any negative values to disable the fallback entirely.")] public override int FallbackDelay { get => Int_FallbackDelay; set => Int_FallbackDelay = value; @@ -121,9 +110,7 @@ public override int FallbackDelay { } public class OptionPageGrid_Japanese : OptionPageGrid_i18n { - [Category("日本語"), - DisplayName("フォールバック遅延"), - Description(">この設定は拡張機能がメディアキーにフォールバックするまでの遅延時間です。\nボタンコマンドが失敗した場合、エクステンションは遅延していないことを確認するためにしばらく待ちます。遅延後、メディアからの応答がない場合、拡張機能は手動でキーボードキーを押します。\nこれは、誤ったメディアソースを制御する可能性があるため、通常は避けます。\n\nキーボードキーのみを使用する場合は「0」に設定します。\nまた、負の値を設定すると、フォールバックを完全に無効にすることができます。")] + [Category("日本語")][DisplayName("フォールバック遅延")][Description(">この設定は拡張機能がメディアキーにフォールバックするまでの遅延時間です。\nボタンコマンドが失敗した場合、エクステンションは遅延していないことを確認するためにしばらく待ちます。遅延後、メディアからの応答がない場合、拡張機能は手動でキーボードキーを押します。\nこれは、誤ったメディアソースを制御する可能性があるため、通常は避けます。\n\nキーボードキーのみを使用する場合は「0」に設定します。\nまた、負の値を設定すると、フォールバックを完全に無効にすることができます。")] public override int FallbackDelay { get => Int_FallbackDelay; set => Int_FallbackDelay = value; diff --git a/i18n/AppTranslations.cs b/i18n/AppTranslations.cs index 312aef4..2033b5f 100644 --- a/i18n/AppTranslations.cs +++ b/i18n/AppTranslations.cs @@ -1,4 +1,4 @@ -#region Copyright (C) 2017-2020 Starflash Studios +#region Copyright (C) 2017-2021 Starflash Studios // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License (Version 3.0) // as published by the Free Software Foundation. @@ -6,10 +6,14 @@ // More information can be found here: https://www.gnu.org/licenses/gpl-3.0.en.html #endregion +#region Using Directives + using System; using System.Collections.Generic; using System.Reflection; +#endregion + namespace QMediaVSIX.i18n { public abstract class AppTranslations { // ReSharper disable once EmptyConstructor //Ensures inherited classes must have an empty constructor @@ -42,7 +46,7 @@ static AppTranslations_Helper() { Type AppT = typeof(AppTranslations); // ReSharper disable once LoopCanBePartlyConvertedToQuery foreach(Type T in Assembly.GetExecutingAssembly().GetTypes()) { - if (AppT.IsAssignableFrom(T) && AppT != T) { + if (T != null && AppT.IsAssignableFrom(T) && AppT != T) { AppTranslations Obj = T.GetConstructor(Type.EmptyTypes).Invoke(null) as AppTranslations; AllTrans.Add(Obj.In_Lang, Obj); } @@ -91,6 +95,9 @@ static AppTranslations_Helper() { } } // ReSharper restore ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator + + if (!FoundUI) { UITrans = Found ? Trans : new AppTranslations_English(); } + if (!Found) { Trans = FoundUI ? UITrans : new AppTranslations_English(); } } } } diff --git a/i18n/TransUtil.cs b/i18n/TransUtil.cs index a0c4495..67fd4a2 100644 --- a/i18n/TransUtil.cs +++ b/i18n/TransUtil.cs @@ -1,4 +1,4 @@ -#region Copyright (C) 2017-2020 Starflash Studios +#region Copyright (C) 2017-2021 Starflash Studios // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License (Version 3.0) // as published by the Free Software Foundation. @@ -8,23 +8,43 @@ #nullable enable +#region Using Directives + using System; +using System.Linq; using System.Collections.Generic; using System.Collections.ObjectModel; -//using System.Diagnostics; using System.Globalization; -using System.Linq; using System.Text; +//using System.Diagnostics; + +#endregion namespace QMediaVSIX.i18n { public static class TransUtil { - public static readonly Lang Current = new Lang(CultureInfo.CurrentCulture); - public static readonly Lang CurrentUI = new Lang(CultureInfo.CurrentUICulture); public static readonly Lang En = new Lang("en"); public static readonly Lang EnUS = new Lang("en-us"); public static readonly Lang EnGB = new Lang("en-gb"); public static readonly Lang EnAU = new Lang("en-au", EnGB); public static readonly Lang JaJP = new Lang("ja-jp"); + + // ReSharper disable twice ConstantConditionalAccessQualifier + public static readonly Lang Current = /*TryGetCulture(CultureInfo.CurrentCulture?.Name, out CultureInfo CurrentCult) ? new Lang(CurrentCult) : En*/new Lang("pt-br"); + public static readonly Lang CurrentUI = /*TryGetCulture(CultureInfo.CurrentUICulture?.Name, out CultureInfo CurrentCultUI) ? new Lang(CurrentCultUI) : En*/new Lang("pt-br"); + + public static bool TryGetCulture(string? Code, out CultureInfo Found) { + if (Code == null || string.IsNullOrWhiteSpace(Code)) { + Found = CultureInfo.CurrentCulture; + return false; + } + try { + Found = CultureInfo.GetCultureInfo(Code); + return true; + } catch (CultureNotFoundException) { + Found = CultureInfo.CurrentCulture; + return false; + } + } } public readonly struct Trans { @@ -114,6 +134,8 @@ public Trans( string DefKey, ReadOnlyCollection? Keys = null ) { /// /// A translated string. public string Get( Lang CurrentLang ) { + if (CurrentLang == null || string.IsNullOrWhiteSpace(CurrentLang.Family)) { return DefKey; } + //All languages in the same family (i.e. 'en', 'en-au', 'en-gb', etc.) List Fam = new List(); //The root of the language (i.e. 'en') @@ -143,8 +165,6 @@ public string Get( Lang CurrentLang ) { //Debug.WriteLine("\t\tFamily."); Fam.Add(Key); } - } else { - //Debug.WriteLine("\t\tDifferent Family."); } if (CurrentLang.Variants.Contains(Key.Expected)) { @@ -206,7 +226,7 @@ public string Get( Lang CurrentLang ) { public Lang[] Variants { get; } public Lang[] Related { get; } - public Lang( string Family, string Tag, params Lang[] Variants ) : this(Family: Family, Tag: Tag, Related: null, Variants: Variants) { } + public Lang( string Family, string Tag, params Lang[] Variants ) : this(Family, Tag, null, Variants) { } public Lang( string Family, string Tag, Lang[]? Related, params Lang[] Variants ) { this.Family = Family.ToUpperInvariant(); @@ -215,7 +235,7 @@ public Lang( string Family, string Tag, Lang[]? Related, params Lang[] Variants this.Variants = Variants; } - public Lang( string FullTag, params Lang[] Variants ) : this(FullTag: FullTag, Related: null, Variants: Variants) { } + public Lang( string FullTag, params Lang[] Variants ) : this(FullTag, Related: null, Variants: Variants) { } public Lang( string FullTag, Lang[]? Related, params Lang[] Variants ) { int HyphInd = FullTag.IndexOf('-'); @@ -231,7 +251,7 @@ public Lang( string FullTag, Lang[]? Related, params Lang[] Variants ) { this.Variants = Variants; } - public Lang( CultureInfo Cult, params Lang[] Variants ) : this(Cult: Cult, Related: null, Variants: Variants) { } + public Lang( CultureInfo Cult, params Lang[] Variants ) : this(Cult, null, Variants) { } public Lang( CultureInfo Cult, Lang[]? Related, params Lang[] Variants ) : this(Cult.Name, Related, Variants) { } public bool IsSameFamily( Lang L ) => Family == L.Family; diff --git a/i18n/en-US/AppTranslations_English.cs b/i18n/en-US/AppTranslations_English.cs index 10207ee..7967f92 100644 --- a/i18n/en-US/AppTranslations_English.cs +++ b/i18n/en-US/AppTranslations_English.cs @@ -1,4 +1,4 @@ -#region Copyright (C) 2017-2020 Starflash Studios +#region Copyright (C) 2017-2021 Starflash Studios // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License (Version 3.0) // as published by the Free Software Foundation. @@ -6,7 +6,7 @@ // More information can be found here: https://www.gnu.org/licenses/gpl-3.0.en.html #endregion -namespace QMediaVSIX.i18n.en_US { +namespace QMediaVSIX.i18n { public class AppTranslations_English : AppTranslations { public override Lang In_Lang => TransUtil.EnAU; diff --git a/i18n/ja-JP/AppTranslations_Japanese.cs b/i18n/ja-JP/AppTranslations_Japanese.cs index 7f16e12..1db1d0b 100644 --- a/i18n/ja-JP/AppTranslations_Japanese.cs +++ b/i18n/ja-JP/AppTranslations_Japanese.cs @@ -1,4 +1,4 @@ -#region Copyright (C) 2017-2020 Starflash Studios +#region Copyright (C) 2017-2021 Starflash Studios // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License (Version 3.0) // as published by the Free Software Foundation. @@ -6,7 +6,7 @@ // More information can be found here: https://www.gnu.org/licenses/gpl-3.0.en.html #endregion -namespace QMediaVSIX.i18n.ja_JP { +namespace QMediaVSIX.i18n { public class AppTranslations_Japanese : AppTranslations { public override Lang In_Lang => TransUtil.JaJP; diff --git a/source.extension.vsixmanifest b/source.extension.vsixmanifest index f4baf26..10efe5a 100644 --- a/source.extension.vsixmanifest +++ b/source.extension.vsixmanifest @@ -1,7 +1,7 @@ - + QMediaVSIX Quickly play, pause and skip your currently playing media. https://github.com/starflash-studios/QMediaVSIX