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.36k stars 2.37k forks source link

BUG: 'zh' localization directory not exist #11672

Closed IsQiao closed 1 year ago

IsQiao commented 2 years ago

Describe the bug

To Reproduce

Steps to reproduce the behavior:

  1. when my chrome broswer language is '中文(简体)', the CurrentUICulture field value is zh,
  2. then ModularPoFileLocationProvider() can't find the zh localization dir. because it is not existed.
  3. so the website always display en-US culture.

Expected behavior

show Chinese properly

Screenshots

image image image image image

Skrypt commented 2 years ago

There are discrepancies between different OS with these culture codes. You simply need to rename the folder/file of your choice to the appropriate culture code for this to work.

IsQiao commented 2 years ago

rename the directory can resolve it, but There are same problems in macos and windows 10. so i suguest to add zh dir to OrchardCore.Translations repo, or add some codes to enhance it. (^_^)

Skrypt commented 2 years ago

@agriffard Does Crowdin supports adding the "zh" culture or do we keep only specific culture/regions culture codes?

hyzx86 commented 1 year ago

It looks like it's just a display problem here, because it works fine on setup page, but once you switch to English, you can't change it back to Chinese

The option zh-CN is not listed here

But I remember that there was no problem with some previous versions, I wonder why zh-CN was deleted

@agriffard

hishamco commented 1 year ago

FYI Crowdin nowdays have both zh-CN and zh-TW, so when you choose zh can't find the root culture, so you can choose one of the supported cultures or rename the culture folder as workaround

hyzx86 commented 1 year ago

@hishamco No, that is not a right way. As a Web application, we should follow the browser Settings, not let the user choose

image

hishamco commented 1 year ago

FYI localization APIs already have 3/4 RequestCultureProviders, then it uses a fallback mechanism to the parent culture in case the current cultures is not present

hyzx86 commented 1 year ago

Yes, I remember of a problem, language choice, on the Setup page is good, there use IOptions<RequestLocalizationOptions> LocOptions

let me have a try..

hyzx86 commented 1 year ago

faild 🤣 image

model.Cultures = _locOptions.Value.SupportedCultures 
                        .Select(cultureInfo =>
                        {
                            return new CultureEntry
                            {
                                Supported = settings.SupportedCultures.Contains(cultureInfo.Name, StringComparer.OrdinalIgnoreCase),
                                CultureInfo = cultureInfo,
                                IsDefault = String.Equals(settings.DefaultCulture, cultureInfo.Name, StringComparison.OrdinalIgnoreCase)
                            };
                        }).ToArray();
hishamco commented 1 year ago

Just let me know what will happen if you set your culture to zh-CN in the admin?

hyzx86 commented 1 year ago

FYI localization APIs already have 3/4 RequestCultureProviders, then it uses a fallback mechanism to the parent culture in case the current cultures is not present

Yes, my layer tried to get all cultures first using CultureInfo.GetCultures(CultureTypes.AllCultures) and then all subcultures through SelectMany(x=>x.getAllChildxxx), but I couldn't find the right way .

hyzx86 commented 1 year ago

Just let me know what will happen if you set your culture to zh-CN in the admin?

https://user-images.githubusercontent.com/15613121/210253277-a335ff13-e180-4b76-8c5f-9e6d3dd86e61.mp4

But, there is no place for switching languages in the OC admin theme.

hyzx86 commented 1 year ago

chrome_jWII5d0t2D

hishamco commented 1 year ago

Try to set zh-CN as default culture and have a try

hishamco commented 1 year ago

BTW I think you did the following fallback

https://github.com/OrchardCMS/OrchardCore/blob/083d5d7f9885b6ba034f642259cb94326af9e551/src/OrchardCore/OrchardCore.Localization.Core/DefaultPluralRuleProvider.cs#L66-L78

Right?

hyzx86 commented 1 year ago

BTW I think you did the following fallback

https://github.com/OrchardCMS/OrchardCore/blob/083d5d7f9885b6ba034f642259cb94326af9e551/src/OrchardCore/OrchardCore.Localization.Core/DefaultPluralRuleProvider.cs#L66-L78

Right?

Yes, we can only get parents from children, but not vice versa. I haven't found a way

hishamco commented 1 year ago

Of course you can't ;)

hyzx86 commented 1 year ago

Try to set zh-CN as default culture and have a try

I don't need to set zh-CN as Default, because the program recognizes that the browser's default language is zh-CN, so when I add zh-CN, OC will automatically apply it

hishamco commented 1 year ago

To make it clear, what's your browser default language? your OC default language?

I don't need to set zh-CN as Default,

Why? so, what's you preferred language?

hyzx86 commented 1 year ago

image

in my submission.. All the billions of browsers in China should be zh-CN 🤣

hishamco commented 1 year ago

So, what's the problem then? Just set your default culture in OC to zh-CN then it should work

hyzx86 commented 1 year ago

problem is .. image

hyzx86 commented 1 year ago

image

hyzx86 commented 1 year ago

As I did in PR, zh CN can only be obtained in this way

image

hishamco commented 1 year ago

leave the code for now , the cultures might differ from OS to another, just let me know if you set zh-CN as default culture in OC what happen? is it displayed correctly or not?

hyzx86 commented 1 year ago

in .net 5.0 image

hyzx86 commented 1 year ago

rename the directory can resolve it, but There are same problems in macos and windows 10. so i suguest to add zh dir to OrchardCore.Translations repo, or add some codes to enhance it. (^^_)

