-1

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.

Draif Kroneg
  • 743
  • 13
  • 34

3 Answers3

1

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).

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0

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.

Jonas Köritz
  • 2,606
  • 21
  • 33
  • But facebook suggests to use strings.xml for their ids: https://developers.facebook.com/docs/android/getting-started Why would they do that? – Draif Kroneg Apr 20 '16 at 17:09
  • Google will include using an ids.xml file in some of their guides. Facebook might use strings.xml to make the tutorial less steps and easier to follow for beginners. – Jonas Köritz Apr 20 '16 at 17:14
  • `ids.xml` is for creating an `R.id` resource. I believe OP is referring to API keys, which are strings, and therefore placed in `strings.xml` – OneCricketeer Apr 20 '16 at 17:17
  • @cricket_007 You can store strings in ids.xml too, the filename is not relevant. – Jonas Köritz Apr 20 '16 at 17:22
  • True, but [What is ids.xml used for?](http://stackoverflow.com/questions/7621358/what-is-ids-xml-used-for) says otherwise. – OneCricketeer Apr 20 '16 at 17:25
  • i already changed my answer to reflect that. I think its considered bad design/structure to misuse ids.xml for this. – Jonas Köritz Apr 20 '16 at 17:26
0

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.

satyapol
  • 983
  • 11
  • 16