aymanizz / ktor-i18n

Ktor Internationalization Feature
MIT License
41 stars 3 forks source link

Multi-module support #18

Open ilyasKerbal opened 9 months ago

ilyasKerbal commented 9 months ago

Is your feature request related to a problem? Please describe. The i18n extension doesn't support multi-modules. All the string resources must live inside the main app module.

Describe the solution you'd like I don't have any ideas at the moment.

Describe alternatives you've considered I use a simple Gradle script to merge all the string resources from different modules.

aymanizz commented 9 months ago

Thanks for submitting this feature request. Correct me if I am wrong, but I assume what you're asking for is essentially a way to merge multiple resource bundles into one when loading/reading them whether these come from multiple java/gradle/maven modules or even libraries. As far as I understand it, ResourceBundle uses a class loader to read the required resource and picks the first match, there's no builtin mechanism for merging multiple bundles. However, it should be possible to extend the ResourceBundle or ResourceBundle.Control to support this.

I don't think I'll have the time to implement this into the extension but you're welcome to contribute it if you want. The goal for this extension was to provide a base for implementing I18n support, while being flexible enough to allow extending it and changing the behaviour according to your needs. Thus, the loading and reading of resources is kept simple.

One can implement their own ResourceBundle.Control to customize loading of resources which provides an opportunity to merge multiple bundles together, then provide the implementation to the ResourceBundleMessageResolver. Alternatively, an implementation of MessageResolver (maybe based on ResourceBundleMessageResolver`) could implement custom functionality for the look up of a key in multiple resource bundles.

ageorgousakis commented 5 months ago

@ilyasKerbal can you please share the Gradle script you use to merge all the string resources from different modules?

Regards