Post Reply

[DEV][TOOL][PROJECT] Android APK Translation [CMD + GUI]

OP Aternus

22nd May 2012, 03:41 AM   |  #1  
Aternus's Avatar
OP Senior Member
Thanks Meter: 486
 
387 posts
Join Date:Joined: Feb 2010
Donate to Me
More
Android APK Translation - CMD Line Tool

CMD Line - The Idea

Files involved: "strings.xml", "arrays.xml", "plurals.xml"

translated files:
strings.xml - http://pastebin.com/embed_iframe.php?i=5u40nHZP
arrays.xml - http://pastebin.com/embed_iframe.php?i=93v9vZUk
plurals.xml - http://pastebin.com/embed_iframe.php?i=GwBuFdmW

original files:
strings.xml - http://pastebin.com/embed_iframe.php?i=r2W4yYvh
arrays.xml - http://pastebin.com/embed_iframe.php?i=Lfff9Pur
plurals.xml - http://pastebin.com/embed_iframe.php?i=eSe8yf4S

1) Get translated files from a translator.

2) Sort & delete tags/nodes with duplicate attributes from the translated files.

3) Get original files from the ROM.

4) Sort & delete tags/nodes with duplicate attributes from the original files.

5) Merge translated files with original files

(Optional) Discard all XML tags/nodes with attributes that doesn't exist in the original XML

Suggested Tool Syntax
Code:
apktrans [OPTS] --i rom/strings.xml --t translated/strings.xml --o merged/strings.xml

OPTS:
-s - sort xml nodes
-d - delete duplicate xml nodes
-m - discard xml nodes not present in the source xml
Notes
  • The node is considered a duplicate if there is another node with the same attributes, no matter how many children it have inside of it.
  • The node with more children overwrites the node with less.
Needed Tool Features
  • sort xml tags by attribute name
  • delete duplicate xml tags by attribute name
  • preserve node properties - ability to work on any kind of tags (string & arrays - children) - see example
  • should work with UTF-8




Android APK Translation - GUI Tool

GUI - The Idea

Original idea and source code: APK Translation Wizard

For the purpose of explanation, its assumed we want to translate from English source files to Vietnamese without a region code


File Structure

Code:
/
/apks-compiled         - holds the apk files after encoding
/apks-frameworks      - holds the framework files
/apks-source            - holds the apk files for decoding/translation
/apks-translation       - holds the apk files after encoding (with the translated files)
/core                      - holds the application files (binaries, scripts, etc...)
/i18n-crowdin           - holds the translation files from the MIUI translation project
/i18n-other              - holds the other translation files (drawable, raw, xml, etc...)

Decode Window - APK Decoding

Selectbox: Select which APK files you want to decode - apk files should be present inside the "/apks-source" directory

Selectbox: Select which framework file to use for APK decoding - framework file should be present inside "/apks-frameworks" directory

Button: Decode APK files - using APKTool

Config Window - Tool Configuration

Button: Load original files - /res/values/strings.xml, /res/values/arrays.xml, /res/values/plurals.xml

Seletbox: Select destination locale - required - vi

Selectbox: Select destination region - optional - rVI

Button: Start Translation Process - set up /res/values-vi (and /res/values-vi-rVI if selected)

Translation - strings.xml

View: APK_NAME | ATTRIBUTE_NAME | ORIGINAL STRING | TRANSLATED STRING

APK_NAME - name of the decoded apk
ATTRIBUTE_NAME - name of the tag's attribute we are translating
ORIGINAL STRING - the original string for translation
TRANSLATED STRING - the translated string*

*as appears in the /res/values-vi/strings.xml file OR /res/values-vi-rVI/strings.xml file OR empty if none

Button: Sort all tags - sorts all tags by attribute name

Button: Delete duplicate tags - delete tags with duplicate attribute name

Button: Import an XML patch - imports an XML file and merges the tags that have the same attributes

Button: Commit Translation - writes the translated xml file - /res/values-vi(-rVI)/strings.xml

Description
  • The user will be able to edit the TRANSLATED STRING column only.
  • The use will be able to edit tags which present only inside the source xml file (the decoded file) so to avoid adding tags which doesn't exist in the application we are translating.
  • If a tag is present in the XML patch but is missing in the source file; it will be discarded.

Translation - arrays.xml

View: APK_NAME | ATTRIBUTE_NODE_NAME | ORIGINAL STRINGS LIST | TRANSLATED STRINGS LIST

APK_NAME - name of the decoded apk
ATTRIBUTE_NODE_NAME - name of the tag/node's attribute we are translating
ORIGINAL STRINGS LIST - a list of the node's children which includes the original strings for translation
TRANSLATED STRINGS LIST - a list of the node's children which includes the translated strings*

*as appears in the /res/values-vi/arrays.xml file OR /res/values-vi-rVI/arrays.xml file OR empty if none

Button: Sort all nodes - sorts all nodes by attribute name - should NOT sort the children b/c their order is important!

Button: Delete duplicate nodes - delete nodes with duplicate attribute names

Button: Import an XML patch - imports an XML file and merges the nodes that have the same attributes

Button: Commit Translation - writes the translated xml file - /res/values-vi(-rVI)/arrays.xml

Description
  • ORIGINAL STRINGS LIST & TRANSLATED STRINGS LIST column will have a list of all properties (children) which belong to a specific ATTRIBUTE_NODE_NAME.
  • The user will be able to edit the TRANSLATED STRINGS LIST column only.
  • The user will be able to edit nodes which present only inside the source xml file (the decoded file) so to avoid adding nodes which doesn't exist in the application we are translating.
  • If a node is present in the XML patch but is missing in the source file; it will be discarded.
  • If a node in the XML patch includes more children then a node in the source file; All additional children will be discarded.

Translation - plurals.xml

View: APK_NAME | PLURAL_ATTRIBUTE_NODE_NAME | ATTRIBUTE_NAME | ORIGINAL STRING | TRANSLATED STRING

APK_NAME - name of the decoded apk
PLURAL_ATTRIBUTE_NODE_NAME - name of the plural's node attribute we are translating
ATTRIBUTE_NAME - name of the plural's node tag attribute we are translating
ORIGINAL STRING - original string for translation
TRANSLATED STRING - translated string*

*as appears in the /res/values-vi/plurals.xml file OR /res/values-vi-rVI/plurals.xml file OR empty if none

Button: Sort all plural nodes - sorts all nodes by attribute name - should NOT sort the children b/c their order is important!

Button: Delete duplicate plural nodes - delete nodes with duplicate attribute names

Button: Import an XML patch - imports an XML file and merges the nodes that have the same attributes

Button: Commit Translation - writes the translated xml file - /res/values-vi(-rVI)/plurals.xml

Description
  • The user will be able to edit the TRANSLATED STRING column only.
  • The user will be able to edit nodes which present only inside the source xml file (the decoded file) so to avoid adding nodes which doesn't exist in the application we are translating.
  • If a node is present in the XML patch but is missing in the source file; it will be discarded.
  • If a node in the XML patch includes more children then a node in the source file; All additional children will be discarded.

Encode Window - APK Encoding

Selectbox: Select which APK files you want to encode - will be taken from the "/projects" directory

Selectbox: Select which framework file to use for APK encoding - framework file should be present inside "/apks-frameworks" directory

Checkbox: Replace "Resources.arsc" - after compilation, the compiled APK will be unzipped, the Resources.arsc file will be taken out and put inside the original APK*.

Button: Encode APK files - using APKTool

*this is to avoid signature issues within the APK files.




Android Localization - Useful Resources

Android SDK Guide on Localization
http://developer.android.com/guide/t...alization.html
http://developer.android.com/guide/t...html#BestMatch
http://developer.android.com/guide/t...es.html#table2

Mobile Country Codes (MMC)
http://en.wikipedia.org/wiki/List_of..._country_codes

List of ISO-639-1 Codes (Country Codes)
http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

List of ISO-3166-1-alpha-2 Codes (Region Codes)
http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

Examples of Usage
Note: trimmed due to forum length limits, notice that the xml tags are not sorted.

translated strings.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
  <string name="common_minutes_ago">%s minutter siden</string>
  <string name="common_hours_ago">%s timer siden</string>
  <string name="common_days_ago">%s dage siden</string>
  <string name="app_name">Browser</string>
</resources>
original strings.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <string name="common_minutes_ago">%s minutes ago</string>
    <string name="common_hours_ago">%s hours ago</string>
    <string name="common_days_ago">%s days ago</string>
    <string name="app_name">Browser</string>
    <string name="app_settings">Settings</string>
    <string name="urltitlebar_gotourl">GO</string>
    <string name="urltitlebar_hint">Search or type in a URL</string>
    <string name="search_description">Bookmarks, History, Google suggestions</string>
</resources>
final strings.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
  <string name="common_minutes_ago">%s minutter siden</string>
  <string name="common_hours_ago">%s timer siden</string>
  <string name="common_days_ago">%s dage siden</string>
  <string name="app_name">Browser</string>
  <string name="app_settings">Settings</string>
  <string name="urltitlebar_gotourl">GO</string>
  <string name="urltitlebar_hint">Search or type in a URL</string>
  <string name="search_description">Bookmarks, History, Google suggestions</string>
</resources>
Last edited by Aternus; 23rd May 2012 at 10:14 AM.
The Following 4 Users Say Thank You to Aternus For This Useful Post: [ View ]
22nd May 2012, 08:55 AM   |  #2  
SifJar's Avatar
Senior Member
Thanks Meter: 245
 
