jsakamoto / Toolbelt.Blazor.I18nText

The class library that provides the ability to localize texts on your Blazor app!
Mozilla Public License 2.0
246 stars 23 forks source link

Use I18nText from ClassLib #53

Open MichaelHochriegl opened 2 years ago

MichaelHochriegl commented 2 years ago

Greetings,

I try to use this package in the following setup:

Localization Class Library: In this class lib the nuget package is installed, this also has the i18ntext folder with the json-files in it. Appart from that it has a class LocalizationBase that looks like this:

public class LocalizationBase : ComponentBase
{
    [Inject] public Toolbelt.Blazor.I18nText.I18nText I18NText { get; set; } = default!;

    public I18nText.MediaButler Translator { get; set; } = new();

    protected override async Task OnInitializedAsync()
    {
        Translator = await I18NText.GetTextTableAsync<I18nText.MediaButler>(this);
    }
}

BlazorWasm: In this Blazor Wasm project I have a reference to the Localization class lib. My component inherits the LocalizationBase but when I try to translate UI elements with Translator.xxx I get the default text and in the browser dev console a 404 related to I18nText.

XHRGEThttps://localhost:5501/_content/i18ntext/Localization.I18nText.MediaButler.en-US.json?hash=b8n6o49rke
[HTTP/2 404 Not Found 0ms]

GET
    https://localhost:5501/_content/i18ntext/Localization.I18nText.MediaButler.en-US.json?hash=b8n6o49rke
Status
404
Not Found
VersionHTTP/2

The Localization.I18nText.MediaButler.en-US.json is present in the _content/i18ntext folder in the build output. The hash is the same as the one in the auto-generated Localization.I18nText.MediaButler.cs.

jsakamoto commented 2 years ago

@MichaelHochriegl Thank you for letting me know!

I'll investigate this problem. However, I'm currently busy with other projects, so investigating and resolving this issue may take much longer than your expectation. I appreciate it if you are patient.

MichaelHochriegl commented 2 years ago

No worries and thanks for looking into it. If there is anything that I can do to help analyze the problem I 'm more than happy to help you.

jsakamoto commented 2 years ago

@MichaelHochriegl Unfortunately, I could not reproduce your reported problem in my environment. I embedded my project file as a zip file on this post.

📦Issue53App-net6.0-i18n.v11.1.4.zip

Could you disclose your project that can reproduce your problem?

davidlin1568 commented 1 year ago

Did you try to modify file names? eg., Localization.I18nText.MediaButler.en-US.json -> Localization.I18nText.MediaButler.en.json