Skip to content

Commit f9ed764

Browse files
author
osfunapps
committed
Initial commit
0 parents  commit f9ed764

File tree

9 files changed

+203
-0
lines changed

9 files changed

+203
-0
lines changed

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 YOUR NAME
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# file GENERATED by distutils, do NOT edit
2+
setup.cfg
3+
setup.py
4+
os_android_strings_extractor/StringsExtractor.py
5+
os_android_strings_extractor/StringsExtractorBp.py
6+
os_android_strings_extractor/__init__.py
7+
os_android_strings_extractor/example_img.png

README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Introduction
2+
------------
3+
This project's aim is to help with the translation of an Android app.
4+
It will extract the strings.xml file of an app to a nice readable xlsx file, which can be sent to translators to work on.
5+
6+
If, after the translators will finish translating the file, you also interested in converting the translated file back to strings.xml file,
7+
use the complementary library.
8+
9+
10+
## Installation
11+
Install via pip:
12+
13+
pip install os_android_strings_extractor
14+
15+
## Usage
16+
17+
Say you have this *strings.xml* file:
18+
19+
<resources>
20+
<string name="app_name">Memorizer</string>
21+
<string name="capital">Capital</string>
22+
<string name="country">Country</string>
23+
<string name="add_tab">Add List</string>
24+
<string name="action_settings">Settings</string>
25+
<string name="settings">Lists Settings</string>
26+
<string name="save">Save</string>
27+
<string name="delete">DELETE</string>
28+
<string name="entries">%1$s Entries</string>
29+
<string name="entry">%1$s Entry</string>
30+
<string name="from_definition_hint">Like: Date In History </string>
31+
<string name="to_definition_hint">To: Event</string>
32+
<string name="from_translation_hint">Like: Spanish</string>
33+
<string name="to_translation_hint">To: Hebrew</string>
34+
<string name="go">Go</string>
35+
<string name="entries_count">total entries: %1$s</string>
36+
<string name="entries_hard_count">hard entries: %1$s</string>
37+
<string name="tabs_list_title" translatable="false">Lists</string>
38+
</resources>
39+
40+
Convert it to a readable excel file:
41+
42+
import os_android_strings_extractor.StringsExtractor as se
43+
44+
se.run('/path/to/android/project',
45+
'/output/path',
46+
src_language='English',
47+
output_languages_arr=['French', 'German', 'Hindi'])
48+
49+
And you will get the output:
50+
51+
![Alt text](os_android_strings_extractor/example_img.png?raw=true "Title")
52+
(notice the worksheets at the bottom -> 'French', 'German', 'Hindi')
53+
54+
55+
## Licence
56+
MIT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os_android_strings_extractor.StringsExtractorBp as bp
2+
3+
4+
##################################################################################
5+
#
6+
# this module meant to turn the strings.xml file in an android project to a human
7+
# readable xls file, ready to be translated to a specific language or bunch of
8+
# languages
9+
#
10+
##################################################################################
11+
12+
def run(project_path, output_path, src_language, output_languages_arr):
13+
strings_dict = bp.build_strings_dict(project_path)
14+
bp.dict_to_xlsx(project_path, strings_dict, output_path, src_language, output_languages_arr)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import os_tools.XmlFileHandler as xh
2+
import os_tools.FileHandler as fh
3+
4+
5+
##################################################################################
6+
#
7+
# just the StringsExtractor boiler plate script
8+
#
9+
##################################################################################
10+
11+
12+
# will return a dictionary containing all of the strings in the xml file by "id": "value"
13+
def build_strings_dict(project_path):
14+
string_nodes = get_relevant_string_nodes(project_path)
15+
return xh.nodes_to_dict(string_nodes, 'name')
16+
17+
18+
def get_relevant_string_nodes(project_path):
19+
strings_path = project_path + '/app/src/main/res/values/strings.xml'
20+
xml = xh.read_xml_file(strings_path)
21+
return xh.get_nodes_from_xml_without_att(xml, 'string', 'translatable')
22+
23+
24+
# will turn the strings dictionary to a good looking xls file
25+
def dict_to_xlsx(project_path, strings_dict, output_path, src_language, languages_arr):
26+
import xlsxwriter
27+
28+
# Create an new Excel file and add a worksheet.
29+
project_name = fh.get_dir_name(project_path)
30+
workbook = xlsxwriter.Workbook(output_path + '/' + project_name + '-Translations.xlsx')
31+
32+
big_red_format = workbook.add_format()
33+
title_format = workbook.add_format()
34+
content_format = workbook.add_format()
35+
border_format = workbook.add_format()
36+
37+
big_red_format.set_font_color('red')
38+
big_red_format.set_font_size(16)
39+
40+
title_format.set_font_size(22)
41+
42+
content_format.set_font_size(12)
43+
content_format.set_font('Arial')
44+
big_red_format.set_align('center')
45+
46+
border_format.set_top()
47+
48+
# set the border
49+
50+
for language in languages_arr:
51+
worksheet = workbook.add_worksheet(language)
52+
53+
# widen all of the columns used
54+
worksheet.set_column('A:A', 50, cell_format=content_format)
55+
worksheet.set_column('B:B', 50, cell_format=content_format)
56+
worksheet.set_column('C:C', 50, cell_format=content_format)
57+
worksheet.set_column('F:F', 50, cell_format=content_format)
58+
59+
# set headers
60+
worksheet.write('A1', 'Translation Project', title_format)
61+
worksheet.write('A3', src_language, big_red_format)
62+
worksheet.write('B3', language, big_red_format)
63+
worksheet.write('F3', 'Code (DO NOT CHANGE)', big_red_format)
64+
65+
# set strings
66+
keys_list = list(strings_dict.keys())
67+
for i in range(len(strings_dict)):
68+
key = keys_list[i]
69+
worksheet.write('A' + str(i + 4), strings_dict[key])
70+
worksheet.write('F' + str(i + 4), key)
71+
72+
workbook.close()
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import os_android_strings_extractor.StringsExtractor
251 KB
Loading

setup.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Inside of setup.cfg
2+
# [metadata]
3+
# description-file = README.md

setup.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from distutils.core import setup
2+
3+
setup(
4+
name='os_android_strings_extractor',
5+
packages=['os_android_strings_extractor'],
6+
package_data={'os_android_strings_extractor': ['example_img.png']},
7+
version='1.0', # Start with a small number and increase it with every change you make
8+
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
9+
description='This module will extract an Android strings.xml file to a nice excel (xlsx) file, in order to prepare it for translation', # Give a short description about your library
10+
author='Oz Shabat', # Type in your name
11+
author_email='[email protected]', # Type in your E-Mail
12+
url='https://github.com/osfunapps/os_android_strings_extractor-py', # Provide either the link to your github or to your website
13+
keywords=['python', 'osfunapps', 'android', 'strings', 'xml', 'automation', 'translate' 'tools', 'utils', 'excel', 'xls', 'xlsx'], # Keywords that define your package best
14+
install_requires=['os_tools', 'xlsxwriter'],
15+
classifiers=[
16+
'Development Status :: 5 - Production/Stable', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
17+
18+
'Intended Audience :: Developers', # Define that your audience are developers
19+
'Topic :: Software Development :: Build Tools',
20+
21+
'License :: OSI Approved :: MIT License', # Again, pick a license
22+
23+
'Programming Language :: Python :: 3', # Specify which pyhton versions that you want to support
24+
'Programming Language :: Python :: 3.4',
25+
'Programming Language :: Python :: 3.5',
26+
'Programming Language :: Python :: 3.6',
27+
],
28+
)
29+

0 commit comments

Comments
 (0)