Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

How to use localization in Razor Class Library #2404

Closed
Jenan opened this issue Jun 14, 2018 · 4 comments
Closed

How to use localization in Razor Class Library #2404

Jenan opened this issue Jun 14, 2018 · 4 comments
Assignees
Labels

Comments

@Jenan
Copy link

Jenan commented Jun 14, 2018

I have tried to create the Razor Class Library with Asp.Net Core in following project structure:

alt text

I have used in my web application these settings for localization in Startup class:

    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
                    .AddViewLocalization(
                        LanguageViewLocationExpanderFormat.Suffix,
                        opts => { opts.ResourcesPath = "Resources"; })
                    .AddDataAnnotationsLocalization();

                services.Configure<RequestLocalizationOptions>(
                    opts =>
                    {
                        var supportedCultures = new[]
                        {
                            new CultureInfo("en-US"),
                            new CultureInfo("en")
                        };

                        opts.DefaultRequestCulture = new RequestCulture("en");
                        opts.SupportedCultures = supportedCultures;
                        opts.SupportedUICultures = supportedCultures;
                    });

....

var options = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
            app.UseRequestLocalization(options.Value);

In Index.cshtml:

@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer


<h1>@Localizer["Title"]</h1>

Unfortunately, the result is only string "Title". I can't load these resx files from Razor Class Library.

How can I use the localization in Razor Class Library like above?

@Jenan Jenan changed the title How to use localization in Razor Class Library in Asp.Net Core How to use localization in Razor Class Library Jun 14, 2018
@mkArtakMSFT
Copy link
Member

mkArtakMSFT commented Jun 14, 2018

Hi. It looks like this is a question about how to use ASP.NET Core. While we do our best to look through all the issues filed here, to get a faster response we suggest posting your questions to StackOverflow using the asp.net-core-mvc tag.

@mkArtakMSFT
Copy link
Member

@ryanbrandenburg, @pranavkm any suggestions?

@Jenan
Copy link
Author

Jenan commented Jun 15, 2018

I asked same question on StackOverflow - here but without any suggestions. I will be very happy for any recommendation here :)

@ryanbrandenburg
Copy link
Contributor

@Jenan I believe this is essentially a copy of aspnet/Localization#328, which as far as I know still stands. Basically it boils down to not being able to make guarantees about packages/projects that we import using the same systems and conventions that your main app does. There are some suggestions on that bug about what to do in this situation, so please check them out.

I'm closing this out. If you believe that the above issue does not cover your situation please re-open with a description of the differences and a reproduction app so we have a better idea of exactly what you're running into.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants