|
@@ -190,64 +190,114 @@ class LangAreaView(TemplateView):
|
|
|
|
|
|
def do_download_avss(self, id):
|
|
def do_download_avss(self, id):
|
|
content = ''
|
|
content = ''
|
|
- result = {}
|
|
|
|
- lkc_qs = LangKeyModel.objects.filter(langvalmodel__la__id=id, type__in=(1, 2)).values('word_key', 'langkeyclassmodel__clazz__name', 'langvalmodel__word_val', 'langlocationmodel__filename', 'langlocationmodel__line')
|
|
|
|
- if lkc_qs.exists():
|
|
|
|
- for lkc in lkc_qs:
|
|
|
|
- # print(lkc)
|
|
|
|
- name = lkc['langkeyclassmodel__clazz__name']
|
|
|
|
- hasClass = result.__contains__(name)
|
|
|
|
- if hasClass is False:
|
|
|
|
- result[name] = {}
|
|
|
|
-
|
|
|
|
- source = lkc['word_key']
|
|
|
|
- if not result[name].__contains__(source):
|
|
|
|
- result[name][source] = {}
|
|
|
|
- message = result[name][source]
|
|
|
|
-
|
|
|
|
- message['source'] = source
|
|
|
|
- message['translation'] = lkc['langvalmodel__word_val']
|
|
|
|
-
|
|
|
|
- # location
|
|
|
|
- locations = []
|
|
|
|
- locations.append({'filename': lkc['langlocationmodel__filename'], 'line': lkc['langlocationmodel__line']})
|
|
|
|
- message['locations'] = locations
|
|
|
|
- print(result)
|
|
|
|
-
|
|
|
|
- content += '<TS>\n'
|
|
|
|
- keys = result.keys()
|
|
|
|
|
|
+ en_result = self.get_area_language(20)
|
|
|
|
+ target_result = self.get_area_language(id)
|
|
|
|
+ if target_result:
|
|
|
|
+ content += '<TS version=\"2.1\" language=\"' + self.get_avss_language(int(id)) + '\">\n'
|
|
|
|
+ # keys = result.keys()
|
|
|
|
+ keys = en_result.keys()
|
|
for key in keys:
|
|
for key in keys:
|
|
content += '<context>\n<name>'
|
|
content += '<context>\n<name>'
|
|
content += key
|
|
content += key
|
|
content += '</name>\n'
|
|
content += '</name>\n'
|
|
|
|
|
|
- messages = result[key]
|
|
|
|
- messageKeys = messages.keys()
|
|
|
|
|
|
+ messages = None
|
|
|
|
+ if target_result.__contains__(key):
|
|
|
|
+ messages = target_result[key]
|
|
|
|
+ else:
|
|
|
|
+ messages = en_result[key]
|
|
|
|
+ messageKeys = en_result[key].keys()
|
|
for messageKey in messageKeys:
|
|
for messageKey in messageKeys:
|
|
- message = messages[messageKey]
|
|
|
|
|
|
+ message = None
|
|
|
|
+ if messages.__contains__(messageKey):
|
|
|
|
+ message = messages[messageKey]
|
|
|
|
+ else:
|
|
|
|
+ message = en_result[key][messageKey]
|
|
|
|
+
|
|
|
|
+ # message = messages[messageKey]
|
|
content += '<message>\n'
|
|
content += '<message>\n'
|
|
content += '<source>'
|
|
content += '<source>'
|
|
content += message['source']
|
|
content += message['source']
|
|
content += '</source>\n'
|
|
content += '</source>\n'
|
|
content += '<translation>'
|
|
content += '<translation>'
|
|
- content += message['translation']
|
|
|
|
|
|
+ translation = message['translation']
|
|
|
|
+ # if translation is None or translation == '':
|
|
|
|
+ # content += '23333'
|
|
|
|
+ # else:
|
|
|
|
+ content += translation
|
|
content += '</translation>\n'
|
|
content += '</translation>\n'
|
|
-
|
|
|
|
locations = message['locations']
|
|
locations = message['locations']
|
|
print(message)
|
|
print(message)
|
|
for location in locations:
|
|
for location in locations:
|
|
if location['filename'] != '':
|
|
if location['filename'] != '':
|
|
- content += '<location filename=\"' + location['filename'] + '\" line=\"' + str(location['line']) + '\"\n/>'
|
|
|
|
|
|
+ content += '<location filename=\"' + location['filename'] + '\" line=\"' + str(location['line']) + '\"/>\n'
|
|
content += '</message>\n'
|
|
content += '</message>\n'
|
|
- content += '</TS>'
|
|
|
|
|
|
+ content += '</context>\n'
|
|
|
|
+ content += '</TS>'
|
|
return content
|
|
return content
|
|
else:
|
|
else:
|
|
print('none')
|
|
print('none')
|
|
|
|
|
|
return content
|
|
return content
|
|
|
|
|
|
|
|
+ def get_area_language(self, id):
|
|
|
|
+ result = {}
|
|
|
|
+ lkc_qs = LangKeyModel.objects.filter(langvalmodel__la__id=id, type__in=(1, 2)).values('word_key',
|
|
|
|
+ 'langkeyclassmodel__clazz__name',
|
|
|
|
+ 'langvalmodel__word_val',
|
|
|
|
+ 'langlocationmodel__filename',
|
|
|
|
+ 'langlocationmodel__line')
|
|
|
|
+ for lkc in lkc_qs:
|
|
|
|
+ # print(lkc)
|
|
|
|
+ name = lkc['langkeyclassmodel__clazz__name']
|
|
|
|
+ hasClass = result.__contains__(name)
|
|
|
|
+ if hasClass is False:
|
|
|
|
+ result[name] = {}
|
|
|
|
|
|
-from django.http import StreamingHttpResponse
|
|
|
|
|
|
+ source = lkc['word_key']
|
|
|
|
+ if not result[name].__contains__(source):
|
|
|
|
+ result[name][source] = {}
|
|
|
|
+ message = result[name][source]
|
|
|
|
+
|
|
|
|
+ message['source'] = source
|
|
|
|
+ message['translation'] = lkc['langvalmodel__word_val']
|
|
|
|
+
|
|
|
|
+ # location
|
|
|
|
+ locations = []
|
|
|
|
+ locations.append({'filename': lkc['langlocationmodel__filename'], 'line': lkc['langlocationmodel__line']})
|
|
|
|
+ message['locations'] = locations
|
|
|
|
+ print(result)
|
|
|
|
+ return result
|
|
|
|
+
|
|
|
|
+ def get_avss_language(self, id):
|
|
|
|
+ if id == 18: # 简体中文
|
|
|
|
+ return 'zh_CN'
|
|
|
|
+ elif id == 19: # 繁体中文
|
|
|
|
+ return 'zh_HK'
|
|
|
|
+ elif id == 20: # 英文
|
|
|
|
+ return 'en_US'
|
|
|
|
+ elif id == 21: # 俄语
|
|
|
|
+ return 'ru'
|
|
|
|
+ elif id == 22: # 德语
|
|
|
|
+ return 'de'
|
|
|
|
+ elif id == 23: # 波兰语
|
|
|
|
+ return 'pl'
|
|
|
|
+ elif id == 24: # 法语
|
|
|
|
+ return 'fr'
|
|
|
|
+ elif id == 25: # 西班牙语
|
|
|
|
+ return 'es'
|
|
|
|
+ elif id == 26: # 日语
|
|
|
|
+ return 'ja'
|
|
|
|
+ elif id == 27: # 阿拉伯语
|
|
|
|
+ return 'ar'
|
|
|
|
+ elif id == 29: # 意大利语
|
|
|
|
+ return 'it'
|
|
|
|
+ elif id == 30: # 葡萄牙语
|
|
|
|
+ return 'pt'
|
|
|
|
+ elif id == 31: # 荷兰语
|
|
|
|
+ return 'nl'
|
|
|
|
+ elif id == 32: # 越南语
|
|
|
|
+ return 'vi'
|
|
|
|
|
|
|
|
|
|
class exportLangView(TemplateView):
|
|
class exportLangView(TemplateView):
|