I18Next.Net icon indicating copy to clipboard operation
I18Next.Net copied to clipboard

Problem with JsonFileBackend usage: Unable to retrieve translated values

Open kvu-k opened this issue 1 year ago • 0 comments

Issue Description:

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.

Steps to Reproduce:

  1. Use the following code snippet:
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)
    {
    }
}
  1. Ensure that the JSON file exists at the specified path (en.json).
  2. Confirm that the JSON file contains the correct structure and the translation key-value pair.
  3. Execute the code and observe the returned translation.

Expected Behavior:

The translation should return the value associated with the specified key from the JSON file.

Actual Behavior:

The translation returns the key itself instead of the associated value. (key1)

Additional Information:

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.

Environment:

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.

kvu-k avatar Mar 13 '24 10:03 kvu-k