From f44b81cee34141ef41184dd3546eaaf905d9c6cf Mon Sep 17 00:00:00 2001 From: Rudy Huyn Date: Mon, 17 Aug 2020 01:45:41 -0700 Subject: [PATCH] Modify how the Visual Studio add-in filters BCP-47 codes in namespaces. --- .../ClassGenerator/ReswClassGenerator.cs | 13 +++++++------ src/VSExtension/ReswPlus.Core/Constants.cs | 2 +- .../ReswPlusVSIX/source.extension.vsixmanifest | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/VSExtension/ReswPlus.Core/ClassGenerator/ReswClassGenerator.cs b/src/VSExtension/ReswPlus.Core/ClassGenerator/ReswClassGenerator.cs index e159158..e4556bd 100644 --- a/src/VSExtension/ReswPlus.Core/ClassGenerator/ReswClassGenerator.cs +++ b/src/VSExtension/ReswPlus.Core/ClassGenerator/ReswClassGenerator.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Text.RegularExpressions; using ReswPlus.Core.ResourceInfo; +using System.Globalization; namespace ReswPlus.Core.ClassGenerator { @@ -226,15 +227,15 @@ private string[] ExtractNamespace(string defaultNamespace) } // remove bcp47 tag from the namespace - var regexNamespace = - new Regex("\\.Strings\\.[a-z]{2}(?:[-_](?:Latn|Cyrl|Hant|Hans))?(?:[-_](?:\\d{3}|[A-Z]{2,3}))?$"); - var match = regexNamespace.Match(defaultNamespace); - if (match.Success) + var splittedNamespace = defaultNamespace.Split('.'); + var lastNamespace = splittedNamespace.Last().Replace('_', '-'); + var culture = CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(c => string.Compare(c.Name, lastNamespace, true) == 0); + if (culture != null) { - return defaultNamespace.Substring(0, match.Index + 8).Split('.'); + return splittedNamespace.Take(splittedNamespace.Length - 1).ToArray(); } - return defaultNamespace.Split('.'); + return splittedNamespace; } public static (string format, bool isDotNetFormatting) ParseTag(string comment) diff --git a/src/VSExtension/ReswPlus.Core/Constants.cs b/src/VSExtension/ReswPlus.Core/Constants.cs index 310dd23..5f1c5fa 100644 --- a/src/VSExtension/ReswPlus.Core/Constants.cs +++ b/src/VSExtension/ReswPlus.Core/Constants.cs @@ -9,7 +9,7 @@ namespace ReswPlus.Core public sealed class Constants { public const string ReswPlusName = "DotNetPlus.ReswPlus"; - public const string ReswPlusExtensionVersion = "2.1.2"; + public const string ReswPlusExtensionVersion = "2.1.3"; public static Version ReswPlusLibMinVersion = new Version(1, 0, 0); } } diff --git a/src/VSExtension/ReswPlusVSIX/source.extension.vsixmanifest b/src/VSExtension/ReswPlusVSIX/source.extension.vsixmanifest index 4e23665..bad3e10 100644 --- a/src/VSExtension/ReswPlusVSIX/source.extension.vsixmanifest +++ b/src/VSExtension/ReswPlusVSIX/source.extension.vsixmanifest @@ -1,7 +1,7 @@ - + ReswPlus - Advanced Code Generator for .Resw Advanced Resw File Code Generator for UWP apps.