In my project in Android Studio, I have many different string values that I've put in different strings-....xml files. Sometimes finding a specific string resource gets really difficult, even when I'm using a naming convention.
So, I was wondering:
Considering that the string resources names are unique across all the files, is there any way to see all the string resources in one place? Or search through all of them?
(Double-Shift search doesn't actually make it easier!)
There is a new feature in the latest Android Studio 0.8.7 (only in canary channel yet) – Translation Editor.
http://tools.android.com/recent/androidstudio087released
Related
I have the localised string file(s) of an internationalised Android app. Now I want to bring the string translations over to a new Windows Phone 8 ("WP8") app without having to manually copy every string individually.
I found several tools that can do iOS -> Android and/or Android -> iOS (e.g. LocalizedStrings2Android, stringsconvert, etc.), but there seems to be no tool out there that can transform the string files Android -> WP8 (or even iOS -> WP8).
Apple's iOS uses files with simple key-value pairs, Android has an XML file, and WP8 uses "XAML" that contains special binding clauses. WP8's format/content differs quite a bit from iOS's and Android's. Is that the reason no tool(s) exist?
I'd appreciate any pointers to existing tools or hints how to best approach this problem.
If you choose to downvote the question please be so kind to leave a comment.
And finally: No, web searches return nothing, unfortunately!
Microsoft Excel.
Open the Android’s strings.xml with it.
It will ask “How would you like to open?” choose “As an XML table”, it’ll message “Excel will create a schema”, press OK.
In Excel, use cut & paste to reorder the columns so the first column is "name" second is "string". You can cut and paste the compete columns by right-clicking on the headers.
Then you’ll be able to copy-paste the whole table, both names and strings, from Excel to the Visual Studio’s *.resx editor. You might have some issues if e.g. you have many names containing spaces, or with values containing newlines, but it still should be much faster then copy all your individual strings.
If you want to automate (e.g. if you have dozens of languages), the .resx format is a simple XML as well. If you know XSLT, the transformation will only take a few lines, if you don't, use any scripting language instead.
I am a bit noob in Android and recently I found out that I can use the predefined string that Android provides as #android:string/cancel or #android:string/ok. At first I thought it was a good idea to use them because is a way to reuse code, but now I am not so sure about that.
What if somebody with a device configured with a language that I don't support install my app?
I assume that the app will use a default language, probably english, but those string from #android:string will get translated to the user's language, so he will end up with a mix of languages.
It this true? What do you think about use #android:string?
Thanks!
EDIT: Apparently my question hasn't been understood properly. I am NOT asking about how to support different languages. My question is about the convenience of use strings defined on #string:android, if it is correct to use them or can be lead to undesirable situation like a mix up of languages in the same application.
To ensure that your strings are appearing properly on devices configured with different languages, you'll want to create different values directories for different languages. For example, your default string values would be kept under values/strings.xml and French string values would be kept under values-fr/strings.xml.
The Android Developer website gives you plenty of information for supporting different languages in your application. http://developer.android.com/training/basics/supporting-devices/languages.html
The android: values (strings, icons, themes, etc.) will differ between devices and Android versions. If you want to use them, it's safest to copy them into your project. So for strings, you wouldn't have to worry about partial translation.
In the ressource folder of your app (res), ther is a folder "values" in it, and in this folder is the string ressource xml (strings.xml).
Usually, your app selects the strings from this file.
But you can add other value folders like this: Just create a new folder and name it "values-countryCode", for example "values-ch" for Switzerland ;)
Your app automaticly chooses the right string ressource, depending on your device's langague settings. If the langague of your device isn't available, it just takes the sting ressource of the default "values" folder.
A list if the country-codes is here.
Further information can be found here.
Hope I helped, and this is what you're looking for!
This question already has answers here:
Why to use strings.xml?
(3 answers)
Closed 8 years ago.
In creation of UI in android projects ,why we have to refer values of string from the values folder's string.xml?
why eclipse shows warning if we assign values straight away?
I want to know the logic behind this,It's a very basic question but i couldn't find answer for this from google!
Another reason that is not covered in the older post pointed out by KenWolf, is that now when uploading your application to the Google Play Store, you can easily make your app more accessible to other languages/locations by uploading just your strings.xml to their new translation service announced at I/O 2013. This just has to do with localizing your resources like was stated here.
You can read more about it here.
There are many different advantages to using a string resource file, rather than hardcoding strings. While it may seem pointless and convoluted in small projects, it is incredibly useful in larger projects.
If you know that you want the same string to appear in multiple places, possible occurring in separate activities, the string resource file allows you to reference one source, rather than type the string over and over again.
If you decide to change a string in you app, or have a dynamically changing string, it is much easier to modify the resource file than it is to manually change all instances of that string in you app
It is great for localization and translation. If someone wants to port your app to a different language, all you have to do is substitute the strings.xml with a translated version
Thus, it may seem useless in small applications, but for large scale applications, it makes your life much simpler and allows you to more easily reach foreign language users.
The reason we are referring from String.xml is we can reuse the same string where ever we want.
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 :(
I have an app with support for several different languages.
Now lets say I want to add a new feature, which will usually will require new string resources to be added.
What is the (Or is there) way to add new string resources that will be added automatically to all the localization strings files? (Means i'll just need to translate the content of the string and not to create new one with the same key for each localization file)
Because it dosen't make any sense to copy-paste it manually when you have a lot of localization files...
If you follow Android localization rules, there isin't any other way other than manually adding to each language strings.xml file. You can script this but then you will have to write the script. So, my suggestion is to bite the bullet and do it.
As you said if there are a lot of files, then scripting it is best way, even then you may have to manually add the localized string values to each file.
What you refer to is common Localization problem. It is not just strings.xml and Android platform related.
As you might be guessing, people actually found ways to resolve it. Typically, you will send just the English file to translators (translation vendors) and they will update it using Translation Memory software.
Or if you are independent Software Developer, you may want to use some crowd-sourcing platform for your translations, like Launchpad, BabelZilla or Crowdin. These platforms also act as Translation Memory, so you won't have to manually synchronize individual language files.