Skip to content

Commit

Permalink
Refactored some functionality; Added MissingKey event; Cleanup; Bumpe…
Browse files Browse the repository at this point in the history
…d version
  • Loading branch information
DarkLiKally committed Jul 25, 2019
1 parent bfec2f6 commit e6e2095
Show file tree
Hide file tree
Showing 28 changed files with 299 additions and 165 deletions.
1 change: 1 addition & 0 deletions I18Next.Net.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
</ItemGroup>

</Project>
31 changes: 15 additions & 16 deletions samples/Example.ConsoleApp.NetCore/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using I18Next.Net;
using I18Next.Net;
using I18Next.Net.Backends;
using I18Next.Net.Extensions;
using I18Next.Net.Plugins;
Expand Down Expand Up @@ -41,15 +40,15 @@ private static void SampleOne()

var translator = new DefaultTranslator(_backend);

var i18next = new I18NextNet(_backend, translator);
var i18Next = new I18NextNet(_backend, translator);

Console.WriteLine("English translation:");
i18next.Language = "en";
Console.WriteLine(i18next.T("exampleKey"));
i18Next.Language = "en";
Console.WriteLine(i18Next.T("exampleKey"));

Console.WriteLine("German translation:");
i18next.Language = "de";
Console.WriteLine(i18next.T("exampleKey"));
i18Next.Language = "de";
Console.WriteLine(i18Next.T("exampleKey"));

Console.WriteLine();
}
Expand All @@ -70,15 +69,15 @@ private static void SampleTwo()

Console.WriteLine("The first example uses the II18Next interface for direct access to I18Next");

var i18next = scopeProvider.GetService<II18Next>();
var i18Next = scopeProvider.GetService<II18Next>();

Console.WriteLine("English translation:");
i18next.Language = "en";
Console.WriteLine(i18next.T("exampleKey"));
i18Next.Language = "en";
Console.WriteLine(i18Next.T("exampleKey"));

Console.WriteLine("German translation:");
i18next.Language = "de";
Console.WriteLine(i18next.T("exampleKey"));
i18Next.Language = "de";
Console.WriteLine(i18Next.T("exampleKey"));


Console.WriteLine();
Expand All @@ -87,11 +86,11 @@ private static void SampleTwo()
var localizer = scopeProvider.GetService<IStringLocalizer>();

Console.WriteLine("English translation:");
i18next.Language = "en";
i18Next.Language = "en";
Console.WriteLine(localizer["exampleKey"]);

Console.WriteLine("German translation:");
i18next.Language = "de";
i18Next.Language = "de";
Console.WriteLine(localizer["exampleKey"]);


Expand All @@ -101,11 +100,11 @@ private static void SampleTwo()
var localizerGeneric = scopeProvider.GetService<IStringLocalizer<Program>>();

Console.WriteLine("English translation:");
i18next.Language = "en";
i18Next.Language = "en";
Console.WriteLine(localizerGeneric["exampleKey"]);

Console.WriteLine("German translation:");
i18next.Language = "de";
i18Next.Language = "de";
Console.WriteLine(localizerGeneric["exampleKey"]);
Console.WriteLine(localizerGeneric["exampleKey2"]);

Expand Down
14 changes: 7 additions & 7 deletions samples/Example.ConsoleApp.NetFramework/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ public static void Main(string[] args)

var translator = new DefaultTranslator(_backend);

var i18next = new I18NextNet(_backend, translator);
var i18Next = new I18NextNet(_backend, translator);

Console.WriteLine("English translation:");
i18next.Language = "en";
Console.WriteLine(i18next.T("exampleKey"));
i18Next.Language = "en";
Console.WriteLine(i18Next.T("exampleKey"));

Console.WriteLine("German translation:");
i18next.Language = "de";
Console.WriteLine(i18next.T("exampleKey"));
i18Next.Language = "de";
Console.WriteLine(i18Next.T("exampleKey"));

i18next.SetFallbackLanguage("en");
Console.WriteLine(i18next.T("exampleKey2")); // should output "My English text." because of fallback language
i18Next.SetFallbackLanguages("en");
Console.WriteLine(i18Next.T("exampleKey2")); // should output "My English text." because of fallback language

