I use Android Studio in app development. I want to translate strings by exporting/importing the Android language resources (strings.xml) to Excel file (xlsx). What is the best way to do it?
If anyone else needed the answer,
from res -> strings -> right click-> Open Translations Editor. Select data/variable you need then copy and paste data from Translations Editor to excel . done.
Since CTRL+A not working now in the android studio.
There is one way to convert the android strings file to CSV and then translate it with the help of google translator and then again convert back to XML.
https://www.skydevelopers.net/blog/2-best-ways-to-translate-the-android-strings-file/
here is a blog in detail
Export Strings resource file to csv
Get its content translated(probably from google translate)
convert back the Translated file to Strings.xml(android string resource file)
I used http://convertcsv.com/csv-to-xml.htm this website for converting csv file to strings resource file
need to mention Custom output template to convert it to strings resource file
<string name="{f1}">{f2}</string>
put this in template section provided
website also displays the desired converted output file
As many others pointed out, pressing Ctrl+A in the Translations Editor doesn't work since Android Studio 3.2
I work for a company that outsources translations constantly, so we need to convert android strings to and from xls files.
The only solution that worked for us reliably is this fork of the older android-lang-tool. Just build with maven and run the jar.
It exports strings, string-arrays, plurals and their key-values to an xls file. It even exports the comments.
I would suggest the best tool for android app string localization is the Translations Editor that is inbuilt into Android Studio.
The reason this is a great approach is you are able to make the process both easier for translators and less prone to errors. The XML string files in Android Studio support XLIFF notations that are a standardized method to aid string localization.
By utilizing XLIFF notation in your XML string files you can do the following to help the translators:
Provide additional context for declared strings
Mark message parts that should not be translated
To use XLIFF in your Android string XML files you need to include the XLIFF 1.2 namespace:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
Here are a few examples of strings from the android localization documentation:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Example placeholder for a special unicode symbol -->
<string name="star_rating">Check out our 5
<xliff:g id="star">\u2605</xliff:g>
</string>
<!-- Example placeholder for a for a URL -->
<string name="app_homeurl">
Visit us at <xliff:g id="application_homepage">http://my/app/home.html</xliff:g>
</string>
<!-- Example placeholder for a name -->
<string name="prod_name">
Learn more at <xliff:g id="prod_gamegroup">Game Group</xliff:g>
</string>
<!-- Example placeholder for a literal -->
<string name="promo_message">
Please use the "<xliff:g id="promotion_code">ABCDEFG</xliff:g>” to get a discount.
</string>
</resources>
To access the Translations Editor in Android Studio, select Open Translations Editor from the context menu for your XML string file (ie. strings.xml) in your project tree (see below).
Convert your strings.xml to csv xml-to-csv
Import to Google Sheets
Translate using the formula =GOOGLETRANSLATE(B2, "auto", "de")
Generate output in another column using =CONCATENATE("<string name=",char(34),A2,char(34),">",C2,"</string>") where A2 is the resource_ID and C2 is the translated string
Copy the whole output column and paste inside the <resource>...</resource> tag
As Saad Mahmud answered, you can copy from the translation editor (ctrl+a ctrl+c) and then paste into a spreadsheet.
You can copy it back from a spreadsheet to the translation editor by only copying the "default value" and other languages columns, click on the topmost default value and paste (ctrl+v).
It also works with subsets (both subsets of rows and columns), as long as they are next to each other.
Be aware that empty cells in the spreadsheet will not blank out the translation in the editor, it will leave the current untouched.
Also be careful that you haven't added or removed any translation keys since the spreadsheet was created...
Export or copy to excel only supported in Windows PC.
Still not yet in MAC
As many others pointed out, you can't simply copy and paste translations from and into Translations Editor since Android Studio 3.2.
The simplest solution I found was saving the Excel file with translations as CSV file and then converting it to XML with regex and vice versa.
To "import" translations the steps:
Save xls/xlsx file with key in first column and translation in second column as CSV file (If you have file with non-ANSI caracters use Google sheets, because Excel doesn't support saving in CSV using utf-8)
Open csv file in text editor which supports "find and replace" with regex (eg. Notepad++)
Open "find and replace" and set regex search
Search ^([^,]*),(.*)$ and replace it with <string name="$1">$2</string>
Copy file to string resources file between tag
Fix possible mistakes
You can use similar method in reverse for "export". Use <string.+name="(.*)".*>(.*)</string> for finding and $1,$2 for replacing. But it only works if every string tag in in one line.
NOTE: If your res folder doesn't contians strings.xml then Android Studio won't show "Open Editor" in top right corner of the strings.xml file(Open the file). In my case all my string res files are named like strings_feature.xml
To copy/paste from Translations Editor use Android Studio 3.2 Version and below. It allows copy/paste of full column.
Is there a way to tag a strings resource folder with more than one language(values-en-es)?
My problem is that for Hebrew on some devices the language code "iw" and on others it is "he".
My current solution is to make two folders with the same content and only change their name
respectively.
I wonder if there is a more accurate way to do it?
Resource folder names can have multiple qualifiers but only one qualifier per type:
For example
values-en-rGB //Language + Region
is valid but
values-en-fr//Language + Language
is not valid, since it has multiple values for a single qualifier. So
values-iw-he
is not possible.
Source: Android Developers, Qualifier Name Rules.
However this doesn't mean you have to duplicate the files. Instead, you can create an Alias Resource.
Android Developers explains Alias Resouces like this:
Creating Alias Resources: When you have a resource that you'd like to use for more than one device configuration (but do not want to provide as a default resource), you do not need to put the same resource in more than one alternative resource directory. Instead, you can (in some cases) create an alternative resource that acts as an alias for a resource saved in your default resource directory.
For example, a String resource in one folder
<string name="app_name">My Awesome App</string>
can be referenced in another String resource in another folder as:
<string name="application_name">#string/app_name</string>
More about alias-resources on Android Developers.
You can make a File Link in eclipse, as described here.
So you have your values-iw/strings.xml with the real values and you make a File Link to that file in your values-he folder. This has the benefit that you do not have to edit 2 files, the linked 'file' gets updated automatically.
Good morning. Into my android application I have in assets directory a file changelog. I have creato also the directory assets-it and I have put into the file changelog in italian language but when I start the application it always display the file into assets directory also if the device language is set to italian. Why ?
That is the expected behavior. Resources in res/ can be localized in that manner, but the assets/ directory cannot.
Since it's just a changelog, I'd recommend storing it as a localized string resource in res/values-LOCALE/. If you really want localization of assets, you could manually recreate it by getting the current locale and loading, e.g. assets/changelog-en, vs. assets/changelog-it, but I think that would generally not be a good idea, and it certainly isn't necessary in your case.
Try this:
put both changelog files into assets folder:
Path is for example: assets/en/changelog_file and assets/it/changelog_file
enter this into your values/strings.xml:
<string name="changelog_file">file:///android_asset/en/changelog_file</string>
put in your values-it/strings.xml:
<string name="changelog_file">file:///android_asset/it/changelog_file</string>
Like this you can call the string from the code:
getResources().getString(R.string.changelog_file) and it will call the values-en or values-it according to device locale.
I have 2 different functionality to be implemented as part of a single application.
They have different screen flows and BL to be implemented but a single apk,so it is transparent to the end user.
I have 100 screens for each of the flow,so can I have custom folder names in the resources directory for easy maintenance and loose coupling.
eg: res
-layout
-layout_savings
-layout_checking
-drawable
-drawable_savings
-drawable_cheking
currently we have only the following structure
res
-layout
-layout-land
-drawable
-values
Will there be any problem while generating the R.java file.
Any help would be appreciated.
for what you need , i suggest you to use the assets directory instead of res. in assets dir you can sort your files anyway you like (dir name/filename) . You access them with AssetManager.
this require a little change in code but i think this is the only way if you want to sort your file like that , res folder doesn't allow custom directory names.
(Or of course you can store files in the sdcard)
This one puzzles me since my first android project. Consider multi-language string resources with 'en' as the default:
res/values/strings.xml <--- The default language 'en'
res/values-de/strings.xml <--- de
res/values-fr/strings.xml <--- fr
res/values-it/strings.xml <--- it
With that folder structure the Android Market entry for this app shows language support for "default, german, french and italian only". Yes, english is missing in that list.
Is it possible to "include" the complete default strings resource from the "values" folder in an additional "values-en" folder. And yes, I don't want to maintain that file in that new folder because everything is declared in the default string resource already.
Many thanks in advance.
Harald
I don't quite understand where the problem is. Just create a values-en directory and copy'n paste the XMLs from your default directory to the new one.
If you just want to have a kind of symbolic link to that default values directory so that when you change something inside the default directory the files i the linked directory represent the same changes then you just go to File -> New -> Folder select where the new folder should be created (in your case the res directory) and then hit on Advanced >> and there select Link to alternate location (Linked Folder) then browse to the directory you want to link to (in your case the values directory) and your done.
Now whenever you change something inside the values directory all your changes apply to the new linked directory.