OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.35k stars 2.37k forks source link

Orchardcore can work well in my local windows , but doesn't work in remote Linux docker,what's the problem ? i mean the app runs well, only localization doesn't work well. #16497

Open freepay2020 opened 1 month ago

freepay2020 commented 1 month ago

Orchardcore can work well in my local windows , but doesn't work in remote Linux docker,what's the problem ? i mean the app runs well, only localization doesn't work well.

Orchard Core version 1.6 for .net core 6

using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc.Razor;
using System.Globalization;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddPortableObjectLocalization(options => options.ResourcesPath = "Resources");
builder.Services.AddPortableObjectLocalization();
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
    var supportedCultures = new List<CultureInfo>
            {
                new CultureInfo("en-US"),
                new CultureInfo("en"),
                new CultureInfo("fr-FR"),
                new CultureInfo("fr"),
                new CultureInfo("zh")
            };

    options.DefaultRequestCulture = new RequestCulture("zh");
    options.SupportedCultures = supportedCultures;
    options.SupportedUICultures = supportedCultures;
});
builder.Services.AddMvc()
        .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);

// Add services to the container.
builder.Services.AddRazorPages();

var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
var supportedCultures = new string[] { "en-US", "fr-FR", "en", "zh", "fr" };
app.UseRequestLocalization(options =>
    options
        .AddSupportedCultures(supportedCultures)
        .AddSupportedUICultures(supportedCultures)
        .SetDefaultCulture("zh")
);

//where you are
app.UseRouting();
//who you are
app.UseAuthentication();
//what you can do
app.UseAuthorization();

app.MapControllers();
app.MapRazorPages();
await app.RunAsync();

To Reproduce

Steps to reproduce the behavior:

  1. i set up all well and it runs well in my local windows linux docker correctly, but when i upload into remote server linux,run in docker,it doesn't work, the app runs well, only localization doesn't work well
  2. the app runs without any errors, only cannot get localization expected.

Expected behavior

  1. i set up all well and it runs well in my local windows linux docker correctly, but when i upload into remote server linux,run in docker,it doesn't work, the app runs well, only localization doesn't work well
  2. the app runs without any errors, only cannot get localization expected.

Logs and screenshots

If applicable, add log files, browser console logs, and screenshots (or screen recording videos) to help explain your problem.

github-actions[bot] commented 1 month ago

Thank you for submitting your first issue, awesome! 🚀 We're thrilled to receive your input. If you haven't completed the template yet, please take a moment to do so. This ensures that we fully understand your feature request or bug report. On what happens next, see the docs.

If you like Orchard Core, please star our repo and join our community channels.

MikeAlhayek commented 1 month ago

Most of the code you posted is not need and should be removed. Follow the setup described here https://docs.orchardcore.net/en/latest/getting-started/

Enable the Localization feature for the tenant and you should be able to see the site in other languages. @hishamco is more familiar with localization, he may be add more info.

sebastienros commented 1 month ago

Actually I think the issue is about the localization package we ship (po files + pluralization support) and not the CMS part (or modularity/tenants).

For reference, the documentation on how to use this package https://learn.microsoft.com/en-us/aspnet/core/fundamentals/portable-object-localization?view=aspnetcore-8.0

github-actions[bot] commented 1 month ago

We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).

This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.

hishamco commented 1 month ago

@freepay2020 why did you configure RequestLocalizationOptions again? it should be done in OC by default. Please share a repo to reproduce the issue

Actually I think the issue is about the localization package we ship (po files + pluralization support) and not the CMS part (or modularity/tenants).

I don't think there's an issue, I'm updating the localization sample in AspNet Docs frequently, let me do it for the last version then confirm

tangxiaoyu commented 5 days ago

Re-add and set up localization in the background.

sebastienros commented 2 days ago

I can find of two reasons this would fail:

  1. zh might not be a known culture on Linux in .NET (but this should be a good fallback value for zh-CN and zh-TW)
  2. The paths are case sensitive and the folders you created don't match what Orchard is expecting

Can you check both?