libreliodev / android

Android Customizable Reader - Librelio Digital Publishing Suite
www.librelio.com
226 stars 129 forks source link

Make it possible to customize translations #243

Closed libreliodev closed 9 years ago

libreliodev commented 10 years ago

This should be done in a similar way as https://github.com/libreliodev/iOS/issues/72 .

intrications commented 10 years ago

@libreliodev Is this different from using the various strings.xml files in values, values-fr, etc for translations?

libreliodev commented 10 years ago

@intrications What has been implemented on iOS with https://github.com/libreliodev/iOS/issues/72 is the ability for apps to have custom translations. There is a generic translation for each important language in Localization.strings, and there can be specific translations in Application.strings, which will override the generic translation.

On Android, we have the equivalent of Localization.strings with strings.xml. But we don't have the equivalent of Applications.strings. Is it possible to have the same <string name="XXX"> present in 2 xml files, with precedence given to one file? Or do you have other suggestions?

intrications commented 10 years ago

I understand now.

I will have a think about the best way to do this. I can think of a hacky way to do it off the top of my head. You can have strings defined multiple times by we need to make the customisations the highest priority.

This could be done by putting the strings in a values-v14 which would take precedence over the values folder. I can create a test project to show you.

libreliodev commented 10 years ago

@intrications Thank you for this idea. We had the same idea on iOS (creating a fictive language, that would have precedence over the other ones), but we chose another solution, for 2 reasons:

Is there a way, as we did on iOS (see https://github.com/libreliodev/iOS/commit/2de4f76b05466727eca13b95a7654c1c45d8f5ad) to create a method that will be used every time we need a translation, and will try first with customized translation, and then with standard translation?

intrications commented 9 years ago

This should now be easily possible with Gradle and product flavours.

libreliodev commented 9 years ago

@intrications Thanks a lot for your comment. My understanding is that product flavours in Gradle are similar to targets on iOS. If I am right, I am not sure it's a good option. We originally used different targets for different customers and apps on iOS, but it quickly became unmanageable. Having a different customization folder for each app, from where you get all specific elements (including specific translations) using a bash script, is a much better option according to me.

intrications commented 9 years ago

@libreliodev

Don't worry. I understand your concern. That is not my plan.

I have now set up the code to have one extra "script" product flavour. The bash script will copy all the files into this product flavour folder just for the build. The customizations can remain in a folder on Dropbox. (The bash script already does copy the files, it just copies the files over the top of the main ones at the moment.)

But this "script" product flavour allows us to override all resources including strings, images and layouts and it will handle merging of the resources.

libreliodev commented 9 years ago

@intrications

Sorry, I just wanted to make absolutely sure we understood each other! This is absolutely brilliant, many thanks.

cc @ahazeb

intrications commented 9 years ago

@libreliodev

No problem, I'm just glad the Android build tools have improved to the stage where this is possible. It's why I was so eager to switch to Gradle.