Set localized defaults for remote config - android

I am implementing Remote Config in my app. The idea is to be able to A/B test some of the messages shown to the user.
I might want to run some of the experiments with the English messages only and I am trying to figure out what is the best (or most practical) way to do this.
One way would be having an xml file with default values for each language in the res/xml- directory. The main drawback I see is that this will be hard to maintain as every single value needs to be copied to all the xml files (some experiments might be language independent such as a layout color).
A second way would be setting language dependent values to an empty string and then implement some logic to look for the right string in R.strings if the value provided by remote config is empty. This seems like too much overhead for what I want to accomplish.
What is the recommended way to run experiments only for a certain language with A/B testing and Remote Config?

It is a default way in android to provide a localized string resources. Is hard to maintain but there are a service which can help you https://phraseapp.com/ . They have a lot of nice features, like manual translation, cross platform app and ide plugins which can replace/add/append/remove new strings to your xml localized files, also it works for ios.
You can keep string resources name in remote config and load it by some kid of reflection. Here is an nice answer How to get a resource id with a known resource name? . Here is an example for your case:
int resourceId = context.getResources().getIdentifier(nameFromRemoteConfig, "string", context.getPackageName())
Localization a very static logic, boring and expensive process in terms of time and maintaining. From my point of view better solution is to develop your own maximum abstract mechanism for localization and reuse it in all your projects. For example a backend service or library which will provide localized data by your own format, and a library for clients which will deserialize that data. As a result you will obtain production ready api for future projects.

Related

Is there any where I can upload two strings xml files to be translated?

My app is going to be translated by several amateur translators for several languages. I can send them the xml file with all the strings that need to be translated. But, is there a cleaner way to have two files uploaded, the one in English and the one to be translated, to easily identify the strings that are still missing? Basically is like having the Translation Editor of Android Studio but online.
Maybe using google docs? How do you do this?
You can use Google Docs, but that's quite an outdated way to handle this.
The major cons:
it would be cumbersome to update strings this way
no easy way to make sure the new ones have new translations, not the old ones, etc.
no good way to provide context, if needed (typically translators have questions). You can create a column with context and take any discussions into comments, but it can get messy
A few pros:
it's fast to create (although slow to keep up-to-date)
you cooperate online and have shared access
Most developers use localization platforms, which makes updating content and online cooperation much faster.
Main pros:
it's easy to identify strings that are missing
any number of translators can translate simultaneously
track work that is done by each of translators
you can add a review/proofreading step to the process to ensure the quality of translations
leverage Machine Translations and then just have translators review them (saves lots of time)
update content, as most platforms support agile workflow
you can see who's the top translator (give some rewards, invite to other projects, etc.)
integrations (with your Git tool, Android Studio, etc), so you can automate content updates, no manual copy-pasting
Cons:
some of them are paid (still, if you're open source, you can expect a free plan)
Regarding the tools, I can suggest looking at Crowdin or Poedit.
There are many alternatives you can research, some are listed on Wikipedia.
At my work we had to translate english into Norwegian, we've done that by working with an python script that generated an ui from an csv file, after that the file could be exported in several formates as well. But your question indicates that you would like to deploy only on android, so this might be an overkill.
a simple python xml filter would fit your aproach and you could work as well with git as long as the lines stays in the same order.
if you need an quick example please comment, and ill edit this answer as soon as i get time.
At one point I have also had the same question. I need the translation for my vernacular app, also I had the requirement to maintain such that I could easily compare the translation. Here I could suggest a few things that worked out for me.
First, take the string XML file and convert it in an Excel sheet, You may generate multiple excel sheet and having a copy, paste and merge all the translations into a single sheet.
Going forward it will be easy for you to maintain all the translation. Just share a single sheet which has a string key and multiple language column. So you could easily have a look at all language translations.
In the long run, it will be helpful to you.
Few links for the conversion of XML to excel -
Convert string XML to Excel sheet
Using the below online tool works for me. Free and Opensource easy and best.
https://asrt.gluege.boerde.de/

How should I store API URLs in Android, if they are dependent on locale?

Right now they are just stored on a class called Globals as static fields.
I'm not the one who made the app, but I am considering putting them in localized strings.xml files, such as <string name="API_URL">http://someurl</string>. Is this good or bad practice?
UPDATE:
I chose the answer that I feel answers the question most comprehensibly.
But after some re-thinking, I have chosen a different solution alltogether.
Given that URLs are actually based on the country which the app should be distributed for, it doesn't make sense to switch them based on locale, as the URLs should stay the same regardless of the language on the phone.
Instead, I have implemented Gradle Flavors, which create different APKs based on different settings and such. It allows you to create variations of the same app with the small changes that you need. :) So now I have the URLs in a flavor-specific file.
Thank you to everyone who took their time to comment and help me.
I agree with puneet, it's neither good nor bad. It depends on what you are doing with the API Urls.
Are you going to append them later with user input? If so I would suggest you keep them as global variables that way you can modify the API URL programatically as needed.
If the API Url are complete and will not need to be appended then putting them in the strings.xml would be fine. Just remember that you would still have to create a local String variable in the java to hold the text from the API_URL in the string.xml, which seems inefficient if what you're aiming for is to write less code.
Neither good nor bad.If your concern is the security then none of them provide the security as decompilation is possible.

