Repository navigation
Add FLEx-compatible per-writing-system collation to FwLite #2406
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c0ec322
Store writing system collation on import from FLEx.
hahn-kev 34292c3
Add writing system collator provider and use it for LcmCrdt sorting.
hahn-kev dbfdaab
Use ICU4N for FwLite collation and seed demo sort on example project.
hahn-kev cb0adbc
Replace ICU4N with icu.net for FwLite collation
hahn-kev ea27f59
Bump icu.net to 3.0.3-beta.34 for Android support
hahn-kev 7396672
Initialize ICU once at FwLite startup
hahn-kev 99c15ac
Regenerate public OpenAPI schema for writing system collation fields
hahn-kev 1784fe5
Import own-language system collation as default ordering
hahn-kev 2adb6d8
Merge develop into feature/writing-system-collation
hahn-kev 99ba1b6
Merge develop into feature/writing-system-collation
hahn-kev 289775e
Decode Unicode escapes in ICU collation rules like libpalaso
hahn-kev 6ac656f
Address collation review feedback
hahn-kev 4c02be7
Merge remote-tracking branch 'origin/develop' into feature/writing-sy…
claude f54ead0
Regenerate regression data after merging develop
claude fa750c1
Validate patched writing system collation; fix collator tests
hahn-kev d89b35f
Merge remote-tracking branch 'origin/feature/writing-system-collation…
hahn-kev 2ba2025
Check ICU init error code and cache init failure
hahn-kev 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 hidden or 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 hidden or 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 hidden or 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
52 changes: 52 additions & 0 deletions
52
backend/FwLite/FwDataMiniLcmBridge.Tests/Collation/WritingSystemCollationExtractorTests.cs
This file contains hidden or 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,52 @@ | ||
| using FwDataMiniLcmBridge.Collation; | ||
| using FwDataMiniLcmBridge.LcmUtils; | ||
| using SIL.LCModel.Core.WritingSystems; | ||
| using SIL.WritingSystems; | ||
|
|
||
| namespace FwDataMiniLcmBridge.Tests.Collation; | ||
|
|
||
| public class WritingSystemCollationExtractorTests | ||
| { | ||
| // Validating a collation needs SLDR and ICU | ||
| public WritingSystemCollationExtractorTests() => ProjectLoader.Init(); | ||
|
|
||
| private static CoreWritingSystemDefinition Ws(string tag, CollationDefinition collation) => | ||
| new(tag) { DefaultCollation = collation }; | ||
|
|
||
| [Fact] | ||
| public void OwnLanguageSystemCollation_IsDefaultOrdering() | ||
| { | ||
| WritingSystemCollationExtractor.Extract(Ws("es", new SystemCollationDefinition { LanguageTag = "es" })) | ||
| .Should().Be(((string?)null, (string?)null)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void OtherLanguageSystemCollation_StoresLocale() | ||
| { | ||
| WritingSystemCollationExtractor.Extract(Ws("es", new SystemCollationDefinition { LanguageTag = "fr" })) | ||
| .Should().Be(((string?)null, "fr")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CustomIcuRules_StoresRules() | ||
| { | ||
| WritingSystemCollationExtractor.Extract(Ws("es", new IcuRulesCollationDefinition("standard") { IcuRules = "&b < a" })) | ||
| .IcuCollationRules.Should().Contain("&b < a"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DefaultOrdering_IsNull() | ||
| { | ||
| WritingSystemCollationExtractor.Extract(Ws("es", new IcuRulesCollationDefinition("standard"))) | ||
| .Should().Be(((string?)null, (string?)null)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CustomSimpleRules_StoresCompiledRules() | ||
| { | ||
| var (rules, locale) = WritingSystemCollationExtractor.Extract(Ws("es", new SimpleRulesCollationDefinition("standard") { SimpleRules = "b B\na A" })); | ||
| locale.Should().BeNull(); | ||
| rules.Should().NotBeNullOrEmpty(); | ||
| rules!.IndexOf('b').Should().BeLessThan(rules.IndexOf('a'), "simple rules list b before a"); | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
backend/FwLite/FwDataMiniLcmBridge.Tests/MiniLcmTests/CustomCollationSortingTests.cs
This file contains hidden or 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,33 @@ | ||
| using FwDataMiniLcmBridge.Api; | ||
| using FwDataMiniLcmBridge.LcmUtils; | ||
| using FwDataMiniLcmBridge.Tests.Fixtures; | ||
| using MiniLcm.Models; | ||
| using SIL.WritingSystems; | ||
|
|
||
| namespace FwDataMiniLcmBridge.Tests.MiniLcmTests; | ||
|
|
||
| [Collection(ProjectLoaderFixture.Name)] | ||
| public class CustomCollationSortingTests(ProjectLoaderFixture fixture) : CustomCollationSortingTestsBase | ||
| { | ||
| protected override Task<IMiniLcmApi> NewApi() | ||
| { | ||
| return Task.FromResult<IMiniLcmApi>(fixture.NewProjectApi("collation-sorting-test", "en", "en")); | ||
| } | ||
|
|
||
| protected override async Task CreateWritingSystemWithCollation(WritingSystem writingSystem) | ||
| { | ||
| await Api.CreateWritingSystem(writingSystem with { IcuCollationRules = null, SystemCollationLocale = null }); | ||
| var fwDataApi = (FwDataMiniLcmApi)BaseApi; | ||
| await fwDataApi.Cache.DoUsingNewOrCurrentUOW("Set collation", | ||
| "Revert collation", | ||
| () => | ||
| { | ||
| // collation is import-only, so it can't be set through the api | ||
| var ws = fwDataApi.Cache.ServiceLocator.WritingSystemManager.Get(writingSystem.WsId.Code); | ||
| ws.DefaultCollation = writingSystem.IcuCollationRules is { } rules | ||
| ? new IcuRulesCollationDefinition("standard") { IcuRules = rules } | ||
| : new SystemCollationDefinition { LanguageTag = writingSystem.SystemCollationLocale }; | ||
| return ValueTask.CompletedTask; | ||
| }); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
30 changes: 30 additions & 0 deletions
30
backend/FwLite/FwDataMiniLcmBridge/Collation/WritingSystemCollationExtractor.cs
This file contains hidden or 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,30 @@ | ||
| using SIL.LCModel.Core.WritingSystems; | ||
| using SIL.WritingSystems; | ||
|
|
||
| namespace FwDataMiniLcmBridge.Collation; | ||
|
|
||
| public static class WritingSystemCollationExtractor | ||
| { | ||
| public static (string? IcuCollationRules, string? SystemCollationLocale) Extract(CoreWritingSystemDefinition ws) | ||
| { | ||
| var cd = ws.DefaultCollation; | ||
| cd.Validate(out _); | ||
|
|
||
| return cd switch | ||
| { | ||
| // liblcm/libpalaso default a writing system without collation to its own language's system collation | ||
| SystemCollationDefinition sys when IsOwnLanguage(sys, ws) => (null, null), | ||
| SystemCollationDefinition sys => (null, sys.LanguageTag), | ||
| // Custom ICU and Custom Simple both compile to CollationRules | ||
| RulesCollationDefinition rules when !string.IsNullOrEmpty(rules.CollationRules) | ||
|
hahn-kev marked this conversation as resolved.
|
||
| => (rules.CollationRules, null), | ||
| // FLEx "Default Ordering" is an IcuRulesCollationDefinition with empty rules, i.e. ICU root. | ||
| // We map it to null (FwLite's .NET culture fallback) rather than storing an empty rule set. | ||
| // https://github.com/sillsdev/libpalaso/blob/32ca8a0a/SIL.Windows.Forms.WritingSystems/WritingSystemSetupModel.cs#L43-L47 | ||
| _ => (null, null) | ||
| }; | ||
| } | ||
|
|
||
| private static bool IsOwnLanguage(SystemCollationDefinition sys, CoreWritingSystemDefinition ws) => | ||
| string.IsNullOrEmpty(sys.LanguageTag) || string.Equals(sys.LanguageTag, ws.LanguageTag, StringComparison.OrdinalIgnoreCase); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.