Add support for localization file splitting#25227
Conversation
|
Anton Gritsenko seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
There was a problem hiding this comment.
Pull request overview
This PR adds support for splitting a single culture’s localization texts across multiple JSON files and merging them at load time (with “last value wins” semantics), along with tests and documentation updates.
Changes:
- Merge multiple localization dictionaries that share the same
cultureinstead of throwing when duplicates are found. - Allow duplicate localization keys within JSON input by overwriting previous values.
- Add new test resources/tests and update localization documentation to describe file-splitting behavior.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| framework/src/Volo.Abp.Localization/Volo/Abp/Localization/VirtualFiles/VirtualFileLocalizationResourceContributorBase.cs | Merges dictionaries for the same culture instead of throwing. |
| framework/src/Volo.Abp.Localization/Volo/Abp/Localization/StaticLocalizationDictionary.cs | Adds dictionary merge support for static dictionaries. |
| framework/src/Volo.Abp.Localization/Volo/Abp/Localization/Json/JsonLocalizationDictionaryBuilder.cs | Removes duplicate-key exception; last value overwrites. |
| framework/src/Volo.Abp.Localization/Volo/Abp/Localization/ILocalizationDictionary.cs | Adds a new Merge member to the public interface. |
| framework/test/Volo.Abp.Localization.Tests/Volo/Abp/Localization/AbpLocalizationTestModule.cs | Registers a new test resource using split virtual JSON files. |
| framework/test/Volo.Abp.Localization.Tests/Volo/Abp/Localization/AbpStringLocalizerFactory_Tests.cs | Adds a test asserting merged values from split files. |
| framework/test/Volo.Abp.Localization.Tests/Volo/Abp/Localization/AbpLocalization_Tests.cs | Adds a test asserting de texts are loaded from multiple files. |
| framework/test/Volo.Abp.Localization.Tests/Volo/Abp/Localization/JsonLocalizationDictionaryBuilder_Tests.cs | Adds tests for duplicate keys and deep-key collisions. |
| framework/test/Volo.Abp.Localization.Tests/Volo/Abp/Localization/TestResources/Source/de.json | Moves some de texts out to a separate file to test merging. |
| framework/test/Volo.Abp.Localization.Tests/Volo/Abp/Localization/TestResources/Source/de_Book.json | New de split file containing book-related texts. |
| framework/test/Volo.Abp.Localization.Tests/Volo/Abp/Localization/TestResources/FilesSplit/!en_First.json | New split-file fixture to test ordering/overrides. |
| framework/test/Volo.Abp.Localization.Tests/Volo/Abp/Localization/TestResources/FilesSplit/en_Base.json | New split-file fixture with base texts. |
| framework/test/Volo.Abp.Localization.Tests/Volo/Abp/Localization/TestResources/FilesSplit/en_Book.json | New split-file fixture with book texts. |
| framework/test/Volo.Abp.Localization.Tests/Volo/Abp/Localization/TestResources/FilesSplit/zen_Last.json | New split-file fixture intended to override earlier values. |
| docs/en/framework/fundamentals/localization.md | Documents multi-file-per-culture merging and override behavior. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #25227 +/- ##
==========================================
- Coverage 50.69% 50.05% -0.64%
==========================================
Files 3472 3557 +85
Lines 117030 119392 +2362
Branches 8826 9014 +188
==========================================
+ Hits 59327 59766 +439
- Misses 55894 57824 +1930
+ Partials 1809 1802 -7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @antonGritsenko, thanks for this contribution! We've reviewed the PR and made some adjustments on top of your implementation. Here's a summary of the changes: Core implementation (
Tests (
Documentation
|
|
@maliming thanks for improvement! Regarding the |
|
@antonGritsenko You're right, that's a valid point. I've restored the test with a clearer name ( |
|
hi Can you sign the CLA? https://cla-assistant.io/abpframework/abp?pullRequest=25227 Thanks. |
|
@maliming I did, but my name listed twice, not sure why. |
|
Merged! 👍 |
Description
See discussion #25217
The goal of this change is to bring support for multiple JSON files for the same culture. This can be really helpful in case if you have big module and do not want to split it to different resources.
There are few changes in the code, it just removes exception if same culture found.
It can handle duplicate key in same way as it before: last value will win. Order of the files will be handled by the
VirtualFileProvider(default: alphabetically). This mean that if same key defined in the different files, then value from the last file will be used (see unit tests)Checklist
How to test it?