Localization: split to json files #25217
|
Hello The current implementation of the standard localization engine is quite good, except one thing: if you have big module with a lot of strings, handling this starts to be a nightmare. What the reason behind this decision? Why you don't allow to split localization to different file like The implementation also will not be hard (I can add PR if it's OK), I did it already for my own project, but it's big overhead, because I need to implement the entire logic from scratch. The reason is implementation of the I did my own like that (see Merge method): |
Replies: 6 comments
|
Hi, Thanks for the detailed analysis and the workaround you've already implemented. This is a valid use case — large modules can end up with hundreds of localization keys in a single file, and splitting by entity/feature is a reasonable way to keep things maintainable. We're open to accepting a PR for this. A few things to keep in mind:
Feel free to open a PR — we'll review it. Thanks |
|
@maliming thanks for inputs. About point 1, I don't think we need to change current behavior. Having same keys is not something that should be the case, and throw the error like it now is fine: |
|
Hi, Good point — I agree. Keeping the exception for duplicate keys across files is the safer approach. The purpose of splitting files is organizing keys, not overriding them. Throwing an error when the same key appears in multiple files will help users catch unintentional duplicates early. Looking forward to your PR. Thanks |
|
@maliming I'm thinking about this check: and can't find any case then this check will make sense.
Sample for second case: var input = @"{
""culture"": ""en"",
""texts"": {
""ThisFieldIsRequired"": ""This field is required"",
""DeepLocaliaztionKey"": {""DeepKey"": ""DeepValue""},
""DeepLocaliaztionKey__DeepKey"": ""Another translation""
}
}";
var localizationDictionary = JsonLocalizationDictionaryBuilder.BuildFromJsonString(input);
localizationDictionary.ShouldNotBeNull();
var localizationString = localizationDictionary.GetOrNull("DeepLocaliaztionKey__DeepKey");
localizationString.ShouldNotBeNull();
localizationString.Value.ShouldBe("Another translation");Do you know why this check was added? Actully, this even can't be the case because of nature of the |
|
Hi, You are right — this check is likely a leftover from earlier JSON library behavior that may have handled duplicate keys differently. It is effectively dead code now. Feel free to keep it or remove it in your PR — it is not a big deal either way. Thanks |
PR added #25227