From 499405beeb14aada55701d703ec51508edba0fde Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Wed, 23 Aug 2023 19:50:18 -0400 Subject: [PATCH] Localization --- .../ShinyApp/.template.config/ide.host.json | 7 +++++++ .../ShinyApp/.template.config/template.json | 11 +++++++++++ ProjectTemplates/ShinyApp/GlobalUsings.cs | 3 +++ ProjectTemplates/ShinyApp/MainViewModel.cs | 7 ++++++- ProjectTemplates/ShinyApp/MainViewModel.resx | 18 ++++++++++++++++++ ProjectTemplates/ShinyApp/ShinyApp.csproj | 15 ++++++++++----- 6 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 ProjectTemplates/ShinyApp/MainViewModel.resx diff --git a/ProjectTemplates/ShinyApp/.template.config/ide.host.json b/ProjectTemplates/ShinyApp/.template.config/ide.host.json index 56d570e..679f999 100644 --- a/ProjectTemplates/ShinyApp/.template.config/ide.host.json +++ b/ProjectTemplates/ShinyApp/.template.config/ide.host.json @@ -32,6 +32,13 @@ }, "isVisible": true }, + { + "id": "localization", + "name":{ + "text": "Add Localization (Microsoft.Extensions.Localization)" + }, + "isVisible": true + }, { "id": "configuration", "name": { diff --git a/ProjectTemplates/ShinyApp/.template.config/template.json b/ProjectTemplates/ShinyApp/.template.config/template.json index cd08abf..7c53350 100644 --- a/ProjectTemplates/ShinyApp/.template.config/template.json +++ b/ProjectTemplates/ShinyApp/.template.config/template.json @@ -85,6 +85,13 @@ "description": "Add Shiny Framework by Allan Ritchie - Documentation https://github.com/shinyorg/framework - Lots of helpful services like navigation, zero boilerplate MVVM properties, viewmodel validation, localization, viewmodel lifecycles, dialog services, and more", "displayName": "Add Shiny Framework (Shiny + ReactiveUI + Prism)" }, + "localization":{ + "type": "parameter", + "datatype": "bool", + "defaultValue": "true", + "description": "Add Localization (Microsoft.Extensions.Localization)", + "displayName": "Add Localization (Microsoft.Extensions.Localization)" + }, "configuration": { "type": "parameter", "datatype": "bool", @@ -526,6 +533,10 @@ "condition": "(settings == false)", "exclude": "AppSettings.cs" }, + { + "condition": "(localization == false)", + "exclude": "MainViewModel.resx" + }, { "condition": "(usemsalbasic == false && usemsalb2c == false)", "exclude": "Platforms/Android/MsalActivity.cs" diff --git a/ProjectTemplates/ShinyApp/GlobalUsings.cs b/ProjectTemplates/ShinyApp/GlobalUsings.cs index 44efffd..10874a0 100644 --- a/ProjectTemplates/ShinyApp/GlobalUsings.cs +++ b/ProjectTemplates/ShinyApp/GlobalUsings.cs @@ -15,6 +15,9 @@ global using Prism.Navigation; global using Prism.Services; #endif +#if shinyframework || localization +global using Microsoft.Extensions.Localization; +#endif #if shinyframework || communitytoolkit global using CommunityToolkit.Maui; #endif diff --git a/ProjectTemplates/ShinyApp/MainViewModel.cs b/ProjectTemplates/ShinyApp/MainViewModel.cs index ac95ace..cf1abdb 100644 --- a/ProjectTemplates/ShinyApp/MainViewModel.cs +++ b/ProjectTemplates/ShinyApp/MainViewModel.cs @@ -11,10 +11,15 @@ public MainViewModel(BaseServices services) : base(services) {} #else public class MainViewModel : NotifyPropertyChanged { +#if localization + public MainViewModel(IStringLocalizer localizer) + { + } +#else public MainViewModel() { } - +#endif string property; public string Property diff --git a/ProjectTemplates/ShinyApp/MainViewModel.resx b/ProjectTemplates/ShinyApp/MainViewModel.resx new file mode 100644 index 0000000..e2644ea --- /dev/null +++ b/ProjectTemplates/ShinyApp/MainViewModel.resx @@ -0,0 +1,18 @@ + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + This is test localization + + \ No newline at end of file diff --git a/ProjectTemplates/ShinyApp/ShinyApp.csproj b/ProjectTemplates/ShinyApp/ShinyApp.csproj index aadbee4..32164aa 100644 --- a/ProjectTemplates/ShinyApp/ShinyApp.csproj +++ b/ProjectTemplates/ShinyApp/ShinyApp.csproj @@ -4,10 +4,12 @@ + $(TargetFrameworks);{DOTNET_TFM}-ios + $(TargetFrameworks);{DOTNET_TFM}-android - {DOTNET_TFM}-android;{DOTNET_TFM}-ios;{DOTNET_TFM}-maccatalyst + $(TargetFrameworks);{DOTNET_TFM}-maccatalyst - {DOTNET_TFM}-android;{DOTNET_TFM}-ios + Exe ShinyApp @@ -26,7 +28,7 @@ 1.0 1 - 3.0.0-beta-0273 + 3.0.0-beta-0277 @@ -141,7 +143,7 @@ - + @@ -149,11 +151,14 @@ - + + + +