I’m using Google translate to translate strings.xml files to other languages from English. But translating more than 1000 lines one by one takes too much time. Is there an easy way or code to do this?
How do you translate your xml contents to other languages?
from:
<resources> <string name='title_home'>Home</string> <string name='title_dashboard'>Dashboard</string> <string name='title_notifications'>Notifications</string> <string name='title_information'>Information</string> </resources>
to:
<resources> <string name='title_home'>Zuhause</string> <string name='title_dashboard'>Instrumententafel</string> <string name='title_notifications'>Benachrichtigungen</string> <string name='title_information'>Information</string> </resources>
Advertisement
Answer
The input text can be plain text or HTML. Cloud Translation API does not support input text using other markup languages such as XML.
What you can do is use a parser such as SimpleXML
(Basic SimpleXML usage) or xml_parser
to parse your files (More parsers).
Then call the Translation API with a batch of words.
The recommended maximum length for each request is 5K characters (code points). However, the more characters that you include, the higher the response latency. For Cloud Translation – Advanced, the maximum number of code points for a single request is 30K. Cloud Translation – Basic has a maximum request size of 100K bytes (Content quotas).