├── .DS_Store
├── .idea
├── Retranslator.iml
├── inspectionProfiles
│ └── Project_Default.xml
├── misc.xml
├── modules.xml
├── vcs.xml
└── workspace.xml
├── LICENSE
├── README.md
└── android
├── .DS_Store
├── README.md
├── app
├── .DS_Store
└── src
│ ├── .DS_Store
│ └── main
│ ├── .DS_Store
│ └── res
│ ├── .DS_Store
│ └── values
│ └── strings.xml
├── readme
├── .DS_Store
└── scheme.jpg
├── retranslator.gradle
└── retranslator.py
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vacxe/RetranslatorPython/24c54e71426749e30d2102dee904b1d13781e77e/.DS_Store
--------------------------------------------------------------------------------
/.idea/Retranslator.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | buildTranslationFile
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | true
99 | DEFINITION_ORDER
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 | Python
116 |
117 |
118 |
119 |
120 | PyPep8Inspection
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 | 1526130764355
267 |
268 |
269 | 1526130764355
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 |
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Konstantin Aksenov
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.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Retranslator
2 | Translate your applications in one click
3 |
4 | [For Android](https://github.com/vacxe/Retranslator/tree/master/android)
5 |
--------------------------------------------------------------------------------
/android/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vacxe/RetranslatorPython/24c54e71426749e30d2102dee904b1d13781e77e/android/.DS_Store
--------------------------------------------------------------------------------
/android/README.md:
--------------------------------------------------------------------------------
1 | # Retranslator
2 | Translate your applications in one click
3 |
4 | []( https://android-arsenal.com/details/1/6945 )
5 |
6 |
7 | 
8 |
9 | **How to use**
10 |
11 | 1. Install **Python 3**
12 | 2. Copy **retranslator.py** and **retranslator.gradle** to your app directory
13 | 3. Add dependency `apply from: file("retranslator.gradle")` to `build.gradle`
14 |
15 | Now you can easy translate your app to many languages in single click and FREE!
16 | Just run in terminal:
17 | ```sh
18 | $ python3 retranslator.py
19 | ```
20 | Or execute gradle task
21 | ```sh
22 | $ ./gradlew generateTranslates
23 | ```
24 |
25 | If you want assistance me with this script don't hesitate create PRs!
26 | This script is a raw yet and has many lacks but free for use.
27 |
--------------------------------------------------------------------------------
/android/app/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vacxe/RetranslatorPython/24c54e71426749e30d2102dee904b1d13781e77e/android/app/.DS_Store
--------------------------------------------------------------------------------
/android/app/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vacxe/RetranslatorPython/24c54e71426749e30d2102dee904b1d13781e77e/android/app/src/.DS_Store
--------------------------------------------------------------------------------
/android/app/src/main/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vacxe/RetranslatorPython/24c54e71426749e30d2102dee904b1d13781e77e/android/app/src/main/.DS_Store
--------------------------------------------------------------------------------
/android/app/src/main/res/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vacxe/RetranslatorPython/24c54e71426749e30d2102dee904b1d13781e77e/android/app/src/main/res/.DS_Store
--------------------------------------------------------------------------------
/android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Test string
4 | Parametrized %d string
5 | Multi %s Parametrized %d string
6 |
7 |
8 | - Mercury
9 | - Venus
10 | - Earth
11 | - Mars
12 |
13 |
14 |
15 | - one
16 | - many
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/android/readme/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vacxe/RetranslatorPython/24c54e71426749e30d2102dee904b1d13781e77e/android/readme/.DS_Store
--------------------------------------------------------------------------------
/android/readme/scheme.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Vacxe/RetranslatorPython/24c54e71426749e30d2102dee904b1d13781e77e/android/readme/scheme.jpg
--------------------------------------------------------------------------------
/android/retranslator.gradle:
--------------------------------------------------------------------------------
1 | task generateTranslates(type: Exec){
2 | commandLine 'python3', 'Retranslator.py'
3 | }
4 |
--------------------------------------------------------------------------------
/android/retranslator.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import os
3 | from xml.etree import ElementTree
4 | from requests.utils import quote
5 | import requests
6 | import json
7 | import io
8 | import re
9 |
10 | supportedLocales = ['ru', 'es', 'de', 'zh', 'cz', 'nl', 'fr',
11 | 'it', 'ja', 'ko', 'pl', 'ar', 'bg', 'ca',
12 | 'hr', 'da', 'fi', 'el', 'iw', 'hi', 'hu',
13 | 'in', 'lv', 'lt', 'nb', 'pt', 'ro', 'sr',
14 | 'sk', 'sl', 'sv', 'tl', 'th', 'tr', 'uk',
15 | 'vi', 'en']
16 |
17 |
18 | def saveToFile(resdir, locale, xml):
19 | localizedValueDir = resdir + "/values-" + locale
20 | if not os.path.isdir(localizedValueDir):
21 | os.mkdir(localizedValueDir)
22 |
23 | localizedValuesFile = localizedValueDir + "/strings.xml"
24 |
25 | io.open(localizedValuesFile, "w", encoding='utf8').writelines(xml)
26 | print("Successful file creation for {} locale".format(locale))
27 |
28 | pass
29 |
30 |
31 | def translateString(query, targetLocale):
32 | shieldSymbols = re.findall('[%][bBhHsScCdoxXeEfgGaA]', query)
33 | queries = re.split('[%][bBhHsScCdoxXeEfgGaA]', query)
34 |
35 | translation = ""
36 | for query in queries:
37 | preSpace = query[0] == ' '
38 | endspace = query[len(query)-1] == ' '
39 | request = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl={}&dt=t&q={}" \
40 | .format(targetLocale, quote(query))
41 | if preSpace:
42 | translation += " "
43 |
44 | result = json.loads(requests.get(request).content)[0][0][0]
45 |
46 | if query[0].isupper():
47 | result = result[0].upper() + result[1:]
48 |
49 | translation += result
50 |
51 | if endspace:
52 | translation = translation + " "
53 |
54 | if len(shieldSymbols) > 0:
55 | translation += shieldSymbols.pop()
56 |
57 | return translation
58 | pass
59 |
60 |
61 | def translateTo(baseXML, locale):
62 | root = baseXML.getroot()
63 |
64 | for string in root.findall('string'):
65 | string.text = translateString(string.text, locale)
66 |
67 | for stringArray in root.findall('string-array'):
68 | for item in stringArray.findall('item'):
69 | item.text = translateString(item.text, locale)
70 |
71 | for stringArray in root.findall('plurals'):
72 | for item in stringArray.findall('item'):
73 | item.text = translateString(item.text, locale)
74 | return ElementTree.tostring(baseXML.getroot(), encoding='utf8').decode()
75 |
76 |
77 | def main(argv):
78 | print("Starting script...")
79 |
80 | projectDir = os.getcwd()
81 |
82 | print("Project dir is: " + projectDir)
83 |
84 | print("Try to find resources directory")
85 |
86 | resDir = projectDir + "/app/src/main/res"
87 |
88 | if os.path.isdir(resDir):
89 | print("Successful detection: " + resDir)
90 | else:
91 | while not os.path.isdir(resDir):
92 | print("Input res directory manually")
93 | resDir = input()
94 |
95 | templateStringXmlLocation = resDir + "/values/strings.xml"
96 | if os.path.exists(templateStringXmlLocation):
97 | print("Template string.xml detected")
98 | else:
99 | print("Could't find string.xml in default value directory")
100 | pass
101 |
102 | for locale in supportedLocales:
103 | translatedXML = translateTo(ElementTree.parse(templateStringXmlLocation), locale)
104 | saveToFile(resDir, locale, translatedXML)
105 | pass
106 |
107 |
108 | if __name__ == "__main__":
109 | main(sys.argv)
110 |
--------------------------------------------------------------------------------