Console.ReadKey();
}
Expand Down
3 changes: 0 additions & 3 deletions samples/Example.WebApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Example.WebApp.Models;
using Microsoft.Extensions.Localization;
Expand Down
4 changes: 2 additions & 2 deletions samples/Example.WebApp/Example.WebApp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions samples/Example.WebApp/Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace Example.WebApp.Models
{
public class ErrorViewModel
Expand Down
9 changes: 1 addition & 8 deletions samples/Example.WebApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace Example.WebApp
{
Expand Down
3 changes: 1 addition & 2 deletions samples/Example.WebApp/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using I18Next.Net.AspNetCore;
using I18Next.Net.Backends;
using I18Next.Net.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand Down Expand Up @@ -42,7 +41,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void ConfigureServices(IServiceCollection services)
{
// Option 1: Simple setup for AspNetCore using the default configuration
services.AddI18NextLocalization(i18n => i18n.IntegrateToAspNetCore());
services.AddI18NextLocalization(i18N => i18N.IntegrateToAspNetCore());

// Option 2: Customize the locales location in order to use the same json files on the client side.
// services.AddI18NextLocalization(i18n =>
Expand Down
4 changes: 2 additions & 2 deletions src/I18Next.Net.Abstractions/I18Next.Net.Abstractions.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Product>I18Next.Net</Product>
<Authors>DarkLiKally</Authors>
<Company>DarkLiKally</Company>
<Version>0.6.1</Version>
<Version>0.7.0</Version>
<RepositoryUrl>https://github.com/DarkLiKally/I18Next.Net</RepositoryUrl>
<PackageProjectUrl>https://github.com/DarkLiKally/I18Next.Net</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
Expand Down
3 changes: 3 additions & 0 deletions src/I18Next.Net.Abstractions/II18Next.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System;
using System.Threading.Tasks;
using I18Next.Net.Backends;
using I18Next.Net.Plugins;

namespace I18Next.Net
{
public interface II18Next
{
ITranslationBackend Backend { get; }

ITranslator Translator { get; }

string DefaultNamespace { get; set; }

Expand Down
23 changes: 23 additions & 0 deletions src/I18Next.Net.Abstractions/MissingKeyEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace I18Next.Net
{
public class MissingKeyEventArgs : EventArgs
{
public MissingKeyEventArgs(string language, string ns, string key, string[] possibleKeys)
{
Language = language;
Namespace = ns;
Key = key;
PossibleKeys = possibleKeys;
}

public string Language { get; }

public string Namespace { get; }

public string Key { get; }

public string[] PossibleKeys { get; }
}
}
7 changes: 5 additions & 2 deletions src/I18Next.Net.Abstractions/Plugins/ITranslator.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace I18Next.Net.Plugins
{
public interface ITranslator
{
event EventHandler<MissingKeyEventArgs> MissingKey;

List<IPostProcessor> PostProcessors { get; }

Task<string> TranslateAsync(string language, string defaultNamespace, string key, IDictionary<string, object> args, IList<string> fallbackLanguages);
Task<string> TranslateAsync(string language, string key, IDictionary<string, object> args, TranslationOptions options);
}
}
23 changes: 23 additions & 0 deletions src/I18Next.Net.Abstractions/TranslationOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace I18Next.Net
{
public class TranslationOptions
{
private string _defaultNamespace;

public string[] FallbackLanguages { get; set; }

public string DefaultNamespace
{
get => _defaultNamespace;
set
{
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentException(nameof(value));

_defaultNamespace = value;
}
}
}
}
6 changes: 3 additions & 3 deletions src/I18Next.Net.AspNetCore/I18Next.Net.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/DarkLiKally/I18Next.Net</RepositoryUrl>
<PackageProjectUrl>https://github.com/DarkLiKally/I18Next.Net</PackageProjectUrl>
<Version>0.6.1</Version>
<Version>0.7.0</Version>
<Authors>DarkLiKally</Authors>
<RepositoryType>git</RepositoryType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Localization" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Localization" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions src/I18Next.Net.Extensions/I18Next.Net.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
<Product>I18Next.Net</Product>
<Authors>DarkLiKally</Authors>
<Company>DarkLiKally</Company>
<Version>0.6.1</Version>
<Version>0.7.0</Version>
<RepositoryUrl>https://github.com/DarkLiKally/I18Next.Net</RepositoryUrl>
<PackageProjectUrl>https://github.com/DarkLiKally/I18Next.Net</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\I18Next.Net\I18Next.Net.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion src/I18Next.Net.Extensions/I18NextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public II18Next CreateInstance()
Logger = _logger,
DetectLanguageOnEachTranslation = _options.Value.DetectLanguageOnEachTranslation,
};
instance.SetFallbackLanguage(_options.Value.FallbackLanguages.ToArray());
instance.SetFallbackLanguages(_options.Value.FallbackLanguages.ToArray());

return instance;
}
Expand Down
2 changes: 1 addition & 1 deletion src/I18Next.Net.ICU/I18Next.Net.ICU.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RepositoryUrl>https://github.com/DarkLiKally/I18Next.Net</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Product>I18Next.Net</Product>
<Version>0.6.1</Version>
<Version>0.7.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MessageFormat" Version="3.0.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/I18Next.Net.PolyglotJs/I18Next.Net.PolyglotJs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageProjectUrl>https://github.com/DarkLiKally/I18Next.Net</PackageProjectUrl>
<RepositoryUrl>https://github.com/DarkLiKally/I18Next.Net</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>0.6.1</Version>
<Version>0.7.0</Version>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\I18Next.Net\I18Next.Net.csproj" />
Expand Down
4 changes: 3 additions & 1 deletion src/I18Next.Net/Formatters/DefaultFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public string Format(object value, string format, string language)

var cultureInfo = CultureInfo.GetCultureInfo(language);

return string.Format(cultureInfo, "{0:" + format + "}", value);
var formatString = $"{{0:{format}}}";

return string.Format(cultureInfo, formatString, value);
}
}
}
4 changes: 2 additions & 2 deletions src/I18Next.Net/I18Next.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/DarkLiKally/I18Next.Net</RepositoryUrl>
<PackageProjectUrl>https://github.com/DarkLiKally/I18Next.Net</PackageProjectUrl>
<Version>0.6.1</Version>
<Version>0.7.0</Version>
<Authors>DarkLiKally</Authors>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\I18Next.Net.Abstractions\I18Next.Net.Abstractions.csproj" />
Expand Down
Loading

0 comments on commit e6e2095

Please sign in to comment.