Our App supports different languages, some of the translations contain mistakes. The translations on the server are correct.
What is the recommended way to update the strings.xml from the server and how it could be done? Which technologies would be involved?
You cannot update your app's resources without deploying a new APK.
If you want to continue keeping the translations in XML resources, you will need to update them appropriately then deploy a new version of your application.
If you would like those strings to come only from the server in the future, you will need to set up an API service to expose the strings, and consume that API in your app instead of loading the strings from resource files.
Related
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.
I am very new for developing the multi-language oriented Android APP. This is the first time i am going to support my app in multi-support language app. I need some clarification for developing the multi-language support app. Already i have some ideas before initiate the development.
Single APK with Localization like will make the multiple String.xml and include it in inside of the app and based the member selection of language its automatically invokes and works.
All language strings values will retain in app server (back-end) and will raise the Rest-API request and get those values and change it inside of the entire app (all screens) if member click and change the language inside of the app.
Main concern is if anything needs to change in future then Idea2 is best way. We will just change in back-end side it will be appeared in client side. But if we are going Idea1 and wants to change then we need to put the new build only.
Which one is best approach and recommended way to develop?
You will need to create different String.xml depending the languages you want to target as JDenais says, in my app i have the following
for example the first arab string consist in the same as Strings.xml but with all in arab, now, you only need to call one string in your xml files and it will just select where to grab depending on the phone language. Or in default the language from where the app was downloaded by google play, in fact, they are all the same strings.xml , so you dont need to specify which one you want to pull the translated text from, just replicate your main strings.xml in your other strings.xml and then the phone will decide where to pull the data.
Also please read the official doc on how to accomplish this https://developer.android.com/training/basics/supporting-devices/languages
Also please check the language ISO Codes here
What is the list of supported languages/locales on Android?
All your texts should be packaged in the APK in different String.xml files. Forget about receiving texts from a backend. It would be a lot of extra work for limited gain and with added risks of failure.
The framework takes care of selecting the appropriate string.xml file and offers support for needed use cases like plurals.
right click the values folder and choose new-> values resource file -> locale -> choose the language you want and name it strings.
copy the strings from the original string file to the new file and change them to the new language just the strings
make sure that the view xml files have their text set as "#string/the_name of the string" not hard coded
Why i ask this is because the size of my APK is huge. I wanna make it smaller.
There're lots of strings in strings.xml. Our product manager force us to support all languages on the earth.
I'd like to know, can I just put some languages of strings.xml locally, put others in a server, then when user launches the app, downloads the strings.xml from it dynamically according to the language of the user.
I am not quite clear about the process of how android load the strings.xml file. Any idea about it?
Thanks~~
can I just put some languages of strings.xml locally, put others in a server, then when user launches the app, downloads the strings.xml from it dynamically according to the language of the user.
You cannot modify resources at runtime. You are welcome to download and process XML files at runtime, and those XML files might contain strings that you want to display to the user. However, you cannot use the Android resource system to pull in those strings. You would need to write your own Java code that uses those values, including determining which translation to use for a given device (taking into account the multiple-locale support offered in Android 7.0).
You can easily call some web-service on your application start and fetch the strings of desired/selected language in form of say JsonArray. Then parse that data to some data-model like ArrayList of string to manage in your app
It's possible to add dynamic strings resources in my application from my API. Stored with json or XML and with the same format like it is right now?
I have already a multilingual website, so i want in my application to have the same strings from an API! How can i store them in my application in strings resources files?
sorry for my english.
Strings resources files cannot be updated in Application lifecycle because there are compiled when you generate your APK. Maybe you need to look after storing your strings in a database or something else . See https://developer.android.com/guide/topics/data/data-storage.html
As said before you can't modify the resources inside the app. But you can send the message/text in the required language from the server, I would implement a mechanism through which the app tells the server which language must use for the returned texts, and the app simply draws them when received. It is easy, simply change the focus from the app to the server.
I have some configuration I want to save it in my Android application and read it whenever I need , for instance, the server URL that it should try to access like that.
Is there any similar mechanism like web.config in ASP.NET available in Android?
A central configuration file that can be set up manually and then read by the application? Any help would be appreciated!
We use a .properties file in assets folder. It works out very well for us as we support multiple carriers with this, write to it (in case some values, sent from server, need to change. This is done at app start time, thus making our code configurable from server).
You can throw things like that into your strings.xml file. But, since you can't actually modify these values in real-time (since it's a distributed application rather than running on a server), throwing it into a constants class is quite acceptable.
Use Shared Preferences.
Here's a link Shared Preferences
You can use sq lite database files for it. You have a native API to read and write those and on top of that a command line tool.
If you want to create an XML file instead, then it's no different than any other xml file (unless you are thinking about the Shared Preferences, which use an xml format to save the data, but I believe it's not the best API for your application).
I was stumped on this too, but came across Managed Configurations in the Android documentation.
Managed configurations, previously known as application restrictions, allow the enterprise administrator to remotely specify settings for apps. This capability is particularly useful for enterprise-approved apps deployed to a managed profile.
It allows you to set a default value in case you rather not getting into the enterprise admistration business but leaves that option open for the future.
There is a caveat. This only works if your app is registered for EMM. Otherwise you will retrieve an empty map of restrictions.