1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
|
# Copyright 2004-2018 Tom Rothamel <pytom@bishoujo.us>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
init python:
import re
import tempfile
if persistent.translate_language is None:
persistent.translate_language = "english"
if persistent.generate_empty_strings is None:
persistent.generate_empty_strings = True
if persistent.replace_translations is None:
persistent.replace_translations = False
if persistent.reverse_languages is None:
persistent.reverse_languages = False
def CheckLanguage():
return SensitiveIf(re.match(r'^\w+$', persistent.translate_language))
strings_json = None
def get_strings_json():
global strings_json
if strings_json is not None:
return strings_json
try:
tempdir = os.path.expanduser("~/.renpy/tmp")
try:
os.makedirs(os.path.expanduser("~/.renpy/tmp"))
except:
pass
write_test = os.path.join(tempdir, "writetest.txt")
if os.path.exists(write_test):
os.unlink(write_test)
with open(write_test, "w"):
pass
os.unlink(write_test)
except:
tempdir = tempfile.mkdtemp()
strings_json = os.path.join(tempdir, "strings.json")
return strings_json
screen translate:
default tt = Tooltip(None)
$ state = AndroidState()
frame:
style_group "l"
style "l_root"
window:
has vbox
label _("Translations: [project.current.display_name!q]")
add HALF_SPACER
hbox:
# Left side.
frame:
style "l_indent"
xmaximum ONEHALF
xfill True
has vbox
frame:
style "l_indent"
has vbox
text _("Language:")
add HALF_SPACER
frame style "l_indent":
input style "l_default":
value FieldInputValue(persistent, "translate_language")
size 24
color INPUT_COLOR
allow interface.TRANSLATE_LETTERS
# Left side.
frame:
style "l_indent"
xmaximum ONEHALF
xfill True
has vbox
frame:
style "l_indent"
has vbox
text _("The language to work with. This should only contain lower-case ASCII characters and underscores.")
add SPACER
hbox:
frame:
style "l_indent"
xmaximum ONEHALF
xfill True
has vbox
add SEPARATOR2
add HALF_SPACER
frame:
style "l_indent"
has vbox
textbutton _("Generate Translations"):
text_size 24
action [ CheckLanguage(), Jump("generate_translations") ]
add HALF_SPACER
textbutton _("Generate empty strings for translations") style "l_checkbox" action ToggleField(persistent, "generate_empty_strings")
frame:
style "l_indent"
xmaximum ONEHALF
xfill True
has vbox
add SEPARATOR2
frame:
style "l_indent"
top_padding 10
has vbox
text _("Generates or updates translation files. The files will be placed in game/tl/[persistent.translate_language!q].")
add SPACER
hbox:
frame:
style "l_indent"
xmaximum ONEHALF
xfill True
has vbox
add SEPARATOR2
add HALF_SPACER
frame:
style "l_indent"
has vbox
textbutton _("Extract String Translations"):
action [ CheckLanguage(), Jump("extract_strings") ]
textbutton _("Merge String Translations"):
action [ CheckLanguage(), Jump("merge_strings") ]
add HALF_SPACER
textbutton _("Replace existing translations") style "l_checkbox" action ToggleField(persistent, "replace_translations")
textbutton _("Reverse languages") style "l_checkbox" action ToggleField(persistent, "reverse_languages")
add HALF_SPACER
textbutton _("Update Default Interface Translations"):
action [ Jump("update_renpy_strings") ]
frame:
style "l_indent"
xmaximum ONEHALF
xfill True
has vbox
add SEPARATOR2
frame:
style "l_indent"
top_padding 10
has vbox
text _("The extract command allows you to extract string translations from an existing project into a temporary file.\n\nThe merge command merges extracted translations into another project.")
textbutton _("Return") action Jump("front_page") style "l_left_button"
label translate:
call screen translate
# Common code to create the new translations in the current game.
label generate_translations_common:
python:
language = persistent.translate_language
args = [ "translate", language ]
if language == "rot13":
args.append("--rot13")
elif language == "piglatin":
args.append("--piglatin")
elif persistent.generate_empty_strings:
args.append("--empty")
interface.processing(_("Ren'Py is generating translations...."))
project.current.launch(args, wait=True)
project.current.update_dump(force=True)
return
# Code to generate translations by themselves.
label generate_translations:
call generate_translations_common
python:
interface.info(_("Ren'Py has finished generating [language] translations."))
jump front_page
label extract_strings:
python:
language = persistent.translate_language
args = [ "extract_strings", language, get_strings_json() ]
interface.processing(_("Ren'Py is extracting string translations..."))
project.current.launch(args, wait=True)
interface.info(_("Ren'Py has finished extracting [language] string translations."))
jump front_page
label merge_strings:
call generate_translations_common
python:
language = persistent.translate_language
args = [ "merge_strings", language, get_strings_json() ]
if persistent.replace_translations:
args.append("--replace")
if persistent.reverse_languages:
args.append("--reverse")
interface.processing(_("Ren'Py is merging string translations..."))
project.current.launch(args, wait=True)
interface.info(_("Ren'Py has finished merging [language] string translations."))
jump front_page
label update_renpy_strings_common:
python:
language = _preferences.language
interface.processing(_("Updating default interface translations..."))
renpy.translation.extract.extract_strings_core(language, get_strings_json())
args = [ "translate", "None", "--common-only", "--strings-only", "--max-priority", "399", "--no-todo" ]
project.current.launch(args, wait=True)
args = [ "merge_strings", "None", get_strings_json() ]
project.current.launch(args, wait=True)
return
label update_renpy_strings:
call update_renpy_strings_common
jump front_page
screen extract_dialogue:
frame:
style_group "l"
style "l_root"
window:
has vbox
label _("Extract Dialogue: [project.current.display_name!q]")
add HALF_SPACER
frame:
style "l_indent"
xfill True
has vbox
add SEPARATOR2
frame:
style "l_indent"
has vbox
text _("Format:")
add HALF_SPACER
frame:
style "l_indent"
has vbox
textbutton _("Tab-delimited Spreadsheet (dialogue.tab)") action SetField(persistent, "dialogue_format", "tab")
textbutton _("Dialogue Text Only (dialogue.txt)") action SetField(persistent, "dialogue_format", "txt")
add SPACER
add SEPARATOR2
frame:
style "l_indent"
has vbox
text _("Options:")
add HALF_SPACER
textbutton _("Strip text tags from the dialogue.") action ToggleField(persistent, "dialogue_notags") style "l_checkbox"
textbutton _("Escape quotes and other special characters.") action ToggleField(persistent, "dialogue_escape") style "l_checkbox"
textbutton _("Extract all translatable strings, not just dialogue.") action ToggleField(persistent, "dialogue_strings") style "l_checkbox"
textbutton _("Cancel") action Jump("front_page") style "l_left_button"
textbutton _("Continue") action Jump("start_extract_dialogue") style "l_right_button"
label extract_dialogue:
call screen extract_dialogue
label start_extract_dialogue:
python:
args = [ "dialogue" ]
if persistent.dialogue_format == "txt":
args.append("--text")
if persistent.dialogue_strings:
args.append("--strings")
if persistent.dialogue_notags:
args.append("--notags")
if persistent.dialogue_escape:
args.append("--escape")
interface.processing(_("Ren'Py is extracting dialogue...."))
project.current.launch(args, wait=True)
project.current.update_dump(force=True)
interface.info(_("Ren'Py has finished extracting dialogue. The extracted dialogue can be found in dialogue.[persistent.dialogue_format] in the base directory."))
jump front_page
|