Search code examples
c#asp.net-core.net-corepoorchardcore

Ability to use multiple po files for localization asp.net core 2.2


I'm using OrchardCore.Localization.Core NuGet package and follow this tutorial for making an asp.net core project localized. everything is works well and fine, I have files like en.po and fr.po for localizations for english and french languages. but i want to separate some words into separate file like splitting po files into en.po, fr.po, errorlist.en.po and errorlist.fr.po. I'm not looking for a smart way of separating some words just for a special files or etc. i just want to have some words in separate files to avoid having one big po file for each language. I'm not quite sure i can't find any doc for this matter. Is OrchardCore.Localization.Core NuGet already have this feature? or can i implement something that can achieve this?


Solution

  • NOTE
    I asked this question on product own github issue list here and i want to add the owner answer here for future reference, all credits to Sébastien Ros:

    On the same documentation page, it mentions you can provide your own logic to file the files: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/portable-object-localization?view=aspnetcore-2.2#implementing-a-custom-logic-for-finding-localization-files

    Which means you can copy this file: https://github.com/OrchardCMS/OrchardCore/blob/dev/src/OrchardCore/OrchardCore.Localization.Core/ContentRootPoFileLocationProvider.cs

    And adapt the GetLocations() method to your needs, by for instance listing all the files that end with the specific culture instead of returning a single IFileInfo.

    Here is another example whe use in OC Framework to find file in multiple module folders: https://github.com/OrchardCMS/OrchardCore/blob/dev/src/OrchardCore.Modules/OrchardCore.Localization/ModularPoFileLocationProvider.cs

    Then you can register you provider like this:

    services.AddSingleton<ILocalizationFileLocationProvider, MyPoFileLocationProvider>();