darklikally / i18next.net Goto Github PK
View Code? Open in Web Editor NEWA port of the i18next javascript library for .Net platforms based on .Net Standard 2.0
License: Apache License 2.0
A port of the i18next javascript library for .Net platforms based on .Net Standard 2.0
License: Apache License 2.0
Any sample on how to lazy load using API?
The same feature for react here:
https://linguinecode.com/post/lazy-loading-react-i18next-translations
And also, does this support .NET 4.5?
Hi, sorry for the weird issue. I am trying to decide on i18n solution for a rather big project we're working on. We are already using i18next on the frontend which would make this perfect in terms of compatibility of tools and the build process.
I, however, see that this lib is not widely adopted, and in order to save precious time, I was curious if you could help me understand the state of its development. Is this actively developed/maintained? Are there any issues that you currently are aware of that need fixing and/or is it ready for production? Did you do any performance testing comparing it to the more traditional dot net i18n frameworks?
Thank you very much for any kind of feedback you could provide here.
The project includes several logging implmentations. However, neither the default translator and none of the implemented backends ever log any diagnostics.
Hello i've tryed to look at the code and search for docs but it doesn't seems to me that this library already supports the i18next saveMissing, and updateMissing, backend configurrations, which allows the browser to signal missing keys (and the server should create them in the json file so they will be ready to be translated.
I'm i missing something? if the feature is missing i can probably contribute to the project implementing it. just let me know if i've missed it or there is at least something already implemented so i can pick up from there.
Thanks.
When using the provided code snippet with the JsonFileBackend
method in I18NextNet, I'm encountering an issue where the translation returns the key instead of the value from the JSON file.
private async Task Translate()
{
try
{
var backend = new JsonFileBackend();
await SetupJsonBackend(backend);
var translator = new DefaultTranslator(backend);
var i18Next = new I18NextNet(backend, translator);
//set language to english
i18Next.Language = "en";
var enText = i18Next.T("key1");
}
catch (Exception ex)
{
}
}
private async Task SetupJsonBackend(JsonFileBackend backend)
{
try
{
await backend.LoadNamespaceAsync("en", "en.json");
}
catch (Exception ex)
{
}
}
The translation should return the value associated with the specified key from the JSON file.
The translation returns the key itself instead of the associated value. (key1)
I have verified the correctness of the JSON file and ensured that it contains the expected key-value pair.
There are no exceptions thrown during the loading of the JSON file or the translation process.
I have debugged the code and confirmed that the language is correctly set to "en" before retrieving the translation.
Operating System: Windows 10 Pro 22H2 19045.4046
.NET Framework Version: 4.6.1
I18NextNet Version: 1.0.0
Note:
I also wanted to confirm whether the provided JSON file is grammatically correct. It contains the following key-value pair:
{
"key1": "Good morning"
}
Thank you for your assistance in resolving this issue.
Hello, I think i've found a bug or an oversight but i'm not sure.
Given this JSON translation file...
{
"key": "value of key",
"look": {
"deep": "value of look deep"
}
}
TranslationTree.GetAllValues() will return...
{
"key": "value of key",
"deep": "value of look deep"
}
I think the mistake is here: https://github.dev/DarkLiKally/I18Next.Net/blob/6dbd30f23a8655134dc7d2041fe803240584a3ad/src/I18Next.Net/TranslationTrees/TranslationTree.cs#L69-L70
The parent translation name (key path) isn't propagated through the recursion for use in the dictionary.
I think it's supposed to result in this dictionary instead
{
"key": "value of key",
"look.deep": "value of look deep"
}
We receive the following exception:
System.ArgumentNullException: Value cannot be null.
at I18Next.Net.I18NextNet.set_Language(String value)
at I18Next.Net.Extensions.I18NextStringLocalizer.Translate(String name, Object[] arguments)
when Accept-Language header is not present in http request (e.g. from Mobile app, not web-browser).
Set up is:
services.AddI18NextLocalization(
i18N => i18N
.AddLanguageDetector<ThreadLanguageDetector>()
);
I was wondering how and if i can split up language files. For an example i would like to have the following folder structure:
locales/Controllers/Home/en.json
locales/Models/Home/en.json
locales/Services/Home/en.json
Is that possible? The default localisation .net Core offers, tries to guess where the localisations files are based on the path of the actual cs file. Unfortunately i am unable to figure out how it works with this library.
According to the documentation of CurrentCulture & CurrentUICulture
https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.currentculture?view=net-5.0
https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.currentuiculture?view=net-5.0
the first one (CurrentCulture) defines the format of numbers and dates.
The second one (CurrentUICulture) defines which resource to load (which translation to apply).
I wonder if it's a bug that this library uses CurrentCulture to determine which JSON files to load. Logically it has to use CurrentUICulture.
This is the code I'm talking about:
In the new version of i18next the JSON format for pluralization has changed. See https://www.i18next.com/misc/json-format
Specifically the suffixes have changed structure.
Are there any plans to support this update?
Hi,
I would like to have my localization files structured like this:
The default JsonFileBackend has a method FindFile which is private. If this method (or even other methods) are defined protected virtual then the only effort is to implement the methods that are necessary. And re-use the code from the JsonFileBackend. One more additional benefit is that if you make changes to this class in future release, my custom class will inherit these changes automatically when I upgrade the I18Next NuGet package.
Please let me know what you think. Thank you
Is it possible to use I18Next.Net in a desktop C# application? An example of how to setup a basic C# command line app would be nice.
For example when given:
translation.json
{ "test": "Test Entry" }
more.json
{ "other": "Other Entry" }
The use of Localize["more:test"]
should fall back to the value of "Test Entry"
instead of "test"
. As described in the i18next docs.
Could you please add consistently ConfigureAwait(false) to the awaited async calls for using this awesome i18next library in Blazor projects?
To provide parity with the Javascript implementation, this library should implement Namespace fallback.
https://www.i18next.com/principles/fallback#namespace-fallback
When DetectLanguageOnEachTranslation
is set to true, the detected language parameter is loaded to the class, but it is never updated to be used, meaning that the detected language from the LanguageDetector is never used.
Pluralization currently seems broken when used in combination with fallback languages. Different languages have different pluralization suffixes but DefaultTranslator.ResolveTranslationAsync right now only calls IPluralResolver for the main language and then reuses the possibleKeys for fallback languages.
Here's a failing test that can be added to I18NextFixture as an example.
`
// Add this line to SetupBackend()
backend.AddTranslation("en", "translation", "exampleKey2_plural", "My English plural fallback {{count}}.");
[Test]
public void Pluralization_MissingLanguage_ReturnsFallback()
{
_i18Next.Language = "ja";
_i18Next.SetFallbackLanguages("en");
Assert.AreEqual("My English plural fallback 2.", _i18Next.T("exampleKey2", new { count = 2 }));
}
`
The original fallback language support PR #6 had this right but later refactoring broke it.
I'll submit a new PR that I believe fixes the problem.
In the ObjectToDictionary(object value) extension method , check whether the value is already an IDictionary<string, object>
@DarkLiKally Do you have any news on the planned update and new version for resolving this PR?
Originally posted by @csmith1983 in #13 (comment)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.