def write_strings(language, filter, min_priority, max_priority, common_only): # @ReservedAssignment """ Writes strings to the file. """ if language == "None": stl = renpy.game.script.translator.strings[None] # @UndefinedVariable else: stl = renpy.game.script.translator.strings[ language] # @UndefinedVariable # If this function changes, count_missing may also need to # change. strings = renpy.translation.scanstrings.scan(min_priority, max_priority, common_only) stringfiles = collections.defaultdict(list) for s in strings: tlfn = translation_filename(s) if tlfn is None: continue # Already seen. if s.text in stl.translations: continue if language == "None" and tlfn == "common.rpy": tlfn = "common.rpym" stringfiles[tlfn].append(s) for tlfn, sl in stringfiles.items(): # sl.sort(key=lambda s : (s.filename, s.line)) tlfn = os.path.join(renpy.config.gamedir, renpy.config.tl_directory, language, tlfn) f = open_tl_file(tlfn) f.write(u"translate {} strings:\n".format(language)) f.write(u"\n") for s in sl: text = filter(s.text) f.write(u" # {}:{}\n".format(elide_filename(s.filename), s.line)) f.write(u" old \"{}\"\n".format(quote_unicode(s.text))) f.write(u" new \"{}\"\n".format(quote_unicode(text))) f.write(u"\n")
def write_strings(language, filter, min_priority, max_priority, common_only): # @ReservedAssignment """ Writes strings to the file. """ if language == "None": stl = renpy.game.script.translator.strings[None] # @UndefinedVariable else: stl = renpy.game.script.translator.strings[language] # @UndefinedVariable # If this function changes, count_missing may also need to # change. strings = renpy.translation.scanstrings.scan(min_priority, max_priority, common_only) stringfiles = collections.defaultdict(list) for s in strings: tlfn = translation_filename(s) if tlfn is None: continue # Already seen. if s.text in stl.translations: continue if language == "None" and tlfn == "common.rpy": tlfn = "common.rpym" stringfiles[tlfn].append(s) for tlfn, sl in stringfiles.items(): # sl.sort(key=lambda s : (s.filename, s.line)) tlfn = os.path.join(renpy.config.gamedir, renpy.config.tl_directory, language, tlfn) f = open_tl_file(tlfn) f.write(u"translate {} strings:\n".format(language)) f.write(u"\n") for s in sl: text = filter(s.text) f.write(u" # {}:{}\n".format(s.elided, s.line)) f.write(u" old \"{}\"\n".format(quote_unicode(s.text))) f.write(u" new \"{}\"\n".format(quote_unicode(text))) f.write(u"\n")
def get_strings(self): """ Finds the strings in the file. """ lines = [] filename = renpy.parser.elide_filename(self.filename) for line, s in scan_strings(self.filename): stl = renpy.game.script.translator.strings[ None] # @UndefinedVariable if s in stl.translations: continue stl.translations[s] = s if self.notags: s = notags_filter(s) if self.escape: s = quote_unicode(s) if self.tdf: lines.append(["", "", s, filename, str(line)]) else: lines.append([s]) return lines
def get_strings(self): """ Finds the strings in the file. """ lines = [] filename = renpy.parser.elide_filename(self.filename) for line, s in scan_strings(self.filename): stl = renpy.game.script.translator.strings[None] # @UndefinedVariable if s in stl.translations: continue stl.translations[s] = s if self.notags: s = notags_filter(s) if self.escape: s = quote_unicode(s) if self.tdf: lines.append(["", "", s, filename, str(line)]) else: lines.append([s]) return lines
def write_dialogue(self): """ Writes the dialogue to the file. """ lines = [] translator = renpy.game.script.translator for label, t in translator.file_translates[self.filename]: if label is None: label = "" for n in t.block: if isinstance(n, renpy.ast.Say): if not n.who: who = "" else: who = n.who what = n.what if self.notags: what = notags_filter(what) if self.escape: what = quote_unicode(what) elif self.tdf: what = what.replace("\\", "\\\\") what = what.replace("\t", "\\t") what = what.replace("\n", "\\n") if self.tdf: lines.append([ t.identifier, who, what, n.filename, str(n.linenumber), n.get_code(what_filter) ]) else: lines.append([what]) if self.strings: lines.extend(self.get_strings()) # If we're tab-delimited, we have line number info, which means we # can sort the list so everything's in order, for menus and stuff. if self.tdf: lines.sort(key=lambda x: int(x[4])) for line in lines: self.f.write("\t".join(line) + "\n")
def write_dialogue(self): """ Writes the dialogue to the file. """ lines = [] translator = renpy.game.script.translator for label, t in translator.file_translates[self.filename]: if label is None: label = "" for n in t.block: if isinstance(n, renpy.ast.Say): if not n.who: who = "" else: who = n.who what = n.what if self.notags: what = notags_filter(what) if self.escape: what = quote_unicode(what) elif self.tdf: what = what.replace("\\", "\\\\") what = what.replace("\t", "\\t") what = what.replace("\n", "\\n") if self.tdf: lines.append([ t.identifier, who, what, n.filename, str(n.linenumber), ]) else: lines.append([what]) if self.strings: lines.extend(self.get_strings()) # If we're tab-delimited, we have line number info, which means we # can sort the list so everything's in order, for menus and stuff. if self.tdf: lines.sort(key=lambda x: int(x[4])) for line in lines: self.f.write("\t".join(line).encode("utf-8") + "\n")
def write_strings(self): """ Writes strings to the file. """ # If this function changes, count_missing may also need to # change. started = False filename = renpy.parser.elide_filename(self.filename) strings = scan_strings(self.filename) if renpy.config.translate_comments: strings.extend(scan_comments(self.filename)) # Sort by line number. strings.sort(key=lambda a: a[0]) for line, s in strings: stl = renpy.game.script.translator.strings[ self.language] # @UndefinedVariable if s in stl.translations: continue stl.translations[s] = s if not started: started = True self.open() self.f.write(u"translate {} strings:\n".format(self.language)) self.f.write(u"\n") fs = self.filter(s) self.f.write(u" # {}:{}\n".format(filename, line)) self.f.write(u" old \"{}\"\n".format(quote_unicode(s))) self.f.write(u" new \"{}\"\n".format(quote_unicode(fs))) self.f.write(u"\n")
def write_strings(self): """ Writes strings to the file. """ # If this function changes, count_missing may also need to # change. started = False filename = renpy.parser.elide_filename(self.filename) strings = scan_strings(self.filename) if renpy.config.translate_comments: strings.extend(scan_comments(self.filename)) # Sort by line number. strings.sort(key=lambda a : a[0]) for line, s in strings: stl = renpy.game.script.translator.strings[self.language] # @UndefinedVariable if s in stl.translations: continue stl.translations[s] = s if not started: started = True self.open() self.f.write(u"translate {} strings:\n".format(self.language)) self.f.write(u"\n") fs = self.filter(s) self.f.write(u" # {}:{}\n".format(filename, line)) self.f.write(u" old \"{}\"\n".format(quote_unicode(s))) self.f.write(u" new \"{}\"\n".format(quote_unicode(fs))) self.f.write(u"\n")
def get_strings(self): """ Finds the strings in the file. """ lines = [] filename = renpy.parser.elide_filename(self.filename) for ss in renpy.translation.scanstrings.scan_strings(self.filename): line = ss.line s = ss.text stl = renpy.game.script.translator.strings[None] # @UndefinedVariable # don't include s in common.rpym if s in stl.translations: continue # avoid to include same s stl.translations[s] = s s = renpy.translation.translate_string(s, self.language) if self.notags: s = notags_filter(s) if self.escape: s = quote_unicode(s) elif self.tdf: s = s.replace("\\", "\\\\") s = s.replace("\t", "\\t") s = s.replace("\n", "\\n") if self.tdf: lines.append(["", "", s, filename, str(line)]) else: lines.append([s]) return lines