def run(self): from_po_doc=c.load_po(self.from_file) #print("{}; Loaded:{}".format(self.from_file, len(from_po_doc))) to_po_doc=c.load_po(self.to_file) #print("{}; Loaded:{}".format(self.to_file, len(to_po_doc))) from_po_list = self.dicToList(from_po_doc) sorted_from_dic = sorted(from_po_list) #pp(sorted_from_dic) for m in to_po_doc: found_index = self.binarySearch(sorted_from_dic, m) is_found = (found_index >= 0) if (not is_found): print("to_po_doc, INSERTED: id=[{}], context=[{}]".format(m.id, m.context)) continue to_po_list = self.dicToList(to_po_doc) sorted_to_dic = sorted(to_po_list) for m in from_po_doc: found_index = self.binarySearch(sorted_to_dic, m) is_found = (found_index >= 0) if (not is_found): print("from_po_doc, DELETED: id=[{}], context=[{}]".format(m.id, m.context)) continue
def loadFiles(self): self.po_cat = c.load_po(self.from_file) if self.update_dic: self.json_dic = self.loadJSONDic(self.to_file) else: self.pot_cat = c.load_po(self.to_file) self.sorted_po_cat = None
def loadFiles(self): valid_from_file = (self.from_file is not None) and (os.path.isfile( self.from_file)) valid_to_file = (self.to_file is not None) and (os.path.isfile( self.to_file)) valid = (valid_from_file and valid_to_file) if not valid: print("Source file:", self.from_file, "and/or Target File:", self.to_file, "is NOT VALID or doesn't exists, or cann't be accessed.") return self.from_po_cat = c.load_po(self.from_file) self.to_po_cat = c.load_po(self.to_file)
def ProcessRSTDoc(self): #print(dic_file) doc_path = self.getDocPath(self.document) l = [] result = self.getByKeyword(self.document) if (result != None): l.extend(result) l = sorted(l) print("{}".format(doc_path)) print("{}".format(l)) print("-" * 50) return po_file = "{}.po".format(doc_path) po_path = os.path.join(RSTToPo.default_po_path, po_file) #print("Processing: {}".format(po_path)) if (os.path.exists(po_path)): ##print("File is there: {}".format(po_path)) po_doc = c.load_po(po_path) ##self.translatingSubtitlesUsingDictionary(po_doc, po_path, l) ##self.duplicateMSGIDToUntranslatedMSGSTR(po_path, po_doc, l) self.getUntranslatedSubtitleToDictionary(po_doc, po_path, l) ##po_doc = Document(po_path) ##po_doc.loadPOText() ##po_doc.duplicateMSGIDToUntranslatedMSGSTR(l) #self.resetFileNamePrinted() else: print("File is NOT there: {}".format(po_path))
def run(self): #exit(0) self.po_file_list = self.getPOFileList() for po_file in self.po_file_list: po_doc = c.load_po(po_file) #po_file = "/home/htran/test_vi.po" self.dump_po(po_file, po_doc)
def run(self): changed = False po_cat = cat.load_po(self.input_file) for index, po_entry in enumerate(po_cat): is_changed = False is_first_entry = (index == 0) if (is_first_entry): continue c = po_entry.context k = po_entry.id s = po_entry.string is_ignore_word = cm.isIgnoredWord(k) is_number = cm.isNumber(k) is_single_char = (len(k) <= 2) is_resolution = cm.isResolution(k) is_hz = cm.isHz(k) is_untranslated = cm.isUntranslated(k) is_ignore = (is_ignore_word or is_number or is_single_char or is_resolution or is_hz or is_untranslated) if (is_ignore): continue is_untranslated = (len(s.strip()) == 0) if (not is_untranslated): continue self.printMSGID(k) self.printMSGSTR(s) self.printSeparator()
def copyTranslationFromVIPOToDictOnFile(self): vipo_file = "/home/htran/blender_documentations/new_po/vi.po" dict_file = "/home/htran/menuselection_dictionary_sorted_translated.json" new_dict_file = "/home/htran/menuselection_new_dictionary_sorted_translated.json" vipo_doc = c.load_po(vipo_file) local_vipo_dict = {} for index, m in enumerate(vipo_doc): if (index == 0): continue k = m.id v = m.string local_vipo_dict.update({k: v}) self.readDictionary(file_name=dict_file) print("len of vipo_dic:{}".format(len(local_vipo_dict))) print("len of json_dic:{}".format(len(self.dic_list))) new_dict_list = {} for k, v in self.dic_list.items(): new_dict_list.update({k: v}) #print("json k:[{}] json v:[{}]".format(k, v)) can_find_definition = (len(v) == 0) if (not can_find_definition): continue #kk = re.search("\((.*)\)", k) #key = kk[0] trans = None key = k.strip("()") if (not key in local_vipo_dict): print("NOT IN VIPO DIC:[{}]".format(key)) key_word_list = (key.split(" ")) print("key_word_list:{}".format(key_word_list)) trans_word_list = [] for word in key_word_list: if (not word in local_vipo_dict): trans_word_list.append(word) else: trans = local_vipo_dict[word] trans_word_list.append(trans) trans = " ".join(trans_word_list) if (trans == key): continue else: trans = local_vipo_dict[key] has_translation = (len(trans) > 0) if (has_translation): k = "({})".format(key) #print("key:[{}]; value:[{}]".format(k, trans)) new_dict_list.update({k: trans}) else: print("key:[{}]; NO TRANSLATION".format(key)) self.writeDictionary(dict_list=new_dict_list, file_name=new_dict_file)
def loadDictionary(self): master_dic={} self.po_file_list = self.getPOFileList() for po_file in self.po_file_list: po_doc = c.load_po(po_file) doc_dic = self.docToDic(po_doc) master_dic.update(doc_dic) return master_dic
def run(self): po_dic = self.poCatToList(self.po_cat) self.sorted_po_cat = sorted(po_dic, key=lambda x: "{}{}".format(x[0], x[1])) self.sorted_lower_po_cat = sorted( po_dic, key=lambda x: "{}{}".format(x[0].lower(), x[1])) getter = POBasic(self.po_dir, False) po_dir_list = getter.getSortedPOFileList() #pp(po_dir_list) #exit(0) trans_cat = None #pp(self.sorted_po_cat) #exit(0) changed = False for file_index, trans_path in enumerate(po_dir_list): print("File:", trans_path) print("-" * 80) trans_cat = c.load_po(UpdateTranslationFiles.to_blender_pot_path) for index, pot_entry in enumerate(trans_cat): is_first_entry = (index == 0) if (is_first_entry): continue #print("id:{}, is_fuzzy:{}".format(po_entry.id, po_entry.fuzzy)) #if (po_entry.fuzzy): #exit(0) #else: #continue k = pot_entry.id found_entry = self.binarySearch(self.sorted_po_cat, pot_entry) is_in = isinstance(found_entry, Message) if (not is_in): #print("Find in lower case list: ", k) found_entry = self.binarySearch(self.sorted_lower_po_cat, pot_entry, is_lcase=True) is_in = isinstance(found_entry, Message) if (not is_in): #print("Not Found, NEW: {}".format(k)) continue changed = self.dealWithEntry(found_entry, pot_entry) if (changed): new_po_file = "/home/htran/new_vi.po" print( "Saving content of new pot_cat to:{}".format(new_po_file)) self.dump_po(new_po_file, trans_cat)
def run(self): master_dic = self.loadDictionary() self.sorted_master_dic = master_dic for po_file in self.po_file_list: po_doc = c.load_po(po_file) changed = self.updateDocument(po_doc, po_file) if (changed): print("Save changes to file:{}".format(po_file)) print("=" * 80) #po_file = "/home/htran/test.po" self.dump_po(po_file, po_doc)
def run(self): #exit(0) self.readDictionary() #for k,v in self.dic_list.items(): #print("K=[{}] V=[{}]".format(k, v)) #exit(0) self.po_file_list = self.getPOFileList() for po_file in self.po_file_list: po_doc = c.load_po(po_file) self.rewordingMSGSTR(po_doc, po_file) self.writeDictionary()
def test_write_and_read_po_file_with_non_ascii_string(temp): from sphinx_intl import catalog cat = Catalog(locale='ja', domain='domain', fuzzy=False) msg = Message('Hello World', u'こんにちは世界') cat[msg.id] = msg po_file = (temp / 'domain.po') catalog.dump_po(po_file, cat) cat2 = catalog.load_po(po_file) assert cat2[msg.id].string == msg.string
def run(self): #exit(0) try: self.po_file_list = self.getPOFileList() for po_file in self.po_file_list: po_doc = c.load_po(po_file) if self.dry_run: print("File to be flatted:", po_file) else: #self.dump_po(po_file, po_doc) c.dump_po(po_file, po_doc) except Exception as e: print(e) print(po_file)
def run(self): with lock_(): self.readDictionary() #self.writeDictionary() #exit(0) self.dic_list_updated = False self.po_file_list = self.getPOFileList() for po_file in self.po_file_list: if (self.isExcluded(po_file)): continue po_doc = c.load_po(po_file) self.FindAndFill(po_doc, po_file) self.resetFileNamePrinted() if (self.dic_list_updated): self.writeDictionary()
def run(self): changed = False po_cat = cat.load_po(self.input_file) for index, po_entry in enumerate(po_cat): is_changed = False is_first_entry = (index == 0) if (is_first_entry): continue c = po_entry.context k = po_entry.id s = po_entry.string is_fuzzy = (po_entry.fuzzy) if (not is_fuzzy): continue self.printMSGID(k) self.printMSGSTR(s) self.printSeparator()
def ProcessRSTDoc(self): #self.readDictionary() #print(self.dic_list) ##exit(0) kw = ['title', 'field_name', 'term', 'strong', 'rubric'] doc_path = self.getDocPath(self.document) #print(self.text) #p = re.compile(self.pattern) #t = re.sub("\n", " ", self.text) #r'<title[^>]*>([^<]+)</title>' #print("{}".format(m[0])) l = [] for k in kw: result = self.getByKeyword(k, self.document) if (result != None): l.extend(result) #s = set(l) #s1 = sorted(s) #l = list(s1) #print("doc_path:{}, keywords: {}".format(doc_path, l)) po_file = "{}.po".format(doc_path) po_path = os.path.join(RSTToPo.default_po_path, po_file) if (os.path.exists(po_path)): #print("File is there: {}".format(po_path)) po_doc = c.load_po(po_path) self.translatingSubtitlesUsingDictionary(po_doc, po_path, l) #self.duplicateMSGIDToUntranslatedMSGSTR(po_path, po_doc, l) #po_doc = Document(po_path) #po_doc.loadPOText() #po_doc.duplicateMSGIDToUntranslatedMSGSTR(l) else: print("File is NOT there: {}".format(po_path))
def run(self): status = { 'create': 0, 'update': 0, 'notchanged': 0, } for dirpath, dirnames, filenames in os.walk(self.pot_dir): for filename in filenames: pot_file = os.path.join(dirpath, filename) base, ext = os.path.splitext(pot_file) basename = relpath(base, self.pot_dir) for lang in self.languages: po_dir = os.path.join(self.locale_dir, lang, 'LC_MESSAGES') po_file = os.path.join(po_dir, basename + ".po") if os.path.exists(po_file): cat = c.load_po(po_file) changed = False #self.dump_po(po_file, cat) for func in function_list: if isinstance(func, FunctionBase): #print("apply_function: po_file{}".format(po_file)) func.category = c func.pofileCategory = cat func.fileName = po_file func.setLocalVars() func.run() if (func.changed): print('Update:{}'.format(po_file)) status['update'] += 1 self.dump_po(po_file, cat) else: pass #status['notchanged'] += 1 return status
def __init__(self): self.po_cat = c.load_po(UpdateTranslationFiles.from_vipo_path) self.pot_cat = c.load_po(UpdateTranslationFiles.to_blender_pot_path) self.sorted_po_cat = None self.po_dir = UpdateTranslationFiles.translation_default_dir
def __init__(self): self.po_cat = c.load_po(FindCaseDiff.from_vipo_path) self.sorted_po_cat = None
def replaceAndReport(self, changed_file): # these lines are taken from /Library/Python/3.7/site-packages/babel/messages/catalog.py # put here for references # # self.domain = domain # self.locale = locale # self._header_comment = header_comment # self._messages = OrderedDict() # self.project = project or 'PROJECT' # self.version = version or 'VERSION' # self.copyright_holder = copyright_holder or 'ORGANIZATION' # self.msgid_bugs_address = msgid_bugs_address or 'EMAIL@ADDRESS' # self.last_translator = last_translator or 'FULL NAME <EMAIL@ADDRESS>' # """Name and email address of the last translator.""" # self.language_team = language_team or 'LANGUAGE <*****@*****.**>' # """Name and email address of the language team.""" # self.charset = charset or 'utf-8' # if creation_date is None: # creation_date = datetime.now(LOCALTZ) # elif isinstance(creation_date, datetime) and not creation_date.tzinfo: # creation_date = creation_date.replace(tzinfo=LOCALTZ) # self.creation_date = creation_date # if revision_date is None: # revision_date = 'YEAR-MO-DA HO:MI+ZONE' # elif isinstance(revision_date, datetime) and not revision_date.tzinfo: # revision_date = revision_date.replace(tzinfo=LOCALTZ) # self.revision_date = revision_date # self.fuzzy = fuzzy # self.obsolete = OrderedDict() # Dictionary of obsolete messages # self._num_plurals = None # self._plural_expr = None cat_changed = False header_changed = False in_po_cat = c.load_po(changed_file) local_time = timezone(TIME_ZONE) time_now = local_time.localize(datetime.datetime.now()) if self.modi_time: change_time = time_now.strftime('%Y-%m-%d %H:%M%z') print("PO-Revision-Date:", change_time) in_po_cat.revision_date = time_now cat_changed = True is_you_last_translator = (YOUR_ID in in_po_cat.last_translator) if not is_you_last_translator: print("Last-Translator:", YOUR_ID) in_po_cat.last_translator = YOUR_ID cat_changed = True is_language_team_already_set = (YOUR_TRANSLATION_TEAM in in_po_cat.language_team) if not is_language_team_already_set: print("Language-Team:", YOUR_TRANSLATION_TEAM) in_po_cat.language_team = YOUR_TRANSLATION_TEAM cat_changed = True header = in_po_cat._get_header_comment() is_you_already_first_author = (YOUR_NAME in header) and (default_first_author not in header) if not is_you_already_first_author: print("FIRST AUTHOR <EMAIL@ADDRESS>", YOUR_ID) header = header.replace(default_first_author, YOUR_NAME) header = header.replace(default_mail_address, YOUR_EMAIL) is_year_set = (header.find(default_year) < 0) if not is_year_set: year = time_now.strftime('%Y') print(default_year, year) actual_year = ", {}.".format(year) header = header.replace(default_year, actual_year) header_changed = True in_po_cat.header_comment = header changed = (cat_changed or header_changed) if changed: if self.dry_run: print("Processing file:", changed_file) print("-" * 80) else: #self.basic_io.writeTextFile(changed_file, data) c.dump_po(changed_file, in_po_cat) print("Wrote changes to:", changed_file)
def __init__(self): self.from_po_cat = c.load_po(UpdateVIPO.from_vipo_path) self.to_po_cat = c.load_po(UpdateVIPO.to_blender_pot_path) self.sorted_from_po_cat = None
def run(self): c = None k = None s = None find_c = self.msgctx find_k = self.msgid find_s = self.msgstr rep_txt = self.rep_txt ex_msgid = self.exclude_id ex_msgstr = self.exclude_str is_find_context = (find_c != None) is_find_msgid = (find_k != None) is_find_msgstr = (find_s != None) is_replace = (rep_txt != None) is_exclude_msgid = (ex_msgid != None) is_exclude_msgstr = (ex_msgstr != None) msgid_exclude_p = None msgstr_exclude_p = None is_valid = (is_find_context or is_find_msgid or is_find_msgstr or is_replace) if not is_valid: return context_p = msgid_p = msgstr_p = None if (self.case_insensitive): if (is_find_context): context_p = re.compile(find_c, flags=re.I) if (is_find_msgid): msgid_p = re.compile(find_k, flags=re.I) if (is_find_msgstr): msgstr_p = re.compile(find_s, flags=re.I) if (is_exclude_msgid): msgid_exclude_p = re.compile(ex_msgid, flags=re.I) if (is_exclude_msgstr): msgstr_exclude_p = re.compile(ex_msgstr, flags=re.I) else: if (is_find_context): context_p = re.compile(find_c) if (is_find_msgid): msgid_p = re.compile(find_k) if (is_find_msgstr): msgstr_p = re.compile(find_s) if (is_exclude_msgid): msgid_exclude_p = re.compile(ex_msgid) if (is_exclude_msgstr): msgstr_exclude_p = re.compile(ex_msgstr) changed = False po_cat = cat.load_po(self.input_file) for index, po_entry in enumerate(po_cat): is_changed = False is_first_entry = (index == 0) if (is_first_entry): continue c = po_entry.context k = po_entry.id s = po_entry.string is_found_msgctx = False is_found_msgid = False is_found_msgstr = False is_found_exclude_msgid = False is_found_exclude_msgstr = False if (is_find_context): is_found_msgctx = (c != None) and (len(c) > 0) and ( context_p.search(c) != None) if (is_find_msgid): is_found_msgid = (k != None) and (len(k) > 0) and ( msgid_p.search(k) != None) if (is_found_msgid): is_found_exclude_msgid = (is_exclude_msgid) and ( msgid_exclude_p.search(k) != None) is_found_msgid = (not is_found_exclude_msgid) if (is_find_msgstr): is_found_msgstr = (s != None) and (len(s) > 0) and ( msgstr_p.search(s) != None) if (is_found_msgstr): is_found_exclude_msgstr = (is_exclude_msgstr) and ( msgstr_exclude_p.search(s) != None) is_found_msgstr = (not is_found_exclude_msgstr) #0 0 0 #0 0 1 #0 1 0 #0 1 1 #1 0 0 #1 0 1 #1 1 0 #1 1 1 p1 = (not is_find_context and not is_find_msgid and is_find_msgstr) and (is_found_msgstr) p2 = (not is_find_context and is_find_msgid and not is_find_msgstr) and (is_found_msgid) p3 = (not is_find_context and is_find_msgid and is_find_msgstr) and (is_found_msgid and is_found_msgstr) p4 = (is_find_context and not is_find_msgid and not is_find_msgstr) and (is_found_msgctx) p5 = (is_find_context and not is_find_msgid and is_find_msgstr) and (is_found_msgctx and is_found_msgstr) p6 = (is_find_context and is_find_msgid and not is_find_msgstr) and (is_found_msgctx and is_found_msgid) p7 = (is_find_context and is_find_msgid and is_find_msgstr) and (is_found_msgctx and is_found_msgid and is_found_msgstr) is_replacing = (is_replace and (p1 or p3 or p5 or p7)) if (is_replacing): old_text = str(s) new_text = msgstr_p.sub(rep_txt, s) po_entry.string = new_text is_changed = (old_text != new_text) if (is_changed): s = new_text changed = True if (p1): self.printMSGSTR(s) elif (p2): self.printMSGID(k) elif (p3): self.printMSGID(k) self.printMSGSTR(s) elif (p4): self.printMSGCTXT(c) elif (p5): self.printMSGCTXT(c) self.printMSGSTR(s) elif (p6): self.printMSGCTXT(c) self.printMSGID(k) elif (p7): self.printMSGCTXT(c) self.printMSGID(k) self.printMSGSTR(s) is_found = (p1 or p2 or p3 or p4 or p5 or p6 or p7) if (is_found): self.printSeparator() if (changed): print("Writting changes to:", FindVIPO.output_file) self.dump_po(FindVIPO.output_file, po_cat)
def __init__(self): self.dic_path = "/home/htran/blender_documentations/new_po/vi.po" self.dic_cat = c.load_po(self.dic_path) self.dic_cat_lower = self.poCatDictLower(self.dic_cat)
def run(self): #exit(0) self.po_file_list = self.getPOFileList() for po_file in self.po_file_list: po_doc = c.load_po(po_file) self.checkForFuzzy(po_doc, po_file)
def loadFiles(self): self.po_cat = c.load_po(self.from_vipo) self.pot_cat = c.load_po(self.to_vipo)