forked from spacecowboy/NotePad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listlang.py
executable file
·50 lines (39 loc) · 1.18 KB
/
listlang.py
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
#!/usr/bin/env python
'''
Lists the values directories for languages. Then
inserts them in arrays.xml
'''
from __future__ import print_function
import os, re, fileinput
#Array file
arrayfile = './res/values/arrays.xml'
# List dirs in res dir
dirs = os.listdir('./res/')
langs = []
for dir in dirs:
if not dir.startswith('values-'):
continue
m = re.match('^values\-([a-z]{2})(-r([A-Z]{2}))?$', dir)
if m is not None:
# Language iso code
isocode = m.group(1)
if m.group(3) is not None:
# Region code
isocode += "_" + m.group(3)
langs.append(isocode)
#for isocode in sorted(langs):
# print(isocode)
replacing = False
for line in fileinput.FileInput(arrayfile, inplace=1):
if not replacing:
print(line, end='')
if 'name="translated_langs"' in line:
replacing = True
#Print list of languages
#Locale default is empty string
#print('{}<item></item>'.format(' '*8))
for isocode in sorted(langs):
print('{}<item>{}</item>'.format(' '*8, isocode))
if replacing and '</string-array>' in line:
replacing = False
print(line, end='')