We have a .NET MAUI Hybrid app that needs translations. The usual way to do this is to use .resx files but based on our requirements they are not good enough.
Architecture:
Our theoretical approach
adhoc download - we dont want translations to be baked into app in build process, but when we edit something (e.g. some typo), client will fetch a new version on his app startup
structure - the final translation JSON has a structure based on Pages and Components. Example:
{ "General":{ "Yes": "Yes", "No": "No", "Cancel": "Cancel" }, "Pages": { "Home": { "Title": "Home", "Statistics": "Statistics" }, "About": { "Title": "About", "Developers": "Developers" } }, "Components":{ "Header": { "Title": "Header", "Back": "Go back" }, "Footer": { "AllRightsReserved": "All rights reserved" } } }
not to do typos on client (when calling localisation dict like L["Pages.Home.Title"]
), we would like to use some class with pre-defined properties duplicating structure of the JSON. Example: In case I have HomePage.razor
I will inject translation service that would contain: _translationService.Translations.Pages.Home.Title
Proposed flow:
HomePage.razor
Questions:
One of the very first things, that I have done about localization, was something very similar to this.
XML file, containing serialized dictionary, saved on Windows Mobile device, with code using NET Compact Framework 2.0.
It works. And this is the only good thing I can say about it.
You see, localization is not just some key-value pairs, that you store somewhere. Just because you see "Hallo" instead of "Hello", it does not mean that your app is now perfectly fit for German people.
At some point, I started to stick to what is generally used, working stable and easy to implement.
You are planning to do the opposite.
(This is opinion based, but your question leads that way anyway)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With