-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added examples for console applications; Minor bugfix
- Loading branch information
1 parent
77f0001
commit e4a1324
Showing
69 changed files
with
317 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
samples/Example.ConsoleApp.NetCore/Example.ConsoleApp.NetCore.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\I18Next.Net.Extensions\I18Next.Net.Extensions.csproj" /> | ||
<ProjectReference Include="..\..\src\I18Next.Net\I18Next.Net.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<II18Next>(); | ||
|
||
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<IStringLocalizer>(); | ||
|
||
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<T> interface for translations."); | ||
|
||
var localizerGeneric = scopeProvider.GetService<IStringLocalizer<Program>>(); | ||
|
||
Console.WriteLine("English translation:"); | ||
i18next.Language = "en"; | ||
Console.WriteLine(localizerGeneric["exampleKey"]); | ||
|
||
Console.WriteLine("German translation:"); | ||
i18next.Language = "de"; | ||
Console.WriteLine(localizerGeneric["exampleKey"]); | ||
|
||
Console.WriteLine(); | ||
} | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
samples/Example.ConsoleApp.NetFramework/Example.ConsoleApp.NetFramework.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{15DAA359-C831-4260-9F6F-6255B7A45110}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Example.ConsoleApp.NetFramework</RootNamespace> | ||
<AssemblyName>Example.ConsoleApp.NetFramework</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\I18Next.Net.Abstractions\I18Next.Net.Abstractions.csproj"> | ||
<Project>{42ab2562-8da6-41e1-abd5-152ddd622e6d}</Project> | ||
<Name>I18Next.Net.Abstractions</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\..\src\I18Next.Net\I18Next.Net.csproj"> | ||
<Project>{71f47bec-c9fb-4393-aa78-8d7ad2d51863}</Project> | ||
<Name>I18Next.Net</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
samples/Example.ConsoleApp.NetFramework/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.