CSV example for translation service in Google Play Console - android

I built my first mobile game using Unity and localized it for a few known languages using localization tool created by my own. However, I decided to have a bit more languages and wanted to translate app using Google Play Console Translation Service. Unfortunately, I stuck with CSV file.
Does anyone have an example of CSV file that tool is asking for please? Or maybe any other solution?
Upload your strings.xml file to upload your user interface text if you use Android Studio for development. Upload a CSV file if you use any other tool for development. A CSV file must be encoded in UTF-8 format, and have string IDs and text to translate columns without a header row.

The following XML file worked for me. If the XML is invalid, they'll inform you right away when you upload it.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="inventory">
<item>Rewind</item>
<item>Switch</item>
<item>Mirage Filter</item>
<item>Holy Grenade</item>
</string-array>
<string name="app_name">Gravity</string>
<string name="rewind_desc">Got trapped in the space-time continuum? Rewind time back to the beginning and start over</string>
</resources>
FYI: resources/string-resource

I haven't heard back from translators yet, but by trial and error, this file format was at least accepted by the UI:
UTF-8
Comma as separator
No header row
Column1 stringID
Column2 OriginalText
No extra columns*
Fields quoted with double quotes
Like this:
arno#brick ~ $ cat polsk.csv
"Adminlagre","Adminlagre"
"AlleVerktøy","Alle verktøy"
"BortkomneVerktøy","- Bortkomne verktøy -"
"GarantienUtløpDen","Garantien utløp %0"
"ReservasjonerSenere","Reservasjoner senere"
"SkjulteVerktøy","- Skjulte verktøy -"
"ukjentleverandør","(ukjent leverandør)"
*It seems uploading a csv with 3 columns is accepted too (unsure what that results in), but 4 columns didn't work…

Related

How to set Default language other than english in Android?

I have a project by my client that has built successfully in his system but as he sent to me I am unable to compile it because of unicode characters (Latin characters) in default strings.xml under res. I believe its the default localizations file but its forcing me to convert it into English but not parsing Latin Characters into it.
e.g.
<string name="old_questions">Questões e soluções dos anos anteriores</string>
Check that the XML is in UTF-8 and has
<?xml ... encoding="UTF-8"?>
or defaulted
<?xml ... ?>
I tried your text in my studio , well it is working fine. You could also update question with your error , that would help understand it better.
Another workaround for small texts would be to simply escape it.
<string name="Example">Example character \u0026</string>
go to this website : https://unicode-table.com/en/#control-character and this could help you .
Make sure your string file is in the default values folder.
You can check the android developers link for better understanding.
To help you better please post the exact error you get while compiling the code.

How to import/export Android string resource to Excel for localization?

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.

Can I include a file of strings that would be autocompleting and crossplatform (iOS/Android)?

I'm not even sure what the vocabulary for this question is, but I'd like to have a file which is a list of strings which could be included as constants in Android and iOS.
I'm trying to find better vocab to describe this issue so comments are greatly appreciated too, thanks all.
Edit: For example, I'd like to have a file such as
color_names.txt
COLOR_NAME_BLUE "blue"
COLOR_NAME_RED "red"
COLOR_NAME_GREEN "green"
Which I can include in both an Android and an iOS project I have, in a way that in the code COLOR_NAME_BLUE is symbol checked, and if someone were to type COLOR_NAME_BLEU it would throw a compile error.
The actual file will be much larger and is something I want to be maintainable. I could put this in JSON but then I'd have to do the checking at run time, which isn't terrible I just am trying to figure out if there is a better way.
We also have iOS and Android apps that should be sharing strings.
You should use a python program (or some inferior scripting system) that takes your input file (checking it for errors) and outputs a Localizable.strings file for the iOS and strings.xml file for the Android.
So long as you have a good handle on your directory structure, you should be able to place both the Localizable.strings file and strings.xml file right where they need to be for your build.
For example, for a label pair like this:
PRIMARY_AGE_10 "Primary Age 10"
The label/string matchup is pretty obvious for the Android strings.xml:
<string name="PRIMARY_AGE_10">Primary Age 10</string>
The iOS Localizable.strings format is like this:
"PRIMARY_AGE_10" = "Primary Age 10";
Then when I want to use the label "Primary Age 10" instead of using an NSString, or #"Primary Age 10" i just make a call like this:
NSLocalizedString(#"PRIMARY_AGE_10", nil)
One other big advantage is if you need to localize, you can generate multiple Localizable.strings files and strings.xml files.

Update Android Strings.xml with Ruby script

I'd like to use a Ruby based script to go through the strings.xml file in Android to update certain values.
For example:
This is the original xml file
<resources>
<string name="accounts">accounts</string>
</resources>
I want it to become this after running the ruby script:
<resources>
<string name="accounts">my accounts</string>
</resources>
I'm completely new to ruby, but I was able to get it to read a xml file....just not sure how to update the values.
(In case you are wondering, I'm doing this so I can white-label my app and sell it to businesses. This will help speed up the process a lot.)
I found a way to do it.
require 'rubygems'
require 'nokogiri'
#opens the xml file
io = File.open('/path/to/my/strings.xml', 'r')
doc = Nokogiri::XML(io)
io.close
#this line looks for something like this: "<string name="nameOfStringAttribute">myString</string>"
doc.search("//string[#name='nameOfStringAttribute']").each do |string|
#this line updates the string value
string.content = "new Text -- IT WORKED!!!!"
#this section writes back to the original file
output = File.open('/path/to/my/strings.xml', "w")
output << doc
output.close
end
Be warned, if you are using the resources from the strings.xml file from the android code, using the R.string class, then modifying the XML externally will not work.
The R.string class is created when you compile your application, so if you modify the XML file after compilation, the changes will not take effect in your application.
Super helpful! For posterity's sake...I opted for:
doc = Nokogiri::XML(File.open('path_to/strings.xml')))
doc.search("//string[#name='my_string_attribute']").first.content = "my new string value"
File.open('path_to/strings.xml', 'w') { |f| f.print(doc.to_xml) }
That works well when your string key (name) is unique (which Android Studio enforces so you can trust that they will be). You can throw as many string edits in the middle there and then save the changes without worrying about messing up any other values.

Android Strings

I wrote a big app with thousands of string in the code.... very bad idea, because now I want to translate each string.... big problem.
Copying all strings to the strings.xml takes a long time.
Eclipse has an option to take all selected strings and put them into messages.properties.
Does this work similiar like strings.xml? When, why all people use strings.xml.
Or should is use eclipse to seperate each string and than I should copy them to string.xml?
All people are using strings.xml because this is the normal way to do it on Android. You don't have to manage the load of the strings, to call any locale function in your script.
You can see the documentation here : http://developer.android.com/guide/topics/resources/index.html
BTW, you can easily transform your eclipse generated file to an strings.xml file after the extraction.
In Eclipse you can use the shortcut keys Alt + Shift A, S to extract an inline string in to the strings.xml file via a popup dialog - might be a bit easier than doing it by hand. And as the others say, yes you should ALWAYS use the strings.xml file so that you only have to look in one place when you want to change a string, instead of having to search through all your code.

Categories

Resources