Why app ids are stored in strings.xml in Android?

Isn't strings.xml is supposed to be used as a text storage for easing the translation of text in the app to other languages?
For example - Facebook app id according to facebook manuals is advised to be stored in strings.xml.
It means that if I want to share this file with 3-th parties for translation - I will have to manually remove all ids by myself, or share those ids with 3-th parties.
Isn't strings.xml is supposed to be used as a text storage for easing the translation of text in the app to other languages?
No. It's string storage for any kind of strings. Majority of use is localization related but it is perfectly fine to have anything that is string there like API keys, tokens whatever.
Please be aware that you are not limited to just strings.xml file. You can have as many *.xml files holding string resources as you like (so it's quite common to split localization per class/functional module and keep it in separate xml file).
You can create more then one strings.xml you could name it appids.xml and store all your ids inside this file. It is common software design pardigm to seperate data from code, so you won't just use a String constant for your id.
For Android best practices, Google is the source to go, for example they propose the usage of an appids.xml file here: Getting started with Play Games
Facebook might be using this simpler form of storing your id to make the tutorial easier to follow.
Basically it may happen that the ids that you're going to use inside your app may occur in multiple java class files. So by mistake there may be a chance that you mistype the id or secret key which will result in failure of result that you are expecting. As a good practice you should store such things in strings.xml which will help you minimizing the possibility of error in your result. Also if you change your id or key because of any reason then you might have to change that in each file where you've mentioned it. Instead of that if you just change it in strings.xml then it will automatically reflect at every instance where you've used it.
Going further, Android is open source. Thus any app that you create can be reverse engineered and all the code can be read. This leads to leakage of your id's and may be some secret keys for any api that you've used inside your app.

Is there a way to add or change Android apps language after packaging it into an APK?

In the case of a windows application(EXE/DLL), we can change or add language resources within the binary without re-compiling it. Can the same be done in case of an Android application? Is there any editor available to make this happen?
My plan is to develop the application in English and then release it to the sales department, where they will be responsible for the localization of the application without compiling and packaging it into a new APK. I just want to split the development part and localization part of the app.
The correct way to localize is to create a string resource for your base language and then have that localized and reimported into your project for every language that you support.
Much more detail can be found in the Localization documentation.
I don't believe there is a safe/supported way to inject localized strings into your app after it's been built.
No. You can not, because once your apk is signed then modifying it after this (you can always do that as apk is just a zip file) will corrupt the signed binary.
When having multiple languages with your application you have to build them into the application itself. Android uses XML files to store strings used within your application. Android allows you to add language localization files containing local specific strings. You can't do this without recompiling your project so you'll want to do it as a future update or right from the start. But you can't have the marketing department do it, that's just not a good idea.
As others have said, the short answer is no. The long(er) answer is sort of. If you pack all your language resources into remote XML that can be updated from the web, then with a little bit of forethought you can do all sorts of live updates to your app's strings, graphics, etc.
So if you want to use the standard R.string method for everything it will be a little difficult. I think it's possible to do something funky with a dynamic classloader for the assets and static dex classes (basically classes of data with just inline byte arrays that can be decoded after). However that would still require compiling. See Custom Class Loading in Dalvik for more info.
Another approach would be more of a standard Java implementation. Java has a class known as ResourceBundle. You could create a ResourceBundle from a property file (key-value plain text, or even property xml). Then these files could be loaded outside the apk, via a network connection or sdcard or other file type resource and deleted as necessary. You will have to write the loader code for it, but that's going to happen with any solution. This solution will be less performant and outside the standard design methods for android but it will solve the problem being asked to solve. Like you won't be able to use R.string or #string/whatever for any of these resources but I think you may be able to write an adapter to such resources (like your own TextView extension and whatever that would allow all of this). It's a matter mostly of how much work you want to invest in solving this actual problem.
Honestly I would opt for trying to distribute whole apks with only the targeted language if you are trying to save space, but then there is no way to change locale for the app at runtime :(

Android internationalization

I am planning to internationalize my Android app such that the user can choose the language that he wants. However, I will be providing an xml file for the translated words from my server when a client wants to switch from the default language.
What is the best way of incorporating this internationalization methodology in Android?
First thing, from what I recall, it would be difficult to load language specific xml from server. Android design allows you to package these string into xml file and load them from that file stored in res folder. Dynamic loading from server may be harder and not recommended.
You can read up in detail about Android's guidelines for that here.
I would also recommend using a professional translating company, it worked well for us but YMMV.

Categories

Resources