From e4a13243932c2450b8616e56757c49a945be2f21 Mon Sep 17 00:00:00 2001 From: "DarkLiKally (Stefan Sch)" Date: Wed, 10 Oct 2018 17:48:50 +0200 Subject: [PATCH] Added examples for console applications; Minor bugfix --- I18Next.Net.sln | 14 ++- .../Example.ConsoleApp.NetCore.csproj | 17 +++ samples/Example.ConsoleApp.NetCore/Program.cs | 114 ++++++++++++++++++ .../Example.ConsoleApp.NetFramework.csproj | 62 ++++++++++ .../Program.cs | 41 +++++++ .../Properties/AssemblyInfo.cs | 35 ++++++ .../Controllers/HomeController.cs | 0 .../Example.WebApp/Example.WebApp.csproj | 0 .../Example.WebApp/Models/ErrorViewModel.cs | 0 .../Example.WebApp/Program.cs | 0 .../Example.WebApp/Startup.cs | 0 .../Example.WebApp/Views/Home/About.cshtml | 0 .../Example.WebApp/Views/Home/Contact.cshtml | 0 .../Example.WebApp/Views/Home/Index.cshtml | 0 .../Example.WebApp/Views/Home/Privacy.cshtml | 0 .../Example.WebApp/Views/Shared/Error.cshtml | 0 .../Views/Shared/_CookieConsentPartial.cshtml | 0 .../Views/Shared/_Layout.cshtml | 0 .../Shared/_ValidationScriptsPartial.cshtml | 0 .../Example.WebApp/Views/_ViewImports.cshtml | 0 .../Example.WebApp/Views/_ViewStart.cshtml | 0 .../appsettings.Development.json | 0 .../Example.WebApp/appsettings.json | 0 .../locales/de/translation.json | 0 .../locales/en/translation.json | 0 .../Example.WebApp/wwwroot/css/site.css | 0 .../Example.WebApp/wwwroot/css/site.min.css | 0 .../Example.WebApp/wwwroot/favicon.ico | Bin .../Example.WebApp/wwwroot/images/banner1.svg | 0 .../Example.WebApp/wwwroot/images/banner2.svg | 0 .../Example.WebApp/wwwroot/images/banner3.svg | 0 .../Example.WebApp/wwwroot/js/site.js | 0 .../Example.WebApp/wwwroot/js/site.min.js | 0 .../wwwroot/lib/bootstrap/.bower.json | 0 .../wwwroot/lib/bootstrap/LICENSE | 0 .../bootstrap/dist/css/bootstrap-theme.css | 0 .../dist/css/bootstrap-theme.css.map | 0 .../dist/css/bootstrap-theme.min.css | 0 .../dist/css/bootstrap-theme.min.css.map | 0 .../lib/bootstrap/dist/css/bootstrap.css | 0 .../lib/bootstrap/dist/css/bootstrap.css.map | 0 .../lib/bootstrap/dist/css/bootstrap.min.css | 0 .../bootstrap/dist/css/bootstrap.min.css.map | 0 .../fonts/glyphicons-halflings-regular.eot | Bin .../fonts/glyphicons-halflings-regular.svg | 0 .../fonts/glyphicons-halflings-regular.ttf | Bin .../fonts/glyphicons-halflings-regular.woff | Bin .../fonts/glyphicons-halflings-regular.woff2 | Bin .../lib/bootstrap/dist/js/bootstrap.js | 0 .../lib/bootstrap/dist/js/bootstrap.min.js | 0 .../wwwroot/lib/bootstrap/dist/js/npm.js | 0 .../jquery-validation-unobtrusive/.bower.json | 0 .../jquery-validation-unobtrusive/LICENSE.txt | 0 .../jquery.validate.unobtrusive.js | 0 .../jquery.validate.unobtrusive.min.js | 0 .../wwwroot/lib/jquery-validation/.bower.json | 0 .../wwwroot/lib/jquery-validation/LICENSE.md | 0 .../dist/additional-methods.js | 0 .../dist/additional-methods.min.js | 0 .../jquery-validation/dist/jquery.validate.js | 0 .../dist/jquery.validate.min.js | 0 .../wwwroot/lib/jquery/.bower.json | 0 .../wwwroot/lib/jquery/LICENSE.txt | 0 .../wwwroot/lib/jquery/dist/jquery.js | 0 .../wwwroot/lib/jquery/dist/jquery.min.js | 0 .../wwwroot/lib/jquery/dist/jquery.min.map | 0 .../Builder/I18NextBuilder.cs | 25 ++-- src/I18Next.Net/Backends/InMemoryBackend.cs | 2 +- src/I18Next.Net/Plugins/DefaultTranslator.cs | 16 +++ 69 files changed, 317 insertions(+), 9 deletions(-) create mode 100644 samples/Example.ConsoleApp.NetCore/Example.ConsoleApp.NetCore.csproj create mode 100644 samples/Example.ConsoleApp.NetCore/Program.cs create mode 100644 samples/Example.ConsoleApp.NetFramework/Example.ConsoleApp.NetFramework.csproj create mode 100644 samples/Example.ConsoleApp.NetFramework/Program.cs create mode 100644 samples/Example.ConsoleApp.NetFramework/Properties/AssemblyInfo.cs rename {examples => samples}/Example.WebApp/Controllers/HomeController.cs (100%) rename {examples => samples}/Example.WebApp/Example.WebApp.csproj (100%) rename {examples => samples}/Example.WebApp/Models/ErrorViewModel.cs (100%) rename {examples => samples}/Example.WebApp/Program.cs (100%) rename {examples => samples}/Example.WebApp/Startup.cs (100%) rename {examples => samples}/Example.WebApp/Views/Home/About.cshtml (100%) rename {examples => samples}/Example.WebApp/Views/Home/Contact.cshtml (100%) rename {examples => samples}/Example.WebApp/Views/Home/Index.cshtml (100%) rename {examples => samples}/Example.WebApp/Views/Home/Privacy.cshtml (100%) rename {examples => samples}/Example.WebApp/Views/Shared/Error.cshtml (100%) rename {examples => samples}/Example.WebApp/Views/Shared/_CookieConsentPartial.cshtml (100%) rename {examples => samples}/Example.WebApp/Views/Shared/_Layout.cshtml (100%) rename {examples => samples}/Example.WebApp/Views/Shared/_ValidationScriptsPartial.cshtml (100%) rename {examples => samples}/Example.WebApp/Views/_ViewImports.cshtml (100%) rename {examples => samples}/Example.WebApp/Views/_ViewStart.cshtml (100%) rename {examples => samples}/Example.WebApp/appsettings.Development.json (100%) rename {examples => samples}/Example.WebApp/appsettings.json (100%) rename {examples => samples}/Example.WebApp/locales/de/translation.json (100%) rename {examples => samples}/Example.WebApp/locales/en/translation.json (100%) rename {examples => samples}/Example.WebApp/wwwroot/css/site.css (100%) rename {examples => samples}/Example.WebApp/wwwroot/css/site.min.css (100%) rename {examples => samples}/Example.WebApp/wwwroot/favicon.ico (100%) rename {examples => samples}/Example.WebApp/wwwroot/images/banner1.svg (100%) rename {examples => samples}/Example.WebApp/wwwroot/images/banner2.svg (100%) rename {examples => samples}/Example.WebApp/wwwroot/images/banner3.svg (100%) rename {examples => samples}/Example.WebApp/wwwroot/js/site.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/js/site.min.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/.bower.json (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/LICENSE (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.css (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.css.map (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.min.css (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.min.css.map (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.css (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.css.map (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css.map (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.svg (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/js/bootstrap.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/bootstrap/dist/js/npm.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/.bower.json (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery-validation/.bower.json (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery-validation/LICENSE.md (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery-validation/dist/additional-methods.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery-validation/dist/additional-methods.min.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery-validation/dist/jquery.validate.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery-validation/dist/jquery.validate.min.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery/.bower.json (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery/LICENSE.txt (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery/dist/jquery.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery/dist/jquery.min.js (100%) rename {examples => samples}/Example.WebApp/wwwroot/lib/jquery/dist/jquery.min.map (100%) diff --git a/I18Next.Net.sln b/I18Next.Net.sln index 22450ae..d22951f 100644 --- a/I18Next.Net.sln +++ b/I18Next.Net.sln @@ -12,10 +12,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "I18Next.Net.Tests", "tests\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "I18Next.Net.AspNetCore", "src\I18Next.Net.AspNetCore\I18Next.Net.AspNetCore.csproj", "{AC1CFDD9-1DBC-4E21-A1CF-F9C154BBF177}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.WebApp", "examples\Example.WebApp\Example.WebApp.csproj", "{7A9BDD90-BC7A-4B7D-A3F0-42A83D04E6C3}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.WebApp", "samples\Example.WebApp\Example.WebApp.csproj", "{7A9BDD90-BC7A-4B7D-A3F0-42A83D04E6C3}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "I18Next.Net.Abstractions", "src\I18Next.Net.Abstractions\I18Next.Net.Abstractions.csproj", "{42AB2562-8DA6-41E1-ABD5-152DDD622E6D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.ConsoleApp.NetCore", "samples\Example.ConsoleApp.NetCore\Example.ConsoleApp.NetCore.csproj", "{4F2A9939-3351-465F-9E4C-12616F64A0CD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.ConsoleApp.NetFramework", "samples\Example.ConsoleApp.NetFramework\Example.ConsoleApp.NetFramework.csproj", "{15DAA359-C831-4260-9F6F-6255B7A45110}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -54,5 +58,13 @@ Global {42AB2562-8DA6-41E1-ABD5-152DDD622E6D}.Debug|Any CPU.Build.0 = Debug|Any CPU {42AB2562-8DA6-41E1-ABD5-152DDD622E6D}.Release|Any CPU.ActiveCfg = Release|Any CPU {42AB2562-8DA6-41E1-ABD5-152DDD622E6D}.Release|Any CPU.Build.0 = Release|Any CPU + {4F2A9939-3351-465F-9E4C-12616F64A0CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F2A9939-3351-465F-9E4C-12616F64A0CD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F2A9939-3351-465F-9E4C-12616F64A0CD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F2A9939-3351-465F-9E4C-12616F64A0CD}.Release|Any CPU.Build.0 = Release|Any CPU + {15DAA359-C831-4260-9F6F-6255B7A45110}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {15DAA359-C831-4260-9F6F-6255B7A45110}.Debug|Any CPU.Build.0 = Debug|Any CPU + {15DAA359-C831-4260-9F6F-6255B7A45110}.Release|Any CPU.ActiveCfg = Release|Any CPU + {15DAA359-C831-4260-9F6F-6255B7A45110}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/samples/Example.ConsoleApp.NetCore/Example.ConsoleApp.NetCore.csproj b/samples/Example.ConsoleApp.NetCore/Example.ConsoleApp.NetCore.csproj new file mode 100644 index 0000000..18fa616 --- /dev/null +++ b/samples/Example.ConsoleApp.NetCore/Example.ConsoleApp.NetCore.csproj @@ -0,0 +1,17 @@ + + + + Exe + netcoreapp2.1 + + + + + + + + + + + + diff --git a/samples/Example.ConsoleApp.NetCore/Program.cs b/samples/Example.ConsoleApp.NetCore/Program.cs new file mode 100644 index 0000000..6bba5be --- /dev/null +++ b/samples/Example.ConsoleApp.NetCore/Program.cs @@ -0,0 +1,114 @@ +using System; +using I18Next.Net; +using I18Next.Net.Backends; +using I18Next.Net.Extensions; +using I18Next.Net.Plugins; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Localization; +using Console = System.Console; + +namespace Example.ConsoleApp.NetCore +{ + class Program + { + private static ITranslationBackend _backend; + + static void Main(string[] args) + { + SetupBackend(); + + SampleOne(); + + SampleTwo(); + + Console.ReadKey(); + } + + private static void SetupBackend() + { + var backend = new InMemoryBackend(); + + backend.AddTranslation("en", "translation", "exampleKey", "My English text."); + backend.AddTranslation("de", "translation", "exampleKey", "Mein deutscher text."); + + _backend = backend; + } + + private static void SampleOne() + { + Console.WriteLine("Sample one: Without Microsoft.Extensions.DependencyInjection"); + + var translator = new DefaultTranslator(_backend); + + var i18next = new I18NextNet(_backend, translator); + + Console.WriteLine("English translation:"); + i18next.Language = "en"; + Console.WriteLine(i18next.T("exampleKey")); + + Console.WriteLine("German translation:"); + i18next.Language = "de"; + Console.WriteLine(i18next.T("exampleKey")); + + Console.WriteLine(); + } + + private static void SampleTwo() + { + Console.WriteLine("Sample one: Using Microsoft.Extensions.DependencyInjection"); + + var services = new ServiceCollection(); + + // Register I18Next.Net + services.AddI18NextLocalization(builder => builder.AddBackend(_backend)); + + using(var serviceProvider = services.BuildServiceProvider()) + using (var scope = serviceProvider.CreateScope()) + { + var scopeProvider = scope.ServiceProvider; + + Console.WriteLine("The first example uses the II18Next interface for direct access to I18Next"); + + var i18next = scopeProvider.GetService(); + + Console.WriteLine("English translation:"); + i18next.Language = "en"; + Console.WriteLine(i18next.T("exampleKey")); + + Console.WriteLine("German translation:"); + i18next.Language = "de"; + Console.WriteLine(i18next.T("exampleKey")); + + + Console.WriteLine(); + Console.WriteLine("The second example uses Microsofts IStringLocalizer interface for translations."); + + var localizer = scopeProvider.GetService(); + + Console.WriteLine("English translation:"); + i18next.Language = "en"; + Console.WriteLine(localizer["exampleKey"]); + + Console.WriteLine("German translation:"); + i18next.Language = "de"; + Console.WriteLine(localizer["exampleKey"]); + + + Console.WriteLine(); + Console.WriteLine("It is also possible to use Microsofts IStringLocalizer interface for translations."); + + var localizerGeneric = scopeProvider.GetService>(); + + Console.WriteLine("English translation:"); + i18next.Language = "en"; + Console.WriteLine(localizerGeneric["exampleKey"]); + + Console.WriteLine("German translation:"); + i18next.Language = "de"; + Console.WriteLine(localizerGeneric["exampleKey"]); + + Console.WriteLine(); + } + } + } +} diff --git a/samples/Example.ConsoleApp.NetFramework/Example.ConsoleApp.NetFramework.csproj b/samples/Example.ConsoleApp.NetFramework/Example.ConsoleApp.NetFramework.csproj new file mode 100644 index 0000000..388f82e --- /dev/null +++ b/samples/Example.ConsoleApp.NetFramework/Example.ConsoleApp.NetFramework.csproj @@ -0,0 +1,62 @@ + + + + + Debug + AnyCPU + {15DAA359-C831-4260-9F6F-6255B7A45110} + Exe + Properties + Example.ConsoleApp.NetFramework + Example.ConsoleApp.NetFramework + v4.6.1 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + {42ab2562-8da6-41e1-abd5-152ddd622e6d} + I18Next.Net.Abstractions + + + {71f47bec-c9fb-4393-aa78-8d7ad2d51863} + I18Next.Net + + + + + \ No newline at end of file diff --git a/samples/Example.ConsoleApp.NetFramework/Program.cs b/samples/Example.ConsoleApp.NetFramework/Program.cs new file mode 100644 index 0000000..05a0ced --- /dev/null +++ b/samples/Example.ConsoleApp.NetFramework/Program.cs @@ -0,0 +1,41 @@ +using System; +using I18Next.Net; +using I18Next.Net.Backends; +using I18Next.Net.Plugins; + +namespace Example.ConsoleApp.NetFramework +{ + internal class Program + { + private static ITranslationBackend _backend; + + public static void Main(string[] args) + { + SetupBackend(); + + var translator = new DefaultTranslator(_backend); + + var i18next = new I18NextNet(_backend, translator); + + Console.WriteLine("English translation:"); + i18next.Language = "en"; + Console.WriteLine(i18next.T("exampleKey")); + + Console.WriteLine("German translation:"); + i18next.Language = "de"; + Console.WriteLine(i18next.T("exampleKey")); + + Console.ReadKey(); + } + + private static void SetupBackend() + { + var backend = new InMemoryBackend(); + + backend.AddTranslation("en", "translation", "exampleKey", "My English text."); + backend.AddTranslation("de", "translation", "exampleKey", "Mein deutscher text."); + + _backend = backend; + } + } +} diff --git a/samples/Example.ConsoleApp.NetFramework/Properties/AssemblyInfo.cs b/samples/Example.ConsoleApp.NetFramework/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..76352d8 --- /dev/null +++ b/samples/Example.ConsoleApp.NetFramework/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Example.ConsoleApp.NetFramework")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Example.ConsoleApp.NetFramework")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("15DAA359-C831-4260-9F6F-6255B7A45110")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// 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("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/examples/Example.WebApp/Controllers/HomeController.cs b/samples/Example.WebApp/Controllers/HomeController.cs similarity index 100% rename from examples/Example.WebApp/Controllers/HomeController.cs rename to samples/Example.WebApp/Controllers/HomeController.cs diff --git a/examples/Example.WebApp/Example.WebApp.csproj b/samples/Example.WebApp/Example.WebApp.csproj similarity index 100% rename from examples/Example.WebApp/Example.WebApp.csproj rename to samples/Example.WebApp/Example.WebApp.csproj diff --git a/examples/Example.WebApp/Models/ErrorViewModel.cs b/samples/Example.WebApp/Models/ErrorViewModel.cs similarity index 100% rename from examples/Example.WebApp/Models/ErrorViewModel.cs rename to samples/Example.WebApp/Models/ErrorViewModel.cs diff --git a/examples/Example.WebApp/Program.cs b/samples/Example.WebApp/Program.cs similarity index 100% rename from examples/Example.WebApp/Program.cs rename to samples/Example.WebApp/Program.cs diff --git a/examples/Example.WebApp/Startup.cs b/samples/Example.WebApp/Startup.cs similarity index 100% rename from examples/Example.WebApp/Startup.cs rename to samples/Example.WebApp/Startup.cs diff --git a/examples/Example.WebApp/Views/Home/About.cshtml b/samples/Example.WebApp/Views/Home/About.cshtml similarity index 100% rename from examples/Example.WebApp/Views/Home/About.cshtml rename to samples/Example.WebApp/Views/Home/About.cshtml diff --git a/examples/Example.WebApp/Views/Home/Contact.cshtml b/samples/Example.WebApp/Views/Home/Contact.cshtml similarity index 100% rename from examples/Example.WebApp/Views/Home/Contact.cshtml rename to samples/Example.WebApp/Views/Home/Contact.cshtml diff --git a/examples/Example.WebApp/Views/Home/Index.cshtml b/samples/Example.WebApp/Views/Home/Index.cshtml similarity index 100% rename from examples/Example.WebApp/Views/Home/Index.cshtml rename to samples/Example.WebApp/Views/Home/Index.cshtml diff --git a/examples/Example.WebApp/Views/Home/Privacy.cshtml b/samples/Example.WebApp/Views/Home/Privacy.cshtml similarity index 100% rename from examples/Example.WebApp/Views/Home/Privacy.cshtml rename to samples/Example.WebApp/Views/Home/Privacy.cshtml diff --git a/examples/Example.WebApp/Views/Shared/Error.cshtml b/samples/Example.WebApp/Views/Shared/Error.cshtml similarity index 100% rename from examples/Example.WebApp/Views/Shared/Error.cshtml rename to samples/Example.WebApp/Views/Shared/Error.cshtml diff --git a/examples/Example.WebApp/Views/Shared/_CookieConsentPartial.cshtml b/samples/Example.WebApp/Views/Shared/_CookieConsentPartial.cshtml similarity index 100% rename from examples/Example.WebApp/Views/Shared/_CookieConsentPartial.cshtml rename to samples/Example.WebApp/Views/Shared/_CookieConsentPartial.cshtml diff --git a/examples/Example.WebApp/Views/Shared/_Layout.cshtml b/samples/Example.WebApp/Views/Shared/_Layout.cshtml similarity index 100% rename from examples/Example.WebApp/Views/Shared/_Layout.cshtml rename to samples/Example.WebApp/Views/Shared/_Layout.cshtml diff --git a/examples/Example.WebApp/Views/Shared/_ValidationScriptsPartial.cshtml b/samples/Example.WebApp/Views/Shared/_ValidationScriptsPartial.cshtml similarity index 100% rename from examples/Example.WebApp/Views/Shared/_ValidationScriptsPartial.cshtml rename to samples/Example.WebApp/Views/Shared/_ValidationScriptsPartial.cshtml diff --git a/examples/Example.WebApp/Views/_ViewImports.cshtml b/samples/Example.WebApp/Views/_ViewImports.cshtml similarity index 100% rename from examples/Example.WebApp/Views/_ViewImports.cshtml rename to samples/Example.WebApp/Views/_ViewImports.cshtml diff --git a/examples/Example.WebApp/Views/_ViewStart.cshtml b/samples/Example.WebApp/Views/_ViewStart.cshtml similarity index 100% rename from examples/Example.WebApp/Views/_ViewStart.cshtml rename to samples/Example.WebApp/Views/_ViewStart.cshtml diff --git a/examples/Example.WebApp/appsettings.Development.json b/samples/Example.WebApp/appsettings.Development.json similarity index 100% rename from examples/Example.WebApp/appsettings.Development.json rename to samples/Example.WebApp/appsettings.Development.json diff --git a/examples/Example.WebApp/appsettings.json b/samples/Example.WebApp/appsettings.json similarity index 100% rename from examples/Example.WebApp/appsettings.json rename to samples/Example.WebApp/appsettings.json diff --git a/examples/Example.WebApp/locales/de/translation.json b/samples/Example.WebApp/locales/de/translation.json similarity index 100% rename from examples/Example.WebApp/locales/de/translation.json rename to samples/Example.WebApp/locales/de/translation.json diff --git a/examples/Example.WebApp/locales/en/translation.json b/samples/Example.WebApp/locales/en/translation.json similarity index 100% rename from examples/Example.WebApp/locales/en/translation.json rename to samples/Example.WebApp/locales/en/translation.json diff --git a/examples/Example.WebApp/wwwroot/css/site.css b/samples/Example.WebApp/wwwroot/css/site.css similarity index 100% rename from examples/Example.WebApp/wwwroot/css/site.css rename to samples/Example.WebApp/wwwroot/css/site.css diff --git a/examples/Example.WebApp/wwwroot/css/site.min.css b/samples/Example.WebApp/wwwroot/css/site.min.css similarity index 100% rename from examples/Example.WebApp/wwwroot/css/site.min.css rename to samples/Example.WebApp/wwwroot/css/site.min.css diff --git a/examples/Example.WebApp/wwwroot/favicon.ico b/samples/Example.WebApp/wwwroot/favicon.ico similarity index 100% rename from examples/Example.WebApp/wwwroot/favicon.ico rename to samples/Example.WebApp/wwwroot/favicon.ico diff --git a/examples/Example.WebApp/wwwroot/images/banner1.svg b/samples/Example.WebApp/wwwroot/images/banner1.svg similarity index 100% rename from examples/Example.WebApp/wwwroot/images/banner1.svg rename to samples/Example.WebApp/wwwroot/images/banner1.svg diff --git a/examples/Example.WebApp/wwwroot/images/banner2.svg b/samples/Example.WebApp/wwwroot/images/banner2.svg similarity index 100% rename from examples/Example.WebApp/wwwroot/images/banner2.svg rename to samples/Example.WebApp/wwwroot/images/banner2.svg diff --git a/examples/Example.WebApp/wwwroot/images/banner3.svg b/samples/Example.WebApp/wwwroot/images/banner3.svg similarity index 100% rename from examples/Example.WebApp/wwwroot/images/banner3.svg rename to samples/Example.WebApp/wwwroot/images/banner3.svg diff --git a/examples/Example.WebApp/wwwroot/js/site.js b/samples/Example.WebApp/wwwroot/js/site.js similarity index 100% rename from examples/Example.WebApp/wwwroot/js/site.js rename to samples/Example.WebApp/wwwroot/js/site.js diff --git a/examples/Example.WebApp/wwwroot/js/site.min.js b/samples/Example.WebApp/wwwroot/js/site.min.js similarity index 100% rename from examples/Example.WebApp/wwwroot/js/site.min.js rename to samples/Example.WebApp/wwwroot/js/site.min.js diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/.bower.json b/samples/Example.WebApp/wwwroot/lib/bootstrap/.bower.json similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/.bower.json rename to samples/Example.WebApp/wwwroot/lib/bootstrap/.bower.json diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/LICENSE b/samples/Example.WebApp/wwwroot/lib/bootstrap/LICENSE similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/LICENSE rename to samples/Example.WebApp/wwwroot/lib/bootstrap/LICENSE diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.css b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.css similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.css rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.css diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.css.map b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.css.map similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.css.map rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.css.map diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.min.css b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.min.css similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.min.css rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.min.css diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.min.css.map b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.min.css.map similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.min.css.map rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap-theme.min.css.map diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.css b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.css similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.css rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.css diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.css.map b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.css.map similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.css.map rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.css.map diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css.map b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css.map similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css.map rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css.map diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.eot diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.svg b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.svg rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.svg diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/js/bootstrap.js b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/js/bootstrap.js similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/js/bootstrap.js rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/js/bootstrap.js diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js diff --git a/examples/Example.WebApp/wwwroot/lib/bootstrap/dist/js/npm.js b/samples/Example.WebApp/wwwroot/lib/bootstrap/dist/js/npm.js similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/bootstrap/dist/js/npm.js rename to samples/Example.WebApp/wwwroot/lib/bootstrap/dist/js/npm.js diff --git a/examples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/.bower.json b/samples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/.bower.json similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/.bower.json rename to samples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/.bower.json diff --git a/examples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt b/samples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt rename to samples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt diff --git a/examples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js b/samples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js rename to samples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js diff --git a/examples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js b/samples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js rename to samples/Example.WebApp/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js diff --git a/examples/Example.WebApp/wwwroot/lib/jquery-validation/.bower.json b/samples/Example.WebApp/wwwroot/lib/jquery-validation/.bower.json similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery-validation/.bower.json rename to samples/Example.WebApp/wwwroot/lib/jquery-validation/.bower.json diff --git a/examples/Example.WebApp/wwwroot/lib/jquery-validation/LICENSE.md b/samples/Example.WebApp/wwwroot/lib/jquery-validation/LICENSE.md similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery-validation/LICENSE.md rename to samples/Example.WebApp/wwwroot/lib/jquery-validation/LICENSE.md diff --git a/examples/Example.WebApp/wwwroot/lib/jquery-validation/dist/additional-methods.js b/samples/Example.WebApp/wwwroot/lib/jquery-validation/dist/additional-methods.js similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery-validation/dist/additional-methods.js rename to samples/Example.WebApp/wwwroot/lib/jquery-validation/dist/additional-methods.js diff --git a/examples/Example.WebApp/wwwroot/lib/jquery-validation/dist/additional-methods.min.js b/samples/Example.WebApp/wwwroot/lib/jquery-validation/dist/additional-methods.min.js similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery-validation/dist/additional-methods.min.js rename to samples/Example.WebApp/wwwroot/lib/jquery-validation/dist/additional-methods.min.js diff --git a/examples/Example.WebApp/wwwroot/lib/jquery-validation/dist/jquery.validate.js b/samples/Example.WebApp/wwwroot/lib/jquery-validation/dist/jquery.validate.js similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery-validation/dist/jquery.validate.js rename to samples/Example.WebApp/wwwroot/lib/jquery-validation/dist/jquery.validate.js diff --git a/examples/Example.WebApp/wwwroot/lib/jquery-validation/dist/jquery.validate.min.js b/samples/Example.WebApp/wwwroot/lib/jquery-validation/dist/jquery.validate.min.js similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery-validation/dist/jquery.validate.min.js rename to samples/Example.WebApp/wwwroot/lib/jquery-validation/dist/jquery.validate.min.js diff --git a/examples/Example.WebApp/wwwroot/lib/jquery/.bower.json b/samples/Example.WebApp/wwwroot/lib/jquery/.bower.json similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery/.bower.json rename to samples/Example.WebApp/wwwroot/lib/jquery/.bower.json diff --git a/examples/Example.WebApp/wwwroot/lib/jquery/LICENSE.txt b/samples/Example.WebApp/wwwroot/lib/jquery/LICENSE.txt similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery/LICENSE.txt rename to samples/Example.WebApp/wwwroot/lib/jquery/LICENSE.txt diff --git a/examples/Example.WebApp/wwwroot/lib/jquery/dist/jquery.js b/samples/Example.WebApp/wwwroot/lib/jquery/dist/jquery.js similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery/dist/jquery.js rename to samples/Example.WebApp/wwwroot/lib/jquery/dist/jquery.js diff --git a/examples/Example.WebApp/wwwroot/lib/jquery/dist/jquery.min.js b/samples/Example.WebApp/wwwroot/lib/jquery/dist/jquery.min.js similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery/dist/jquery.min.js rename to samples/Example.WebApp/wwwroot/lib/jquery/dist/jquery.min.js diff --git a/examples/Example.WebApp/wwwroot/lib/jquery/dist/jquery.min.map b/samples/Example.WebApp/wwwroot/lib/jquery/dist/jquery.min.map similarity index 100% rename from examples/Example.WebApp/wwwroot/lib/jquery/dist/jquery.min.map rename to samples/Example.WebApp/wwwroot/lib/jquery/dist/jquery.min.map diff --git a/src/I18Next.Net.Extensions/Builder/I18NextBuilder.cs b/src/I18Next.Net.Extensions/Builder/I18NextBuilder.cs index 2b380ae..3ceb857 100644 --- a/src/I18Next.Net.Extensions/Builder/I18NextBuilder.cs +++ b/src/I18Next.Net.Extensions/Builder/I18NextBuilder.cs @@ -4,6 +4,7 @@ using I18Next.Net.Backends; using I18Next.Net.Plugins; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; @@ -205,18 +206,19 @@ public I18NextBuilder AddTranslator(Func factory) public void Build() { - AddSingletonIfNotPresent(); + AddSingletonIfNotPresent(DefaultLoggerFactory); AddSingletonIfNotPresent(); - AddSingletonIfNotPresent(DefaultLanguageDetectorFactory); + AddSingletonIfNotPresent(DefaultLanguageDetectorFactory); AddSingletonIfNotPresent(); - AddSingletonIfNotPresent(DefaultTranslatorFactory); - AddSingletonIfNotPresent(DefaultInterpolatorFactory); + AddSingletonIfNotPresent(DefaultTranslatorFactory); + AddSingletonIfNotPresent(DefaultInterpolatorFactory); Services.AddSingleton(); Services.AddSingleton(c => c.GetRequiredService().CreateInstance()); Services.AddSingleton(); Services.AddTransient(typeof(IStringLocalizer<>), typeof(StringLocalizer<>)); + Services.TryAddTransient(typeof(IStringLocalizer), c => c.GetRequiredService().Create(null)); } public I18NextBuilder Configure(Action configure) @@ -254,12 +256,11 @@ private void AddSingletonIfNotPresent() Services.AddSingleton(); } - private void AddSingletonIfNotPresent(Func factory) - where TImplementation : class, TService + private void AddSingletonIfNotPresent(Func factory) where TService : class { if (Services.All(s => s.ServiceType != typeof(TService))) - Services.AddSingleton(factory); + Services.AddSingleton(factory); } private DefaultInterpolator DefaultInterpolatorFactory(IServiceProvider c) @@ -280,6 +281,16 @@ private DefaultLanguageDetector DefaultLanguageDetectorFactory(IServiceProvider return new DefaultLanguageDetector(options.Value.DefaultLanguage); } + private ILogger DefaultLoggerFactory(IServiceProvider c) + { + var msLogger = c.GetService(); + + if (msLogger != null) + return new DefaultExtensionsLogger(msLogger); + + return new TraceLogger(); + } + private DefaultTranslator DefaultTranslatorFactory(IServiceProvider c) { var backend = c.GetRequiredService(); diff --git a/src/I18Next.Net/Backends/InMemoryBackend.cs b/src/I18Next.Net/Backends/InMemoryBackend.cs index 7ccba32..273b851 100644 --- a/src/I18Next.Net/Backends/InMemoryBackend.cs +++ b/src/I18Next.Net/Backends/InMemoryBackend.cs @@ -19,7 +19,7 @@ public Task LoadNamespaceAsync(string language, string @namesp treeKey = BackendUtilities.GetLanguagePart(language) + "_" + @namespace; if (!_namespaces.TryGetValue(treeKey, out tree)) - return null; + return Task.FromResult(default(ITranslationTree)); return Task.FromResult(tree as ITranslationTree); } diff --git a/src/I18Next.Net/Plugins/DefaultTranslator.cs b/src/I18Next.Net/Plugins/DefaultTranslator.cs index 8944974..f4cbcac 100644 --- a/src/I18Next.Net/Plugins/DefaultTranslator.cs +++ b/src/I18Next.Net/Plugins/DefaultTranslator.cs @@ -26,6 +26,22 @@ public DefaultTranslator(ITranslationBackend backend, ILogger logger, IPluralRes _interpolator = interpolator; } + public DefaultTranslator(ITranslationBackend backend) + { + _backend = backend; + _logger = new TraceLogger(); + _pluralResolver = new DefaultPluralResolver(); + _interpolator = new DefaultInterpolator(); + } + + public DefaultTranslator(ITranslationBackend backend, IInterpolator interpolator) + { + _backend = backend; + _logger = new TraceLogger(); + _pluralResolver = new DefaultPluralResolver(); + _interpolator = interpolator; + } + public bool AllowInterpolation { get; set; } = true; public bool AllowNesting { get; set; } = true;