-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix localization rule \Localization\[CultureName]\[ModuleId].po #16419
Changes from 20 commits
40898cf
a5d3281
c3dda09
f0aed7a
b9bf8bf
247011c
5656aa4
fc0a885
e5f756b
e7e5867
bc73079
398141b
314bd0b
fb212c2
4969c0e
51b4481
be6222a
39124a1
648eb28
83bfaf4
66b500c
95b1b54
42d7293
58785a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
using OrchardCore.Entities; | ||
using OrchardCore.Environment.Shell; | ||
using OrchardCore.Localization; | ||
using OrchardCore.Localization.Models; | ||
using OrchardCore.Settings; | ||
using OrchardCore.Tests.Apis.Context; | ||
|
||
namespace OrchardCore.Tests.Localization | ||
hyzx86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
|
@@ -43,7 +48,7 @@ public void GetDictionaryReturnsDictionaryWithTranslationsFromProvider() | |
.Setup(o => o.LoadTranslations(It.Is<string>(culture => culture == "cs"), It.IsAny<CultureDictionary>())) | ||
.Callback<string, CultureDictionary>((culture, dictioanry) => dictioanry.MergeTranslations(new[] { dictionaryRecord })); | ||
|
||
var manager = new LocalizationManager(new[] { _pluralRuleProvider.Object }, new[] { _translationProvider.Object }, _memoryCache); | ||
var manager = new LocalizationManager([_pluralRuleProvider.Object], [_translationProvider.Object], _memoryCache); | ||
|
||
var dictionary = manager.GetDictionary(CultureInfo.GetCultureInfo("cs")); | ||
var key = new CultureDictionaryRecordKey { MessageId = "ball" }; | ||
|
@@ -67,11 +72,57 @@ public void GetDictionarySelectsPluralRuleFromProviderWithHigherPriority() | |
It.IsAny<CultureDictionary>()) | ||
); | ||
|
||
var manager = new LocalizationManager(new[] { _pluralRuleProvider.Object, highPriorityRuleProvider.Object }, new[] { _translationProvider.Object }, _memoryCache); | ||
var manager = new LocalizationManager([_pluralRuleProvider.Object, highPriorityRuleProvider.Object], [_translationProvider.Object], _memoryCache); | ||
|
||
var dictionary = manager.GetDictionary(CultureInfo.GetCultureInfo("cs")); | ||
|
||
Assert.Equal(dictionary.PluralRule, csPluralRuleOverride); | ||
} | ||
|
||
[Theory] | ||
[InlineData("en", "Hello en !")] | ||
[InlineData("zh-CN", "你好!")] | ||
hyzx86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public async Task TestLocalizationRule(string culture, string expected) | ||
{ | ||
var context = new SiteContext(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a functional test, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I don't understand what you mean. I think this is the closest test to the actual operation. |
||
await context.InitializeAsync(); | ||
|
||
await context.UsingTenantScopeAsync(async scope => | ||
{ | ||
var shellFeaturesManager = scope.ServiceProvider.GetRequiredService<IShellFeaturesManager>(); | ||
var availableFeatures = await shellFeaturesManager.GetAvailableFeaturesAsync(); | ||
var featureIds = new string[] { "OrchardCore.Localization.ContentLanguageHeader", "OrchardCore.Localization" }; | ||
var features = availableFeatures.Where(feature => featureIds.Contains(feature.Id)); | ||
|
||
await shellFeaturesManager.EnableFeaturesAsync(features, true); | ||
|
||
var siteService = scope.ServiceProvider.GetRequiredService<ISiteService>(); | ||
var siteSettings = await siteService.LoadSiteSettingsAsync(); | ||
|
||
siteSettings.Alter<LocalizationSettings>("LocalizationSettings", localizationSettings => | ||
{ | ||
localizationSettings.DefaultCulture = culture; | ||
localizationSettings.SupportedCultures = [culture]; | ||
}); | ||
|
||
await siteService.UpdateSiteSettingsAsync(siteSettings); | ||
|
||
var shellSettings = scope.ServiceProvider.GetRequiredService<ShellSettings>(); | ||
var shellHost = scope.ServiceProvider.GetRequiredService<IShellHost>(); | ||
|
||
await shellHost.ReleaseShellContextAsync(shellSettings); | ||
}); | ||
|
||
await context.UsingTenantScopeAsync(scope => | ||
{ | ||
using var cultureScope = CultureScope.Create(culture, culture); | ||
var localizer = scope.ServiceProvider.GetRequiredService<IStringLocalizer<LocalizationManagerTests>>(); | ||
|
||
// Assert | ||
Assert.Equal(expected, localizer["hello!"]); | ||
|
||
return Task.CompletedTask; | ||
}); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
msgctxt "OrchardCore.Tests.Localization.LocalizationManagerTests" | ||
msgid "hello!" | ||
msgstr "Hello en !" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
msgctxt "OrchardCore.Tests.Localization.LocalizationManagerTests" | ||
msgid "hello!" | ||
msgstr "你好!" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,12 @@ | |
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Localization\*\OrchardCore.Tests.po"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
Comment on lines
+83
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need, you can add them as embedded resources There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are not same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to preserve the newest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the target rule needs to copy it to the output directory. |
||
<Import Project="..\..\src\OrchardCore.Build\OrchardCore.Commons.targets" /> | ||
|
||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You must do this, or you will lose the PO files. You can try it.