File: update_translationdata.py

package info (click to toggle)
stellarium 24.3-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 911,396 kB
  • sloc: ansic: 317,377; cpp: 204,602; xml: 48,590; javascript: 26,348; python: 1,254; perl: 1,108; sh: 207; makefile: 190; pascal: 169
file content (42 lines) | stat: -rw-r--r-- 1,252 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python
#
# Updates the translationdata.js in the data/webroot folder using the current stellarium-remotecontrol.jst file

import re
import sys

def main():
	'''
	main expects 2 arguments:
	'''

	if len(sys.argv) < 3:
		print("usage: update_translationdata.py <stellarium-remotecontrol.jst> <translationdata.js>")
		print(sys.argv)
		return
	potfile = open(sys.argv[1], 'r')
	jsfile = open(sys.argv[2], 'w')
	
	p = re.compile(r'^msgid "([^"\\]*(?:\\.[^"\\]*)*)"$', re.MULTILINE)
	
	jsfile.write(
	"""
//This file is generated automatically by the stellarium-remotecontrol-update-translationdata target through update_translationdata.py from stellarium-remotecontrol.jst
//It contains all strings that can be translated through the StelTranslator in the JavaScript code by calling Main.tr()
//When this file is requested through the RemoteControl web server, the strings are translated using the current Stellarium app language

define({
	""")
	
	first = True
	
	for i in p.finditer(potfile.read()):
		if i.group(1):
			if not first:
				jsfile.write(',\n\t')
			jsfile.write('"'+i.group(1).replace('"','\\"')+'" : \'<?= tr("'+i.group(1).replace("'","\\'")+'")?>\'')
			first = False
	jsfile.write("\n});")

if __name__ == '__main__':
	main()