Add infrastructure for single-string translations.
This is intended to allow important strings to be automatically translated while we work on improving the quality of automatic translations.
This commit is contained in:
@@ -220,7 +220,7 @@ def translation_filename(s):
|
||||
return filename
|
||||
|
||||
|
||||
def write_strings(language, filter, min_priority, max_priority, common_only): # @ReservedAssignment
|
||||
def write_strings(language, filter, min_priority, max_priority, common_only, only_strings=[]): # @ReservedAssignment
|
||||
"""
|
||||
Writes strings to the file.
|
||||
"""
|
||||
@@ -251,6 +251,9 @@ def write_strings(language, filter, min_priority, max_priority, common_only): #
|
||||
if language == "None" and tlfn == "common.rpy":
|
||||
tlfn = "common.rpym"
|
||||
|
||||
if only_strings and s.text not in only_strings:
|
||||
continue
|
||||
|
||||
stringfiles[tlfn].append(s)
|
||||
|
||||
for tlfn, sl in stringfiles.items():
|
||||
@@ -491,6 +494,7 @@ def translate_command():
|
||||
ap.add_argument("--strings-only", help="Only translate strings (not dialogue).", dest="strings_only", default=False, action="store_true")
|
||||
ap.add_argument("--common-only", help="Only translate string from the common code.", dest="common_only", default=False, action="store_true")
|
||||
ap.add_argument("--no-todo", help="Do not include the TODO flag.", dest="todo", default=True, action="store_false")
|
||||
ap.add_argument("--string", help="Translate a single string.", dest="string", action="append")
|
||||
|
||||
args = ap.parse_args()
|
||||
|
||||
@@ -519,7 +523,7 @@ def translate_command():
|
||||
for filename in translate_list_files():
|
||||
write_translates(filename, args.language, filter)
|
||||
|
||||
write_strings(args.language, filter, args.min_priority, max_priority, args.common_only)
|
||||
write_strings(args.language, filter, args.min_priority, max_priority, args.common_only, args.string)
|
||||
|
||||
close_tl_files()
|
||||
|
||||
|
||||
@@ -174,7 +174,17 @@ def quote_unicode(s):
|
||||
|
||||
return f'"{s}"'
|
||||
|
||||
def process_file(fn, language):
|
||||
def process_file(fn, language, only_strings=[]):
|
||||
|
||||
|
||||
def should_translate(s):
|
||||
if "{#" in s:
|
||||
return False
|
||||
|
||||
if only_strings and s not in only_strings:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
print("Translate", fn, "to", language)
|
||||
|
||||
@@ -196,7 +206,7 @@ def process_file(fn, language):
|
||||
new = ast.literal_eval(l.strip().partition(" ")[2])
|
||||
orig_new = new
|
||||
|
||||
if (not new) or (new == old and ("{#" not in new)):
|
||||
if ((not new) or (new == old)) and should_translate(old):
|
||||
new = translate_lines(old, language, source_fn)
|
||||
|
||||
if new != old or new != orig_new:
|
||||
@@ -224,11 +234,12 @@ def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("language")
|
||||
ap.add_argument("files", nargs="+")
|
||||
ap.add_argument("--string", help="Translate a single string.", dest="string", action="append")
|
||||
|
||||
args = ap.parse_args()
|
||||
|
||||
for fn in args.files:
|
||||
process_file(fn, args.language)
|
||||
process_file(fn, args.language, args.string)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
set -e
|
||||
cd $(dirname $(dirname $(readlink -f $0)))
|
||||
|
||||
args=("$@")
|
||||
|
||||
translate () {
|
||||
./run.sh launcher translate $1 --empty --no-todo
|
||||
./scripts/automatic_translate.py $2 launcher/game/tl/$1/*.rpy
|
||||
./run.sh launcher translate $1 --strings-only --empty --no-todo "${args[@]}"
|
||||
./scripts/automatic_translate.py $2 launcher/game/tl/$1/*.rpy "${args[@]}"
|
||||
}
|
||||
|
||||
translate finnish FI
|
||||
|
||||
Reference in New Issue
Block a user