generated from DRincs-Productions/renpy-translations-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tool-only' of https://github.com/DRincs-Productions/ren…
…py-translations-templete into translations-templete
- Loading branch information
Showing
7 changed files
with
271 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
files: | ||
- source: /game/tl/crowdin/*.po | ||
ignore: | ||
- /game/tl/crowdin/common.* | ||
translation: /game/tl/%language%/%original_file_name% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
translate french strings: | ||
|
||
# renpy/common/00accessibility.rpy:28 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
translate german strings: | ||
|
||
# renpy/common/00accessibility.rpy:28 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
translate italian strings: | ||
|
||
# renpy/common/00accessibility.rpy:28 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
translate spanish strings: | ||
|
||
# renpy/common/00accessibility.rpy:28 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import os | ||
import re | ||
import shutil | ||
from fileinput import FileInput | ||
from glob import glob | ||
|
||
# ATTENTION: there must not be 2 equal key or value | ||
# regex: https://www.w3schools.com/python/python_regex.asp | ||
dict = { | ||
# search_text : replace_text | ||
# start | ||
r'\n"Plural-Forms(.*)': r'', | ||
r'\n"X-Crowdin-Pr(.*)': r'', | ||
r'\n"X-Crowdin-Pr(.*)': r'', | ||
r'\n"X-Crowdin-La(.*)': r'', | ||
r'\n"X-Crowdin-Fi(.*)': r'', | ||
r'\n"X-Crowdin-Fi(.*)': r'', | ||
r'\n"Project-Id-V(.*)': r'', | ||
r'\n"Content-Type(.*)': r'', | ||
r'\n"Language-Tea(.*)': r'', | ||
r'\n"Language:(.*)': r'', | ||
r'\n"PO-Revision-(.*)': r'', | ||
r'\n"Большой(.*)': r'', | ||
r'msgid ""\nmsgstr ""': r'', | ||
r'\\n"\n"': r'\\n', | ||
r'\\'+'"': r'§§§§§§§§', | ||
# Effect | ||
r' \[nointeract\]"': r'" nointeract', | ||
r' \[withfade\]"': r'" with fade', | ||
r' \[withdissolve\]"': r'" with dissolve', | ||
r' \[withslowdissolve\]"': r'" with slowdissolve', | ||
r' \[withhpunch\]"': r'" with hpunch', | ||
r' \[withflash\]"': r'" with flash', | ||
r' \[withvpunch\]"': r'" with vpunch', | ||
r' \[withDissolve20\]"': r'" with Dissolve(2.0)', | ||
r' \[withDissolve1\]"': r'" with Dissolve(1)', | ||
r' \[withDissolvey3\]"': r'" with Dissolve(.3)', | ||
r' \[multiple2\]"': r'" (multiple=2)', | ||
r'msgid "\[nvl_clear\]"': r' # nvl clear', | ||
r'msgstr "\[nvl_clear\]"': r' nvl clear', | ||
# first | ||
r'msgid "(.*?) \[special_delimiter\] (.*?)"': r' # "\1" "\2"', | ||
r'msgstr "(.*?) \[special_delimiter\] (.*?)"': r' "\1" "\2"', | ||
r':\nmsgid "(.*?)"': r':\n # "\1"', | ||
r' #(.*?)\nmsgstr "\[_(.*?)\_] (.*?)"': r' #\1\n \2 "\3"', | ||
r' #(.*?)\nmsgstr "\[_(.*?)\_](.*?)"': r' #\1\n \2 "\3"', | ||
r' # (.*?)\nmsgstr "(.*?)"': r' # \1\n "\2"', | ||
# after | ||
r' # "\[_(.*?)\_] (.*?)"': r' # \1 "\2"', | ||
# Comment | ||
r':\n # ': r':\n\n # ', | ||
r'rpy:(.*?) #-#-# translate': r'rpy:\1\ntranslate', | ||
r'strings: #\|#\|# # ': r'strings:\n\n# ', | ||
r'updated at (.*?)-(.*?)-(.*?) (.*?):(.*?) #\|#\|# # ': r'updated at \1-\2-\3 \4:\5\n\n# ', | ||
# end | ||
r'msgid "(.*?)"': r' old "\1"', | ||
r'msgstr "(.*?)"': r' new "\1"', | ||
r'\n#(.*?)\n old "': r'\n #\1\n old "', | ||
r'\n\n# TODO: Translation updated': r'# TODO: Translation updated', | ||
r'§§§§§§§§': r'\\'+'"', | ||
r'# TODO: Translation updated at (.*?)-(.*?)-(.*?) (.*?):(.*?) #\|#\|# # §translate ': r'# TODO: Translation updated at \1-\2-\3 \4:\5\n\ntranslate ', | ||
r'\n# §translate': r'\ntranslate', | ||
} | ||
|
||
|
||
# Creating a function to replace the text | ||
def replacetext(search_text, replace_text, pathFile, languege): | ||
|
||
# Read in the file | ||
with open(pathFile, "r+", encoding="utf8") as file: | ||
filedata = file.read() | ||
|
||
# c = re.compile(search_text) | ||
|
||
# Replace the target string | ||
# filedata = filedata.replace(search_text, replace_text) | ||
filedata = re.sub(search_text, replace_text, filedata) | ||
# TODO: to improve | ||
filedata = re.sub(r'"\n (.*?)_s_(.*?) "', | ||
r'"\n \1 \2 "', filedata) | ||
filedata = re.sub(r'"\n (.*?)_s_(.*?) "', | ||
r'"\n \1 \2 "', filedata) | ||
filedata = re.sub(r'"\n (.*?)_s_(.*?) "', | ||
r'"\n \1 \2 "', filedata) | ||
filedata = re.sub(r'"\n (.*?)_s_(.*?) "', | ||
r'"\n \1 \2 "', filedata) | ||
filedata = re.sub(r'"\n (.*?)_s_(.*?) "', | ||
r'"\n \1 \2 "', filedata) | ||
filedata = re.sub(r'"\n (.*?)_s_(.*?) "', | ||
r'"\n \1 \2 "', filedata) | ||
filedata = re.sub(r'"\n (.*?)_s_(.*?) "', | ||
r'"\n \1 \2 "', filedata) | ||
filedata = re.sub(r'"\n (.*?)_s_(.*?) "', | ||
r'"\n \1 \2 "', filedata) | ||
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "', | ||
r':\n\n # \1 \2 "', filedata) | ||
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "', | ||
r':\n\n # \1 \2 "', filedata) | ||
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "', | ||
r':\n\n # \1 \2 "', filedata) | ||
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "', | ||
r':\n\n # \1 \2 "', filedata) | ||
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "', | ||
r':\n\n # \1 \2 "', filedata) | ||
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "', | ||
r':\n\n # \1 \2 "', filedata) | ||
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "', | ||
r':\n\n # \1 \2 "', filedata) | ||
filedata = re.sub(r':\n\n # (.*?)_s_(.*?) "', | ||
r':\n\n # \1 \2 "', filedata) | ||
filedata = re.sub(r'crowdin', languege, filedata) | ||
|
||
# Write the file out again | ||
with open(pathFile, 'w', encoding="utf8") as file: | ||
file.write(filedata) | ||
return True | ||
|
||
|
||
def replaceDictionary(pathFile, dict={}, languege="crowdin"): | ||
newpathFile = fileRename(pathFile, extension=".rpy") | ||
print(pathFile) | ||
for search_text in dict.keys(): | ||
replacetext(pathFile=newpathFile, search_text=search_text, | ||
replace_text=dict[search_text], languege=languege) | ||
|
||
|
||
def getListFiles(extension, languege="**"): | ||
# Get the list of all files and directories | ||
path = "game/tl/" | ||
dir_list = glob(path + languege+"/*"+extension, recursive=True) | ||
if languege != "**": | ||
dir_list = dir_list + \ | ||
glob(path + languege+"/**/*"+extension, recursive=True) | ||
return dir_list | ||
|
||
|
||
def potorpy(languege): | ||
for path in getListFiles(extension=".po", languege=languege): | ||
replaceDictionary(path, dict=dict, languege=languege) | ||
|
||
|
||
def fileRename(pathFile, extension): | ||
pre, ext = os.path.splitext(pathFile) | ||
shutil.copyfile(pathFile, pre + extension) | ||
return pre + extension | ||
|
||
|
||
potorpy("italian") | ||
potorpy("french") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
from fileinput import FileInput | ||
from glob import glob | ||
import os | ||
import shutil | ||
import re | ||
|
||
# ATTENTION: there must not be 2 equal key or value | ||
# regex: https://www.w3schools.com/python/python_regex.asp | ||
dict = { | ||
# search_text : replace_text | ||
# start | ||
r'\\'+'"': r'§§§§§§§§', | ||
# Effect | ||
r'" nointeract': r' [nointeract]"', | ||
r'" with fade': r' [withfade]"', | ||
r'" with dissolve': r' [withdissolve]"', | ||
r'" with slowdissolve': r' [withslowdissolve]"', | ||
r'" with hpunch': r' [withhpunch]"', | ||
r'" with flash': r' [withflash]"', | ||
r'" with vpunch': r' [withvpunch]"', | ||
r'" with Dissolve\(2.0\)': r' [withDissolve20]"', | ||
r'" with Dissolve\(1\)': r' [withDissolve1]"', | ||
r'" with Dissolve\(.3\)': r' [withDissolvey3]"', | ||
r'" \(multiple=2\)': r' [multiple2]"', | ||
r' # nvl clear': r'msgid "[nvl_clear]"', | ||
r' nvl clear': r'msgstr "[nvl_clear]"', | ||
# first | ||
r' # "(.*?)" "(.*?)"': r'msgid "\1 [special_delimiter] \2"', | ||
r' "(.*?)" "(.*?)"': r'msgstr "\1 [special_delimiter] \2"', | ||
r' #': r'#', | ||
r' old "(.*?)"': r'msgid "\1"', | ||
r' new "(.*?)"': r'msgstr "\1"', | ||
# find: # (.*?) "(.*?)" | ||
# replace:msgid "[$1] $2" | ||
r'# (.*?) "(.*?)"': r'msgid "[_\1_] \2"', | ||
# after | ||
# find: (.*?) "(.*?)" | ||
# replace:msgstr "[$1] $2" | ||
r' (.*?) "(.*?)"': r'msgstr "[_\1_] \2"', | ||
r'# "(.*?)"': r'msgid "\1"', | ||
r' "(.*?)"': r'msgstr "\1"', | ||
# Comment | ||
r':\n\nmsgid': r':\nmsgid', | ||
r'rpy:(.*?)\ntranslate': r'rpy:\1 #-#-# translate', | ||
r'strings:\n\n# ': r'strings: #|#|# # ', | ||
r'\ntranslate': r'\n# §translate', | ||
r'updated at (.*?)-(.*?)-(.*?) (.*?):(.*?)\n\n# ': r'updated at \1-\2-\3 \4:\5 #|#|# # ', | ||
# end | ||
r'§§§§§§§§': r'\\'+'"', | ||
} | ||
|
||
|
||
# Creating a function to replace the text | ||
def replacetext(search_text, replace_text, pathFile): | ||
|
||
# Read in the file | ||
with open(pathFile, "r+", encoding="utf8") as file: | ||
filedata = file.read() | ||
|
||
# c = re.compile(search_text) | ||
|
||
# Replace the target string | ||
# filedata = filedata.replace(search_text, replace_text) | ||
filedata = re.sub(search_text, replace_text, filedata) | ||
# TODO: to improve | ||
filedata = re.sub(r'\[_(.*?)\b (.*?)_\]', r'[_\1_s_\2_]', filedata) | ||
filedata = re.sub(r'\[_(.*?)\b (.*?)_\]', r'[_\1_s_\2_]', filedata) | ||
filedata = re.sub(r'\[_(.*?)\b (.*?)_\]', r'[_\1_s_\2_]', filedata) | ||
filedata = re.sub(r'\[_(.*?)\b (.*?)_\]', r'[_\1_s_\2_]', filedata) | ||
filedata = re.sub(r'\[_(.*?)\b (.*?)_\]', r'[_\1_s_\2_]', filedata) | ||
filedata = re.sub(r'\[_(.*?)\b (.*?)_\]', r'[_\1_s_\2_]', filedata) | ||
filedata = re.sub(r'\[_(.*?)\b (.*?)_\]', r'[_\1_s_\2_]', filedata) | ||
filedata = re.sub(r'\[_(.*?)\b (.*?)_\]', r'[_\1_s_\2_]', filedata) | ||
|
||
# Write the file out again | ||
with open(pathFile, 'w', encoding="utf8") as file: | ||
file.write(filedata) | ||
return True | ||
|
||
|
||
def replaceDictionary(pathFile, dict={}, reverse=False): | ||
newpathFile = fileRename(pathFile, extension=".po") | ||
print(pathFile) | ||
if(reverse): | ||
for item in reversed(list(dict.items())): | ||
replacetext(pathFile=newpathFile, | ||
search_text=item[1], replace_text=item[0]) | ||
else: | ||
for search_text in dict.keys(): | ||
replacetext(pathFile=newpathFile, search_text=search_text, | ||
replace_text=dict[search_text]) | ||
|
||
|
||
def getListFiles(extension=".po"): | ||
# Get the list of all files and directories | ||
path = "game/tl/" | ||
dir_list = glob(path + "/**/*"+extension, recursive=True) | ||
return dir_list | ||
|
||
|
||
def rpytopo(): | ||
for path in getListFiles(extension=".rpy"): | ||
replaceDictionary(path, dict=dict) | ||
|
||
|
||
def potorpy(): | ||
for path in getListFiles(): | ||
replaceDictionary(path, dict=dict, reverse=True) | ||
|
||
|
||
def fileRename(pathFile, extension=".rpy"): | ||
pre, ext = os.path.splitext(pathFile) | ||
shutil.copyfile(pathFile, pre + extension) | ||
return pre + extension | ||
|
||
|
||
rpytopo() |