As mentioned above, it is the same on Mac and Windows

leave the code for now , the cultures might differ from OS to another, just let me know if you set zh-CN as default culture in OC what happen? is it displayed correctly or not?

correctly!

hishamco commented 1 year ago

If it's displayed correctly, the zh is not a problem because OC don't provide a resources for it by default

hyzx86 commented 1 year ago

Ok, so we should change the zh-CN folder to zh or map it to zh in oc

then zh-CN -> zh-Hans -> zh

hishamco commented 1 year ago

if we change it to zh what about zh-TW?

then zh-CN -> zh-Hans -> zh

For that I told you try to set your default culture to zh-CN and forgot everything about zh :)

hyzx86 commented 1 year ago

But if I do not explicitly add zh-CN there, there will be no zh-CN option on the page Therefore, 'zh CN' cannot be set as the default

hishamco commented 1 year ago

Did you mean there's no option for zh-CN in the available cultures?

hyzx86 commented 1 year ago

😥My PR just add an option on the UI

hishamco commented 1 year ago

@hyzx86 please refer to https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo?view=net-7.0#cultureinfo-and-cultural-data

zh-CN is an alias to zh-Hans-CN which is should be available in your OC installation

hishamco commented 1 year ago

I realize that we need to rename the Chinese cultures folders to zh or in case to support simplified & traditional versions we should use zh-Hans-CN and zh-Hant-TW or more precisely zh-Hans and zh-Hant instead of zh-CN and zh-TW @hyzx86 correct me if I'm wrong

/cc @sebastienros @agriffard

hyzx86 commented 1 year ago

Let me try, but I don't think it should recognize the zh-CN passed in by the browser

hishamco commented 1 year ago

I think we should ignore both zh-CN and zh-TW

hyzx86 commented 1 year ago

image image

hyzx86 commented 1 year ago

Yes, it doesn't recognize the language information passed in by the browser

https://user-images.githubusercontent.com/15613121/210428219-4b50552b-e54f-44a2-b9bb-45cf210f72ce.mp4

hyzx86 commented 1 year ago

It's been a long time coming, almost a year since 6.0 was released This question is very unfriendly to Chinese users New Chinese developers think there is no Chinese language option at all Sometimes can inexplicably install a Chinese interface out.

Or, just to keep things simple, let's iterate over all the language packages supported by OC and just show the ones that are supported. There are so many languages in the world and OC only supports some of them. Why list them all?

hishamco commented 1 year ago

zh-Hans-CN

As I mentioned above zh-CN is not listed that's why I'm suggesting not relaying on such cultures. I just renamed zh-CN folder to zh-Hans-CN and everything works as expected

hyzx86 commented 1 year ago

That's because your browser's default language is not zh-CN I think default should refer to the browser language first and the site language second As you can see in my screenshot above, if you add the zh-CN option, it will recognize the installed language based on the browser language even if zh-CN is not set as the default language

hyzx86 commented 1 year ago

Just let me know what will happen if you set your culture to zh-CN in the admin?

chrome_mD27wx9tZM.mp4 But, there is no place for switching languages in the OC admin theme.

here

https://user-images.githubusercontent.com/15613121/210253277-a335ff13-e180-4b76-8c5f-9e6d3dd86e61.mp4

hishamco commented 1 year ago

FYI if your browser has one of the listed culture it will get a priority, coz RequestCultureProvider check AcceptLanguageHeaders first

Skrypt commented 1 year ago

@hyzx86 The reason is that cultures can have different codes based on the OS that you are using. We are using Crowdin to generate these culture folders so that we have at least translations for common culture codes. We can't provide every folder for every culture code.

sebastienros commented 1 year ago

What I see is that zh-CN is not available after .NET 5.0 and that might be the source of the problem. So adding it manually might "fix" the issue. Can someone look for the recording of the meeting when we decided which zh languages we would support by default (there were concrete arguments).

Also having support for zh might be a good safety net. However I am not sure which current files should become the zh ones. Traditional Chineese?

sebastienros commented 1 year ago

Results in sharplab io whatever the .NET version

zh - Chinese
zh-Hans - Chinese (Simplified)
zh-Hans-CN - Chinese (Simplified, China)
zh-Hans-HK - Chinese (Simplified, Hong Kong SAR China)
zh-Hans-MO - Chinese (Simplified, Macao SAR China)
zh-Hans-SG - Chinese (Simplified, Singapore)
zh-Hant - Chinese (Traditional)
zh-Hant-HK - Chinese (Traditional, Hong Kong SAR China)
zh-Hant-MO - Chinese (Traditional, Macao SAR China)
zh-Hant-TW - Chinese (Traditional, Taiwan)

@hyzx86 Assuming we create a new zh culture so we have a fallback in all cases (which I think would be safer). Should this zh culture use zh-Hant - Chinese (Traditional) or zh-Hans - Chinese (Simplified) ? Then we would just add the other one as a specific one Examples: 1- zh (with Simplified values) + zh-Hant 2- zh (with Traditional values) + zh-Hans

Assuming we only keep

hyzx86 commented 1 year ago

zh-Hant,zh-Hans
Yes, I think these are enough, because in terms of characters, Chinese is not so much variety, it is more about pronunciation

hyzx86 commented 1 year ago

But t for me personally... zh-Hans This kind of writing is a little strange. I've been using computers for decades and I'm most familiar with zh-CN because that's how almost all websites are written. Just like here: image

or here image

Skrypt commented 1 year ago

So basically "simplified" Chinese is more common?