summaryrefslogtreecommitdiff
path: root/web/backupcopy
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2019-02-09 11:10:09 -0200
committerJesusaves <cpntb1@ymail.com>2019-02-09 11:10:09 -0200
commitdfea40876271290acb6a50a55f88a8e6b50db1fd (patch)
tree0aa14e0de4bc148d791b7487a32569ce97f22abc /web/backupcopy
parent939e2913eb5ede38c4f9e3170cc44abc8d2618f8 (diff)
downloadtools-dfea40876271290acb6a50a55f88a8e6b50db1fd.tar.gz
tools-dfea40876271290acb6a50a55f88a8e6b50db1fd.tar.bz2
tools-dfea40876271290acb6a50a55f88a8e6b50db1fd.tar.xz
tools-dfea40876271290acb6a50a55f88a8e6b50db1fd.zip
Update
Diffstat (limited to 'web/backupcopy')
-rwxr-xr-xweb/backupcopy129
1 files changed, 129 insertions, 0 deletions
diff --git a/web/backupcopy b/web/backupcopy
new file mode 100755
index 0000000..81601b0
--- /dev/null
+++ b/web/backupcopy
@@ -0,0 +1,129 @@
+#! /usr/bin/env python2.7
+# -*- coding: utf8 -*-
+#
+# Copyright (C) 2018 TMW-2
+# Author: Jesusalva
+
+import os
+
+defaultLang = "en"
+rootPath = "../../web/"
+
+langs=[]
+files={}
+originals={}
+
+# Populates the basic arrays
+def populate():
+ # Populate langs
+ o=open("langs.txt", "r")
+ for i in o:
+ langs.append(i.replace('\n',''))
+ o.close()
+
+ # Populate files
+ for i in os.listdir(rootPath):
+ if i.endswith(".php.en"):
+ print "Valid file: "+str(i)
+ files[i]={}
+ for x in langs:
+ files[i][x]={}
+
+ print str(files)
+# Write po files
+def writePoFile(nf,lg):
+ a=open("po/"+lg+".po", "a")
+ f=open(rootPath+nf, "r")
+
+ for line in f:
+ a.write("#, no-c-format\n")
+ a.write('msgid "%s"\n' % line.replace('\n', ''))
+ try:
+ if files[nf][lg][line] != line:
+ a.write('msgstr "%s"\n' % files[nf][lg][line].replace('\n',''))
+ else:
+ a.write('msgstr "%s"\n' % "")
+ except KeyError:
+ a.write('msgstr "%s"\n' % "")
+
+ a.write('\n')
+
+ a.close()
+
+# Creates/Loads stuff
+def genreadPoFile():
+ for a in langs:
+ print("Reading translations for "+a)
+ for i in files:
+ readPoFile(i,a)
+
+def generatePoFiles():
+ for a in langs:
+ print("Updating po file for "+a)
+ xrv=open("po/"+a+".po", "w")
+ # Print header
+ xrv.write('\
+# Copyright (C) 2018 TMW2\n\
+#\n\
+\n\
+msgid ""\n\
+msgstr ""\n\
+"Project-Id-Version: TMW2\\n"\n\
+"MIME-Version: 1.0\\n"\n\
+"Content-Type: text/plain; charset=UTF-8\\n"\n\
+"Content-Transfer-Encoding: 8bit\\n"\n\
+\n\
+')
+ xrv.close()
+
+ for i in files:
+ writePoFile(i,a)
+
+def generateLocal():
+ for a in langs:
+ print("generating local file for "+a)
+ for i in files:
+ writeLocal(i,a)
+
+# Reads Po Files
+def readPoFile(nf, lg):
+ try:
+ a=open("po/"+lg+".po", "r")
+ except:
+ a=open("po/"+lg+".po", "w")
+ a.close()
+ a=open("po/"+lg+".po", "r")
+
+ ctx=""
+ for line in a:
+ if "msgid " in line:
+ ctx=line.replace('\n','')
+ if "msgstr " in line and ctx != "":
+ if line != 'msgstr ""\n':
+ files[nf][lg][ctx]=line.replace('\n', '')
+ else:
+ files[nf][lg][ctx]=ctx
+ ctx=""
+ a.close()
+
+def writeLocal(nf, lg):
+ a=open(rootPath+nf[:-2]+lg, 'w')
+ b=open(rootPath+nf, 'r')
+
+ for line in b:
+ try:
+ a.write(files[nf][lg][line])
+ except KeyError:
+ a.write(line)
+
+ b.close()
+ a.close()
+
+# Mainframe: populate arrays
+populate()
+
+# Mainframe: handle PO files
+genreadPoFile()
+generatePoFiles()
+generateLocal()
+