-
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
40898cf
fix localization rule \Localization\[CultureName]\[ModuleId].po
hyzx86 a5d3281
Update ModularPoFileLocationProvider.cs
hyzx86 c3dda09
Merge branch 'main' into patch-2
hyzx86 f0aed7a
add TestLocalizationRule
hyzx86 b9bf8bf
Merge branch 'patch-2' of https://github.com/hyzx86/OrchardCore into …
hyzx86 247011c
add empty line
hyzx86 5656aa4
Update OrchardCore.Tests.po
hyzx86 fc0a885
Update OrchardCore.Tests.po
hyzx86 e5f756b
Update test/OrchardCore.Tests/Localization/LocalizationManagerTests.cs
hyzx86 e7e5867
Apply suggestions from code review
hyzx86 bc73079
fix test
hyzx86 398141b
fix files
hyzx86 314bd0b
Merge branch 'main' into patch-2
hyzx86 fb212c2
Apply suggestions from code review
hyzx86 4969c0e
Merge branch 'main' into patch-2
hyzx86 51b4481
Sort using
be6222a
Merge branch 'main' into patch-2
hyzx86 39124a1
Merge branch 'main' into patch-2
hyzx86 648eb28
Merge branch 'main' into patch-2
hyzx86 83bfaf4
Merge branch 'main' into patch-2
hishamco 66b500c
Merge tag 'before-formatting' into patch-2
sebastienros 95b1b54
Format code
sebastienros 42d7293
Merge tag 'formatting' into patch-2
sebastienros 58785a6
Merge branch 'main' into patch-2
hyzx86 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
using OrchardCore.Environment.Shell; | ||
using OrchardCore.Localization; | ||
|
||
using OrchardCore.Localization.Models; | ||
using OrchardCore.Settings; | ||
using OrchardCore.Tests.Apis.Context; | ||
using OrchardCore.Entities; | ||
hyzx86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
namespace OrchardCore.Tests.Localization | ||
hyzx86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public class LocalizationManagerTests | ||
|
@@ -43,7 +47,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 +71,49 @@ 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); | ||
} | ||
|
||
|
||
hyzx86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[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); | ||
hyzx86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
await context.UsingTenantScopeAsync(scope => | ||
{ | ||
var S = scope.ServiceProvider.GetRequiredService<IStringLocalizer<LocalizationManagerTests>>(); | ||
|
||
Assert.Equal(expected, S["hello!"]); | ||
hyzx86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return Task.CompletedTask; | ||
}); | ||
} | ||
|
||
hyzx86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
msgctxt "OrchardCore.Tests.Localization.LocalizationManagerTests" | ||
msgid "hello!" | ||
msgstr "Hello en !" |
3 changes: 3 additions & 0 deletions
3
test/OrchardCore.Tests/Localization/zh-CN/OrchardCore.Tests.po
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
msgctxt "OrchardCore.Tests.Localization.LocalizationManagerTests" | ||
msgid "hello!" | ||
msgstr "你好!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.