587 posts
Join Date:Joined: Jul 2009
Duplicate lines are always right after each other, right? I could throw together a script to delete the second line I think. I don't have time right now, but if no one has posted anything by this afternoon, I'll give it a shot for you.
22nd May 2012, 09:27 AM   |  #3  
zach.antre's Avatar
Senior Member
Flag Athens
Thanks Meter: 69
 
242 posts
Join Date:Joined: Mar 2010
More
Quote:
Originally Posted by SifJar

Duplicate lines are always right after each other, right? I could throw together a script to delete the second line I think. I don't have time right now, but if no one has posted anything by this afternoon, I'll give it a shot for you.

there is no need to create a script.
There are many text editors that can do that.

e.g. Notepad++

line 64-65

Code:
  <string name="car_mode_disable_notification_message">برای خروج از حالت خودرو انتخاب کنید.</string>
  <string name="car_mode_disable_notification_message">برای خروج از حالت خودرو انتخاب کنید</string>
in the above example there is a dot (.) more in 1st line, and for that reason a program will not recognise it as duplicate.
In notepad++ you can check for specific content, mark the duplicated and then delete the marked lines.
We need to delete a duplicate line of "<string name="car_mode_disable_notification_message">" so we make it in notepad++ to search for duplicates that have this pattern
Code:
<string name="   ">
and delete duplicate lines.

I am sure that this can be done because i have used it in the past (long ago).
I'll search some more to remember and post the way to do it.
22nd May 2012, 11:13 AM   |  #4  
Aternus's Avatar
OP Senior Member
Thanks Meter: 486
 
387 posts
Join Date:Joined: Feb 2010
Donate to Me
More
Merged with Post#1
Last edited by Aternus; 22nd May 2012 at 07:45 PM.
22nd May 2012, 11:41 AM   |  #5  
Aternus's Avatar
OP Senior Member
Thanks Meter: 486
 
387 posts
Join Date:Joined: Feb 2010
Donate to Me
More
Merged with Post#1
Last edited by Aternus; 22nd May 2012 at 07:45 PM.
22nd May 2012, 01:29 PM   |  #6  
Aternus's Avatar
OP Senior Member
Thanks Meter: 486
 
387 posts
Join Date:Joined: Feb 2010
Donate to Me
More
Exclamation Useful Resources
Merged with Post#1
Last edited by Aternus; 22nd May 2012 at 07:46 PM.
22nd May 2012, 03:04 PM   |  #7  
SifJar's Avatar
Senior Member
Thanks Meter: 245
 
587 posts
Join Date:Joined: Jul 2009
Well, I decided to go ahead and throw together this:

deldupe.exe

Basically, pass the XML to deldupe.exe (drag the XML and drop it on EXE, or run it from command line like this: "deldupe.exe example.xml"). It'll delete all the lines with the same "name" attribute. It'll leave the first one. I tested it on the example XML you posted in your first post, got this as a result:

test.xml

Seems about right I think.

Dunno if you actually need this or not anymore, but it only took a few minutes to make, so I figured I may as well.

EDIT: It's also probably easier than messing with a text editor's settings. Just drag and drop, job done.
Last edited by SifJar; 22nd May 2012 at 04:29 PM.
The Following User Says Thank You to SifJar For This Useful Post: [ View ]
22nd May 2012, 04:34 PM   |  #8  
Aternus's Avatar
OP Senior Member
Thanks Meter: 486
 
387 posts
Join Date:Joined: Feb 2010
Donate to Me
More
Cool
Merged with Post#1
Last edited by Aternus; 22nd May 2012 at 07:46 PM.
22nd May 2012, 05:07 PM   |  #9  
SifJar's Avatar
Senior Member
Thanks Meter: 245
 
587 posts
Join Date:Joined: Jul 2009
I have to be honest, I'm not really sure what you mean. In the first file you linked, in reference to XML nodes, I can't see any duplication...

And the second part, I'm not really sure what you want. I understand you want to delete the duplicate lines from each version of each file. But I don't get the bit about merging. What is the final result you want to achieve?

I'm probably just being stupid here, but I can't really work out what it is you want the tool to do. If you could try and explain it in another way or something, I might be able to help.

EDIT: With the nodes stuff: Do you mean deleting a whole array when it is duplicated? If so, I think that could be trickier, but I could try it. I won't until I get confirmation though, don't want to waste time on something that isn't right

Also, seeing as they couldn't be sorted, it would probably be a longer process.
Last edited by SifJar; 22nd May 2012 at 05:13 PM.
22nd May 2012, 05:17 PM   |  #10  
Aternus's Avatar
OP Senior Member
Thanks Meter: 486
 
387 posts
Join Date:Joined: Feb 2010
Donate to Me
More
Merged with Post#1
Last edited by Aternus; 22nd May 2012 at 07:50 PM.

Post Reply Subscribe to Thread

Tags
android, apk, translate, xml
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Android Software Development by ThreadRank