A Swiss Army knife for developers.
C# blazorcross-platformcsharpdesktopdesktop-appdesktop-applicationdeveloper-toolsextensiblefluentfluent-designlinuxmacosmicasyntax-highlightingtypescriptwindowswindows-10windows-11winui
Added localization and theme manager support to MAUI Blazor.
Etienne Baudouxfbf33a8fddfa
diff --git a/.gitignore b/.gitignoreindex d99e219c7..eaf62ef6a 100644--- a/.gitignore+++ b/.gitignore@@ -433,7 +433,7 @@ src/app/dev/DevToys.MonacoEditor/monaco-editor# MAUI Blazor web components.!**/DevToys.MauiBlazor/wwwroot/js/*.js-!**/DevToys.MauiBlazor/Components/*.js+!**/DevToys.MauiBlazor/Components/MonacoEditor.razor.js# Build results[Dd]ebug/diff --git a/src/DevToys-Windows.sln b/src/DevToys-Windows.slnindex 45b73208e..ea3117051 100644--- a/src/DevToys-Windows.sln+++ b/src/DevToys-Windows.sln@@ -63,6 +63,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevToys.MauiBlazor", "app\dEndProjectProject("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevToys.Wasdk", "app\dev\platforms\desktop\windows\DevToys.Wasdk\DevToys.Wasdk.csproj", "{804DBC7B-FBF4-4B2E-AAE9-D74C32985D3F}"EndProject+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevToys.Localization", "app\dev\DevToys.Localization\DevToys.Localization.csproj", "{12A1461D-3357-4007-BE15-9622E9513D09}"+EndProject+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "generators", "generators", "{FA3821C4-74BB-4927-ABCC-0D0A12E097A2}"+EndProject+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResxHelperGenerator", "generators\ResxHelperGenerator\ResxHelperGenerator.csproj", "{DB6B033B-584E-43CF-AC96-4F6548C96ECA}"+EndProjectGlobalGlobalSection(SolutionConfigurationPlatforms) = preSolutionDebug|Any CPU = Debug|Any CPU@@ -336,6 +342,46 @@ Global{804DBC7B-FBF4-4B2E-AAE9-D74C32985D3F}.Release|x86.ActiveCfg = Release|x86{804DBC7B-FBF4-4B2E-AAE9-D74C32985D3F}.Release|x86.Build.0 = Release|x86{804DBC7B-FBF4-4B2E-AAE9-D74C32985D3F}.Release|x86.Deploy.0 = Release|x86+ {12A1461D-3357-4007-BE15-9622E9513D09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Debug|Any CPU.Build.0 = Debug|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Debug|AnyCPU.Build.0 = Debug|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Debug|ARM64.ActiveCfg = Debug|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Debug|ARM64.Build.0 = Debug|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Debug|x64.ActiveCfg = Debug|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Debug|x64.Build.0 = Debug|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Debug|x86.ActiveCfg = Debug|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Debug|x86.Build.0 = Debug|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Release|Any CPU.ActiveCfg = Release|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Release|Any CPU.Build.0 = Release|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Release|AnyCPU.ActiveCfg = Release|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Release|AnyCPU.Build.0 = Release|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Release|ARM64.ActiveCfg = Release|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Release|ARM64.Build.0 = Release|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Release|x64.ActiveCfg = Release|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Release|x64.Build.0 = Release|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Release|x86.ActiveCfg = Release|Any CPU+ {12A1461D-3357-4007-BE15-9622E9513D09}.Release|x86.Build.0 = Release|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Debug|AnyCPU.Build.0 = Debug|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Debug|ARM64.ActiveCfg = Debug|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Debug|ARM64.Build.0 = Debug|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Debug|x64.ActiveCfg = Debug|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Debug|x64.Build.0 = Debug|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Debug|x86.ActiveCfg = Debug|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Debug|x86.Build.0 = Debug|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Release|Any CPU.Build.0 = Release|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Release|AnyCPU.ActiveCfg = Release|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Release|AnyCPU.Build.0 = Release|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Release|ARM64.ActiveCfg = Release|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Release|ARM64.Build.0 = Release|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Release|x64.ActiveCfg = Release|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Release|x64.Build.0 = Release|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Release|x86.ActiveCfg = Release|Any CPU+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA}.Release|x86.Build.0 = Release|Any CPUEndGlobalSectionGlobalSection(SolutionProperties) = preSolutionHideSolutionNode = FALSE@@ -360,6 +406,8 @@ Global{9E59352A-836D-47DE-AB02-F404A8345242} = {04F9E03E-B519-49C5-BC6A-2131ED9BADC0}{64B8DB6D-3168-48DE-95BD-BBE7BAB3A262} = {22EE9386-CEFA-47D8-97B2-09A63EDF7F2E}{804DBC7B-FBF4-4B2E-AAE9-D74C32985D3F} = {AFE37797-0A43-4838-8C1E-4D2D1446499C}+ {12A1461D-3357-4007-BE15-9622E9513D09} = {B20E4027-0777-4A75-A848-609594E9A6B0}+ {DB6B033B-584E-43CF-AC96-4F6548C96ECA} = {FA3821C4-74BB-4927-ABCC-0D0A12E097A2}EndGlobalSectionGlobalSection(ExtensibilityGlobals) = postSolutionSolutionGuid = {C2C953F5-F97F-4198-B15C-4947A886050F}diff --git a/src/Directory.Build.props b/src/Directory.Build.propsindex e1cfec3c3..ffeee8a52 100644--- a/src/Directory.Build.props+++ b/src/Directory.Build.props@@ -31,6 +31,9 @@<!-- Enable Central Package Management --><ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally><EnablePackageVersionOverride>false</EnablePackageVersionOverride>++ <!-- Keep generated code in `obj` folder -->+ <EmitCompilerGeneratedFiles>True</EmitCompilerGeneratedFiles></PropertyGroup><PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '16.0' ">diff --git a/src/Directory.Packages.props b/src/Directory.Packages.propsindex 842801004..f45ef1a3e 100644--- a/src/Directory.Packages.props+++ b/src/Directory.Packages.props@@ -19,6 +19,8 @@<PackageVersion Include="CommunityToolkit.Diagnostics" Version="$(CommunityToolkitVersion)" /><PackageVersion Include="CommunityToolkit.Mvvm" Version="$(CommunityToolkitVersion)" /><PackageVersion Include="coverlet.collector" Version="3.1.2" />+ <PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />+ <PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" /><PackageVersion Include="Microsoft.CSharp" Version="4.7.0" /><PackageVersion Include="Microsoft.Extensions.Logging" Version="$(DotNetVersion)" /><PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="$(DotNetVersion)" />diff --git a/src/app/dev/DevToys.Localization/DevToys.Localization.csproj b/src/app/dev/DevToys.Localization/DevToys.Localization.csprojnew file mode 100644index 000000000..7a0c241cc--- /dev/null+++ b/src/app/dev/DevToys.Localization/DevToys.Localization.csproj@@ -0,0 +1,32 @@+<Project Sdk="Microsoft.NET.Sdk">+ <PropertyGroup>+ <TargetFrameworks>$(NetCore)</TargetFrameworks>+ </PropertyGroup>+ <ItemGroup>+ <PackageReference Include="CommunityToolkit.Common" />+ <PackageReference Include="CommunityToolkit.Diagnostics" />+ <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />+ <PackageReference Include="Newtonsoft.Json" />+ <PackageReference Include="System.ComponentModel.Composition" />+ </ItemGroup>+ <ItemGroup>+ <ProjectReference+ Include="..\..\..\generators\ResxHelperGenerator\ResxHelperGenerator.csproj"+ OutputItemType="Analyzer"+ ReferenceOutputAssembly="false" />+ </ItemGroup>+ <ItemGroup>+ <Compile Update="Strings\Settings\Settings.Designer.cs">+ <DesignTime>True</DesignTime>+ <AutoGen>True</AutoGen>+ <DependentUpon>Settings.resx</DependentUpon>+ </Compile>+ </ItemGroup>+ <ItemGroup>+ <EmbeddedResource Update="Strings\Settings\Settings.resx">+ <Generator>PublicResXFileCodeGenerator</Generator>+ <LastGenOutput>Settings.Designer.cs</LastGenOutput>+ </EmbeddedResource>+ </ItemGroup>++</Project>\ No newline at end of filediff --git a/src/app/dev/DevToys.Localization/Strings/Settings/Settings.Designer.cs b/src/app/dev/DevToys.Localization/Strings/Settings/Settings.Designer.csnew file mode 100644index 000000000..bb1eebc42--- /dev/null+++ b/src/app/dev/DevToys.Localization/Strings/Settings/Settings.Designer.cs@@ -0,0 +1,72 @@+//------------------------------------------------------------------------------+// <auto-generated>+// 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.+// </auto-generated>+//------------------------------------------------------------------------------++namespace DevToys.Localization.Strings.Settings {+ using System;+++ /// <summary>+ /// A strongly-typed resource class, for looking up localized strings, etc.+ /// </summary>+ // 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()]+ public class Settings {++ private static global::System.Resources.ResourceManager resourceMan;++ private static global::System.Globalization.CultureInfo resourceCulture;++ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]+ internal Settings() {+ }++ /// <summary>+ /// Returns the cached ResourceManager instance used by this class.+ /// </summary>+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]+ public static global::System.Resources.ResourceManager ResourceManager {+ get {+ if (object.ReferenceEquals(resourceMan, null)) {+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DevToys.Localization.Strings.Settings.Settings", typeof(Settings).Assembly);+ resourceMan = temp;+ }+ return resourceMan;+ }+ }++ /// <summary>+ /// Overrides the current thread's CurrentUICulture property for all+ /// resource lookups using this strongly typed resource class.+ /// </summary>+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]+ public static global::System.Globalization.CultureInfo Culture {+ get {+ return resourceCulture;+ }+ set {+ resourceCulture = value;+ }+ }++ /// <summary>+ /// Looks up a localized string similar to Same as the system.+ /// </summary>+ public static string DefaultLanguage {+ get {+ return ResourceManager.GetString("DefaultLanguage", resourceCulture);+ }+ }+ }+}diff --git a/src/app/dev/DevToys.UI/Strings/en-US/Languages.resw b/src/app/dev/DevToys.Localization/Strings/Settings/Settings.ja-JP.resxsimilarity index 99%rename from src/app/dev/DevToys.UI/Strings/en-US/Languages.reswrename to src/app/dev/DevToys.Localization/Strings/Settings/Settings.ja-JP.resxindex d8ec3b95e..9b0686290 100644--- a/src/app/dev/DevToys.UI/Strings/en-US/Languages.resw+++ b/src/app/dev/DevToys.Localization/Strings/Settings/Settings.ja-JP.resx@@ -118,6 +118,6 @@<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader><data name="DefaultLanguage" xml:space="preserve">- <value>Same as Microsoft Windows</value>+ <value>Same as the system</value></data></root>\ No newline at end of filediff --git a/src/app/dev/DevToys.UI/Strings/ja-JP/Languages.resw b/src/app/dev/DevToys.Localization/Strings/Settings/Settings.resxsimilarity index 99%rename from src/app/dev/DevToys.UI/Strings/ja-JP/Languages.reswrename to src/app/dev/DevToys.Localization/Strings/Settings/Settings.resxindex d8ec3b95e..9b0686290 100644--- a/src/app/dev/DevToys.UI/Strings/ja-JP/Languages.resw+++ b/src/app/dev/DevToys.Localization/Strings/Settings/Settings.resx@@ -118,6 +118,6 @@<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader><data name="DefaultLanguage" xml:space="preserve">- <value>Same as Microsoft Windows</value>+ <value>Same as the system</value></data></root>\ No newline at end of filediff --git a/src/app/dev/DevToys.UI/DevToys.UI.csproj b/src/app/dev/DevToys.UI/DevToys.UI.csprojindex 9b17c9b49..d3933b873 100644--- a/src/app/dev/DevToys.UI/DevToys.UI.csproj+++ b/src/app/dev/DevToys.UI/DevToys.UI.csproj@@ -85,13 +85,13 @@</Page><PRIResource Include="**\*.resw" /><Content Include="Assets\**" />- <None Remove="Strings\ja-JP\Languages.resw" /><Compile Update="**\*.xaml.cs"><DependentUpon>%(Filename)</DependentUpon></Compile></ItemGroup><ItemGroup>+ <ProjectReference Include="..\DevToys.Localization\DevToys.Localization.csproj" /><ProjectReference Include="..\DevToys.MonacoEditor\DevToys.MonacoEditor.csproj" /><ProjectReference Include="..\DevToys.UI.Framework\DevToys.UI.Framework.csproj" /></ItemGroup>diff --git a/src/app/dev/DevToys.UI/LanguageDefinition.cs b/src/app/dev/DevToys.UI/LanguageDefinition.csindex f64a484d0..28eee4544 100644--- a/src/app/dev/DevToys.UI/LanguageDefinition.cs+++ b/src/app/dev/DevToys.UI/LanguageDefinition.cs@@ -41,7 +41,7 @@ public class LanguageDefinition#elseCulture = new CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.Languages[0]);#endif- DisplayName = Strings.Languages.DefaultLanguage;+ DisplayName = Localization.Strings.Settings.Settings.DefaultLanguage;InternalName = "default";}elsediff --git a/src/app/dev/DevToys.UI/LanguageManager.cs b/src/app/dev/DevToys.UI/LanguageManager.csindex a002f5a39..90020d9ca 100644--- a/src/app/dev/DevToys.UI/LanguageManager.cs+++ b/src/app/dev/DevToys.UI/LanguageManager.cs@@ -1,9 +1,6 @@using System.Globalization;using Windows.Globalization;using Microsoft.UI.Xaml;-using System.Resources;-using DevToys.UI.Strings;-using Windows.ApplicationModel.Resources;namespace DevToys.UI;@@ -33,26 +30,13 @@ public sealed class LanguageManagernew LanguageDefinition() // default language};-#if HAS_UNO- IReadOnlyList<string> supportedLanguageIdentifiers = ApplicationLanguages.ManifestLanguages;+ IReadOnlyList<string> supportedLanguageIdentifiers = Localization.CultureHelper.ApplicationCultures;for (int i = 0; i < supportedLanguageIdentifiers.Count; i++){AvailableLanguages.Add(new LanguageDefinition(supportedLanguageIdentifiers[i]));}-#else- IReadOnlyList<Windows.ApplicationModel.Resources.Core.ResourceCandidate> candidates- = Windows.ApplicationModel.Resources.Core.ResourceManager.Current- .MainResourceMap[$"DevToys.UI/{nameof(Languages)}/{nameof(Languages.DefaultLanguage)}"]- .Candidates;- for (int i = 0; i < candidates.Count; i++)- {- AvailableLanguages.Add(- new LanguageDefinition(- candidates[i].GetQualifierValue("Language")));- }-#endif}/// <summary>diff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/App.xaml.cs b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/App.xaml.csindex 9a7323374..8ffe1afe8 100644--- a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/App.xaml.cs+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/App.xaml.cs@@ -1,4 +1,6 @@-namespace DevToys.MauiBlazor;+using DevToys.Api.Core.Theme;++namespace DevToys.MauiBlazor;public partial class App : Application{@@ -6,6 +8,9 @@ public partial class App : Application{InitializeComponent();+ // Apply the app color theme.+ MauiProgram.MefComposer.Provider.Import<IThemeListener>().ApplyDesiredColorTheme();+MainPage = new MainPage();}}diff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Components/MefComponentBase.cs b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Components/MefFluentComponentBase.cssimilarity index 90%rename from src/app/dev/platforms/desktop/DevToys.MauiBlazor/Components/MefComponentBase.csrename to src/app/dev/platforms/desktop/DevToys.MauiBlazor/Components/MefFluentComponentBase.csindex f8af06e9c..ced8c9e4b 100644--- a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Components/MefComponentBase.cs+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Components/MefFluentComponentBase.cs@@ -4,7 +4,7 @@ using Microsoft.Fast.Components.FluentUI;namespace DevToys.MauiBlazor.Components;-internal abstract class MefComponentBase : FluentComponentBase+public abstract class MefFluentComponentBase : FluentComponentBase{#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.[Inject]diff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Components/MefLayoutComponentBase.cs b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Components/MefLayoutComponentBase.csnew file mode 100644index 000000000..14fce9d64--- /dev/null+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Components/MefLayoutComponentBase.cs@@ -0,0 +1,18 @@+using DevToys.Api;+using Microsoft.AspNetCore.Components;++namespace DevToys.MauiBlazor.Components;++public abstract class MefLayoutComponentBase : LayoutComponentBase+{+#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.+ [Inject]+ protected IMefProvider MefProvider { get; set; }+#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.++ protected override void OnInitialized()+ {+ MefProvider.SatisfyImports(this);+ base.OnInitialized();+ }+}diff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Languages/LanguageDefinition.cs b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Languages/LanguageDefinition.csnew file mode 100644index 000000000..8f72c858b--- /dev/null+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Languages/LanguageDefinition.cs@@ -0,0 +1,52 @@+using System.Globalization;++namespace DevToys.MauiBlazor.Core.Languages;++/// <summary>+/// Represents un language supported by the app.+/// </summary>+public class LanguageDefinition+{+ /// <summary>+ /// Unique internal name.+ /// </summary>+ public string InternalName { get; }++ /// <summary>+ /// Unique internal ID used to identify the language.+ /// </summary>+ public string Identifier { get; }++ /// <summary>+ /// The name of the language displayed to the user.+ /// </summary>+ public string DisplayName { get; }++ /// <summary>+ /// The culture to apply.+ /// </summary>+ public CultureInfo Culture { get; }++ public LanguageDefinition()+ : this(null)+ {+ }++ public LanguageDefinition(string? identifier)+ {+ if (string.IsNullOrEmpty(identifier))+ {+ Culture = CultureInfo.CurrentUICulture;+ DisplayName = Localization.Strings.Settings.Settings.DefaultLanguage;+ InternalName = "default";+ }+ else+ {+ Culture = new CultureInfo(identifier!);+ DisplayName = Culture.NativeName;+ InternalName = Culture.Name;+ }++ Identifier = Culture.Name;+ }+}diff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Languages/LanguageManager.cs b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Languages/LanguageManager.csnew file mode 100644index 000000000..11e2cd050--- /dev/null+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Languages/LanguageManager.cs@@ -0,0 +1,57 @@+using System.Globalization;++namespace DevToys.MauiBlazor.Core.Languages;++public sealed class LanguageManager+{+ private static LanguageManager? languageManager;++ /// <summary>+ /// Gets an instance of <see cref="LanguageManager"/>.+ /// </summary>+ public static LanguageManager Instance => languageManager ??= new LanguageManager();++ /// <summary>+ /// Gets if the text must be written from left to right or from right to left.+ /// </summary>+ public FlowDirection FlowDirection { get; private set; }++ /// <summary>+ /// Gets the list of available languages in the app.+ /// </summary>+ public List<LanguageDefinition> AvailableLanguages { get; }++ public LanguageManager()+ {+ AvailableLanguages = new List<LanguageDefinition>+ {+ new LanguageDefinition() // default language+ };++ IReadOnlyList<string> supportedLanguageIdentifiers = DevToys.Localization.CultureHelper.ApplicationCultures;+ for (int i = 0; i < supportedLanguageIdentifiers.Count; i++)+ {+ AvailableLanguages.Add(+ new LanguageDefinition(+ supportedLanguageIdentifiers[i]));+ }+ }++ /// <summary>+ /// Change the current culture of the application+ /// </summary>+ public void SetCurrentCulture(LanguageDefinition language)+ {+ CultureInfo.DefaultThreadCurrentCulture = language.Culture;+ CultureInfo.DefaultThreadCurrentUICulture = language.Culture;++ if (language.Culture.TextInfo.IsRightToLeft)+ {+ FlowDirection = FlowDirection.RightToLeft;+ }+ else+ {+ FlowDirection = FlowDirection.LeftToRight;+ }+ }+}diff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Settings/SettingsStorage.cs b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Settings/SettingsStorage.csindex 41449cc60..960ec9569 100644--- a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Settings/SettingsStorage.cs+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Settings/SettingsStorage.cs@@ -14,7 +14,7 @@ internal sealed class SettingsStorage : ISettingsStorage{if (Preferences.Default.ContainsKey(settingName)){- value = Preferences.Default.Get<object?>(settingName, default);+ value = Preferences.Default.Get<string?>(settingName, default);return true;}@@ -24,6 +24,7 @@ internal sealed class SettingsStorage : ISettingsStoragepublic void WriteSetting(string settingName, object? value){- Preferences.Default.Set(settingName, value);+ string? valueString = value?.ToString();+ Preferences.Default.Set(settingName, valueString);}}diff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Theme/ThemeListener.cs b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Theme/ThemeListener.csnew file mode 100644index 000000000..741425f3f--- /dev/null+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Core/Theme/ThemeListener.cs@@ -0,0 +1,115 @@+using DevToys.Api;+using DevToys.Api.Core.Theme;+using DevToys.Core.Settings;++namespace DevToys.MauiBlazor.Core.Theme;++[Export(typeof(IThemeListener))]+internal sealed class ThemeListener : IThemeListener+{+ private readonly ISettingsProvider _settingsProvider;++ [ImportingConstructor]+ public ThemeListener(ISettingsProvider settingsProvider)+ {+ _settingsProvider = settingsProvider;++ _settingsProvider.SettingChanged += SettingsProvider_SettingChanged;++ Guard.IsNotNull(Application.Current);+ if (Application.Current.RequestedTheme == AppTheme.Dark)+ {+ CurrentSystemTheme = AvailableApplicationTheme.Dark;+ }+ else+ {+ CurrentSystemTheme = AvailableApplicationTheme.Light;+ }++ // TODO: Support High contrast+ IsHighContrast = false;+ }++ public AvailableApplicationTheme CurrentSystemTheme { get; private set; }++ public AvailableApplicationTheme CurrentAppTheme => _settingsProvider.GetSetting(PredefinedSettings.Theme);++ public ApplicationTheme ActualAppTheme { get; private set; }++ public bool IsHighContrast { get; private set; }++ public event EventHandler? ThemeChanged;++ public void ApplyDesiredColorTheme()+ {+ AvailableApplicationTheme theme = CurrentAppTheme;++ if (theme == AvailableApplicationTheme.Default)+ {+ theme = CurrentSystemTheme;+ }++ // Set theme for window root.+ if (theme == AvailableApplicationTheme.Dark)+ {+ ActualAppTheme = ApplicationTheme.Dark;+ }+ else+ {+ ActualAppTheme = ApplicationTheme.Light;+ }+ }++ public void UpdateThemeIfNeeded()+ {+ AvailableApplicationTheme currentAppTheme;+ Guard.IsNotNull(Application.Current);+ if (Application.Current.RequestedTheme == AppTheme.Dark)+ {+ currentAppTheme = AvailableApplicationTheme.Dark;+ }+ else+ {+ currentAppTheme = AvailableApplicationTheme.Light;+ }++ if (CurrentSystemTheme != currentAppTheme /*|| IsHighContrast != _accessible.HighContrast // TODO */)+ {+ UpdateProperties();+ }+ }++ private void SettingsProvider_SettingChanged(object? sender, SettingChangedEventArgs e)+ {+ if (string.Equals(PredefinedSettings.Theme.Name, e.SettingName, StringComparison.Ordinal))+ {+ ApplyDesiredColorTheme();+ ThemeChanged?.Invoke(this, EventArgs.Empty);+ }+ }++ /// <summary>+ /// Set our current properties and fire a change notification.+ /// </summary>+ private void UpdateProperties()+ {+ // TODO: Support High contrast+ IsHighContrast = false;++ AvailableApplicationTheme currentAppTheme;+ Guard.IsNotNull(Application.Current);+ if (Application.Current.RequestedTheme == AppTheme.Dark)+ {+ currentAppTheme = AvailableApplicationTheme.Dark;+ }+ else+ {+ currentAppTheme = AvailableApplicationTheme.Light;+ }++ CurrentSystemTheme = currentAppTheme;++ ApplyDesiredColorTheme();+ ThemeChanged?.Invoke(this, EventArgs.Empty);+ }+}diff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/DevToys.MauiBlazor.csproj b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/DevToys.MauiBlazor.csprojindex dcc300d8e..97688bf0f 100644--- a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/DevToys.MauiBlazor.csproj+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/DevToys.MauiBlazor.csproj@@ -73,11 +73,17 @@<!-- Raw Assets (also remove the "Resources\Raw" prefix) --><MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />++ <!-- TypeScript -->+ <ConfigFiles Include="tsconfig.json" />+ <TypeScriptCompile Remove="**\*.ts" />+ <None Include="**\*.ts" /></ItemGroup><ItemGroup><ProjectReference Include="..\..\..\DevToys.Api\DevToys.Api.csproj" /><ProjectReference Include="..\..\..\DevToys.Core\DevToys.Core.csproj" />+ <ProjectReference Include="..\..\..\DevToys.Localization\DevToys.Localization.csproj" /></ItemGroup><ItemGroup>@@ -92,6 +98,7 @@<ItemGroup><Content Include="..\..\..\DevToys.MonacoEditor\monaco-editor\*" LinkBase="wwwroot\lib\monaco-editor\%(RecursiveDir)/%(Filename)%(Extension)" /><Content Include="..\..\..\DevToys.MonacoEditor\monaco-editor\min\**\*" Link="wwwroot\lib\monaco-editor\min\%(RecursiveDir)/%(Filename)%(Extension)" />+ <TypeScriptCompile Remove="wwwroot\lib\monaco-editor\**\*.*" /></ItemGroup></Project>\ No newline at end of filediff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/MauiProgram.cs b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/MauiProgram.csindex 0165507e1..7d95ae8de 100644--- a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/MauiProgram.cs+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/MauiProgram.cs@@ -1,13 +1,16 @@-using Microsoft.Extensions.Logging;-using Microsoft.Fast.Components.FluentUI.Infrastructure;-using Microsoft.Fast.Components.FluentUI;+using DevToys.Api;using DevToys.Core.Mef;+using DevToys.Core.Settings;+using DevToys.MauiBlazor.Core.Languages;+using Microsoft.Extensions.Logging;+using Microsoft.Fast.Components.FluentUI;+using Microsoft.Fast.Components.FluentUI.Infrastructure;namespace DevToys.MauiBlazor;public static class MauiProgram{- private static readonly MefComposer mefComposer = new();+ internal static readonly MefComposer MefComposer = new();public static MauiApp CreateMauiApp(){@@ -29,7 +32,14 @@ public static class MauiProgrambuilder.Logging.AddDebug();#endif- builder.Services.AddSingleton(provider => mefComposer.Provider);+ builder.Services.AddSingleton(provider => MefComposer.Provider);++ // Set the user-defined language.+ string? languageIdentifier = MefComposer.Provider.Import<ISettingsProvider>().GetSetting(PredefinedSettings.Language);+ LanguageDefinition languageDefinition+ = LanguageManager.Instance.AvailableLanguages.FirstOrDefault(l => string.Equals(l.InternalName, languageIdentifier))+ ?? LanguageManager.Instance.AvailableLanguages[0];+ LanguageManager.Instance.SetCurrentCulture(languageDefinition);return builder.Build();}diff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razorindex b518a0420..d92104763 100644--- a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor@@ -1,32 +1,36 @@-@inherits LayoutComponentBase+@inherits MefLayoutComponentBase-<StackPanel Orientation="Orientation.Horizontal" Width="100%">- <div>- <NavigationView Width="320">- <MenuItemsSource>- <NavigationViewItem Text="Never" Icon="@(FluentIcons.LeafOne)" />- <NavigationViewItem Text="Gonna" Icon="@(FluentIcons.LeafOne)" />- <NavigationViewItem Text="Give" Icon="@(FluentIcons.LeafOne)">- <NavigationViewItem Text="You" Icon="@(FluentIcons.LeafOne)" />- <NavigationViewItem Text="Up" Icon="@(FluentIcons.LeafTwo)" />- </NavigationViewItem>- <NavigationViewItem Text="Never" Icon="@(FluentIcons.LeafOne)">- <NavigationViewItem Text="Gonna" Icon="@(FluentIcons.LeafOne)" />- <NavigationViewItem Text="Let" Icon="@(FluentIcons.LeafOne)" />- </NavigationViewItem>- <NavigationViewItem Text="You" Icon="@(FluentIcons.LeafOne)">- <NavigationViewItem Text="Down" Icon="@(FluentIcons.LeafTwo)" />- </NavigationViewItem>- </MenuItemsSource>- <FooterMenuItemsSource>- <NavigationViewItem Text="Settings" Icon="@(FluentIcons.Settings)" />- </FooterMenuItemsSource>- </NavigationView>- </div>+<FluentDesignSystemProvider BaseLayerLuminance=@_baseLayerLuminanceValue>+ <div id="container">+ <StackPanel Orientation="Orientation.Horizontal" Width="100%">+ <div>+ <NavigationView Width="320">+ <MenuItemsSource>+ <NavigationViewItem Text="Never" Icon="@(FluentIcons.LeafOne)" />+ <NavigationViewItem Text="Gonna" Icon="@(FluentIcons.LeafOne)" />+ <NavigationViewItem Text="Give" Icon="@(FluentIcons.LeafOne)">+ <NavigationViewItem Text="You" Icon="@(FluentIcons.LeafOne)" />+ <NavigationViewItem Text="Up" Icon="@(FluentIcons.LeafTwo)" />+ </NavigationViewItem>+ <NavigationViewItem Text="Never" Icon="@(FluentIcons.LeafOne)">+ <NavigationViewItem Text="Gonna" Icon="@(FluentIcons.LeafOne)" />+ <NavigationViewItem Text="Let" Icon="@(FluentIcons.LeafOne)" />+ </NavigationViewItem>+ <NavigationViewItem Text="You" Icon="@(FluentIcons.LeafOne)">+ <NavigationViewItem Text="Down" Icon="@(FluentIcons.LeafTwo)" />+ </NavigationViewItem>+ </MenuItemsSource>+ <FooterMenuItemsSource>+ <NavigationViewItem Text="Settings" Icon="@(FluentIcons.Settings)" />+ </FooterMenuItemsSource>+ </NavigationView>+ </div>- <main>- <article>- @Body- </article>- </main>-</StackPanel>\ No newline at end of file+ <main>+ <article>+ @Body+ </article>+ </main>+ </StackPanel>+ </div>+</FluentDesignSystemProvider>\ No newline at end of filediff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor.cs b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor.csindex fb92534a3..8488853f9 100644--- a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor.cs+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor.cs@@ -1,18 +1,54 @@using DevToys.Api;+using DevToys.Api.Core.Theme;+using DevToys.MauiBlazor.Components;using Microsoft.AspNetCore.Components;+using Microsoft.Fast.Components.FluentUI;+using Microsoft.Fast.Components.FluentUI.DesignTokens;namespace DevToys.MauiBlazor.Shared;-public partial class MainLayout : LayoutComponentBase+public partial class MainLayout : MefLayoutComponentBase{-#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.+ [Import]+ private IThemeListener ThemeListener { get; set; } = default!;+[Inject]- protected IMefProvider MefProvider { get; set; }-#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.+ private GlobalState GlobalState { get; set; } = default!;++ private float _baseLayerLuminanceValue;++ protected override async Task OnAfterRenderAsync(bool firstRender)+ {+ if (firstRender)+ {+ ThemeListener.ThemeChanged += ThemeListener_ThemeChanged;++ ApplyTheme();+ }++ await base.OnAfterRenderAsync(firstRender);+ }++ private void ThemeListener_ThemeChanged(object? sender, EventArgs e)+ {+ ApplyTheme();+ }- protected override void OnInitialized()+ private void ApplyTheme(){- MefProvider.SatisfyImports(this);- base.OnInitialized();+ StandardLuminance theme;+ if (ThemeListener.ActualAppTheme == ApplicationTheme.Dark)+ {+ theme = StandardLuminance.DarkMode;+ }+ else+ {+ theme = StandardLuminance.LightMode;+ }++ _baseLayerLuminanceValue = theme.GetLuminanceValue();+ GlobalState.SetLuminance(theme);++ StateHasChanged();}}diff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor.css b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor.cssindex 7fa47a326..4ec9a3289 100644--- a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor.css+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor.css@@ -1,3 +1,12 @@+#container {+ width: 100%;+ height: 100%;+ position: fixed;+ top: 0;+ left: 0;+ background-color: var(--neutral-layer-4);+}+main {width: 100%;-}\ No newline at end of file+}diff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor.ts b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor.tsnew file mode 100644index 000000000..5f282702b--- /dev/null+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/Shared/MainLayout.razor.ts@@ -0,0 +1 @@+\ No newline at end of filediff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/_Imports.razor b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/_Imports.razorindex 7af23c99e..b75f35bb5 100644--- a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/_Imports.razor+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/_Imports.razor@@ -4,6 +4,7 @@@using Microsoft.AspNetCore.Components.Web@using Microsoft.AspNetCore.Components.Web.Virtualization@using Microsoft.Fast.Components.FluentUI+@using Microsoft.Fast.Components.FluentUI.DesignTokens@using Microsoft.JSInterop@using DevToys.MauiBlazor@using DevToys.MauiBlazor.Componentsdiff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/tsconfig.json b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/tsconfig.jsonnew file mode 100644index 000000000..cb5ed8f5d--- /dev/null+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/tsconfig.json@@ -0,0 +1,13 @@+{+ "compileOnSave": true,+ "compilerOptions": {+ "target": "es2015", // Warning: Monaco editor breaks when using something else than es2015+ "lib": [ "es2015", "DOM" ], // Warning: Monaco editor breaks when using something else than es2015+ "sourceMap": true,+ "allowJs": false+ },+ "include": [+ "**/*.ts"+ ],+ "exclude": [ "wwwroot" ]+}\ No newline at end of filediff --git a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/wwwroot/css/app.css b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/wwwroot/css/app.cssindex 389175528..a33f2d102 100644--- a/src/app/dev/platforms/desktop/DevToys.MauiBlazor/wwwroot/css/app.css+++ b/src/app/dev/platforms/desktop/DevToys.MauiBlazor/wwwroot/css/app.css@@ -1,4 +1,6 @@-html, body {+@import '/_content/Microsoft.Fast.Components.FluentUI/css/reboot.css';++html, body {font-family: -apple-system, /* San Francisco in Safari (on Mac OS X and iOS); Neue Helvetica and Lucida Grande on older versions of Mac OS X. */system-ui, /* Default UI font on a given platform. */BlinkMacSystemFont, /* Equivalent of -apple-system, for Chrome on Mac OS X. */diff --git a/src/generators/ResxHelperGenerator/CultureHelperGenerator.cs b/src/generators/ResxHelperGenerator/CultureHelperGenerator.csnew file mode 100644index 000000000..a5ab374cf--- /dev/null+++ b/src/generators/ResxHelperGenerator/CultureHelperGenerator.cs@@ -0,0 +1,132 @@+using System.Collections.Generic;+using System.Diagnostics;+using System.IO;+using System.Linq;+using System.Text;+using Microsoft.CodeAnalysis;+using Microsoft.CodeAnalysis.CSharp;+using Microsoft.CodeAnalysis.Text;++namespace ResxHelperGenerator;++[Generator]+#pragma warning disable RS1036 // Specify analyzer banned API enforcement setting+public class CultureHelperGenerator : ISourceGenerator+#pragma warning restore RS1036 // Specify analyzer banned API enforcement setting+{+ public void Initialize(GeneratorInitializationContext context)+ {+ // No initialization required for this one+ }++ public void Execute(GeneratorExecutionContext context)+ {+#if DEBUG+ if (!Debugger.IsAttached)+ {+ // Uncomment to debug+ // Debugger.Launch();+ }+#endif++ if (InitialCheckUp(context, out string projectRootPath, out string projectRootNamespace))+ {+ string[] cultures = DetectAllCutlures(projectRootPath);++ if (!context.CancellationToken.IsCancellationRequested)+ {+ GenerateAvailableCultureListSourceFile(context, projectRootNamespace, cultures);+ }+ }+ }++ private bool InitialCheckUp(GeneratorExecutionContext context, out string projectRootPath, out string projectRootNamespace)+ {+ projectRootPath = null;+ projectRootNamespace = null;++ if (context.Compilation is not CSharpCompilation)+ {+ // the converter only support C# for the moment+ context.ReportDiagnostic(Diagnostic.Create(new DiagnosticDescriptor(+ "RHG0001",+ "Language not supported",+ "ResxHelperGenerator source generator only supports C#.",+ "ResxHelperGenerator.Errors",+ DiagnosticSeverity.Error,+ true), (Location)null));+ return false;+ }++ // retrieve the project settings.+ if (!context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.DefaultLanguage", out _)+ || !context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.RootNamespace", out projectRootNamespace)+ || !context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.MSBuildProjectFullPath", out string projectFileFullPath)+ || !context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.OutputType", out _))+ {+ // error+ context.ReportDiagnostic(Diagnostic.Create(new DiagnosticDescriptor(+ "RHG0002",+ "Build properties missing",+ "Build properties are not exposed to ResxHelperGenerator source generator",+ "ResxHelperGenerator.Errors",+ DiagnosticSeverity.Error,+ true), (Location)null));+ return false;+ }++ projectRootPath = Path.GetDirectoryName(projectFileFullPath);+ return true;+ }++ private string[] DetectAllCutlures(string projectRootPath)+ {+ var cultures = new HashSet<string>() { "en-US" };++ string[] resxFiles = Directory.GetFiles(projectRootPath, "*.resx", SearchOption.AllDirectories);+ for (int i = 0; i < resxFiles.Length; i++)+ {+ string filePath = resxFiles[i].Trim();+ string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath);+ string cultureName = fileNameWithoutExtension.Split(new[] { '.' }, System.StringSplitOptions.RemoveEmptyEntries).Last();+ if (cultureName.Length == 2 || (cultureName.Length == 5 && cultureName.Contains("-")))+ {+ cultures.Add(cultureName);+ }+ }++ return cultures.ToArray();+ }++ private void GenerateAvailableCultureListSourceFile(GeneratorExecutionContext context, string projectRootNamespace, string[] cultures)+ {+ var builder = new StringBuilder();+ builder.AppendLine("//------------------------------------------------------------------------------");+ builder.AppendLine("// <auto-generated>");+ builder.AppendLine("// This code was generated by ResxHelperGenerator.");+ builder.AppendLine("//");+ builder.AppendLine("// Changes to this file may cause incorrect behavior and will be lost if");+ builder.AppendLine("// the code is regenerated.");+ builder.AppendLine("// </auto-generated>");+ builder.AppendLine("//------------------------------------------------------------------------------");+ builder.AppendLine("");+ builder.AppendLine($"namespace {projectRootNamespace};");+ builder.AppendLine("");+ builder.AppendLine("public static class CultureHelper");+ builder.AppendLine("{");+ builder.AppendLine(" public static readonly string[] ApplicationCultures");+ builder.AppendLine(" = new string[]");+ builder.AppendLine(" {");++ for (int i = 0; i < cultures.Length; i++)+ {+ builder.AppendLine($" \"{cultures[i]}\",");+ }++ builder.AppendLine(" };");+ builder.AppendLine("}");++ string sourceCode = builder.ToString();+ context.AddSource("CultureHelper.g.cs", SourceText.From(sourceCode, Encoding.UTF8));+ }+}diff --git a/src/generators/ResxHelperGenerator/ResxHelperGenerator.csproj b/src/generators/ResxHelperGenerator/ResxHelperGenerator.csprojnew file mode 100644index 000000000..9d94f9a6e--- /dev/null+++ b/src/generators/ResxHelperGenerator/ResxHelperGenerator.csproj@@ -0,0 +1,15 @@+<Project Sdk="Microsoft.NET.Sdk">++ <PropertyGroup>+ <TargetFramework>netstandard2.0</TargetFramework>+ <IncludeBuildOutput>false</IncludeBuildOutput>+ <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>+ <LangVersion>latest</LangVersion>+ </PropertyGroup>++ <ItemGroup>+ <PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />+ <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />+ </ItemGroup>++</Project>