From 4c3430fa6271b9c02e8383f55fdcdaa355d7be8d Mon Sep 17 00:00:00 2001 From: octospacc Date: Sat, 3 Dec 2022 15:12:36 +0100 Subject: [PATCH] Salv. script traduzione --- Pages/PicoBlog.md | 2 +- Pages/index.pug | 6 +- ...9-18-Aggirare-i-DRM-dei-Libri-di-Scuola.md | 3 + Scripts/Translate.py | 56 ++++++++++++------- 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/Pages/PicoBlog.md b/Pages/PicoBlog.md index 594850e..bff58ee 100644 --- a/Pages/PicoBlog.md +++ b/Pages/PicoBlog.md @@ -41,7 +41,7 @@ href='./PicoBlog.html'>disponibile qui. Considera di consultare quella per u Ho notato che il sitoctt, anche dopo alcune mie misure che avrebbero dovuto far contenti i motori di ricerca, proprio non si trova.. e non ho alcuna idea abbastanza precisa su cosa causi il problema. Devo iniziare a integrare nel generatore una funzione per ripubblicare in automatico su Wordpress, Blogger, e roba di quel tipo, magari da lì i motori lo leggono meglio; intanto, ho iniziato a fare lo script per tradurre il sito in diverse lingue, e questo dovrebbe aiutare a diffonderlo al di fuori dell'Italia. -
+
#### [2022-11-18] Finalmente ho il MIO Misskey Ci avevo provato mesi fa ad ospitare il mio server ActivityPub. Prima Friendica su Altervista.. non andava. Poi Misskey, Mastodon, e Pleroma su Switch in casa.. fallimenti, l'uno più grosso dell'altro. Poi, l'altro giorno sul Raspino ho voluto riprovarci; i problemi sono usciti eccome, ma stavolta li ho saputi risolvere nell'arco di un giorno di lavoro, e quindi adesso ho [il mio Regno del Terrore](https://miss.octt.eu.org){[:MdTgtBlank:]}! 😁 Ho aggiunto il mio profilo alla [pagina dei contatti](./Chi-Sono.html#-I-miei-contatti) qui... e ho sistemato una roba che avevo dimenticato di cancellare praticamente da agosto: la menzione al server Matrix, che ormai non ho più. 🙄 diff --git a/Pages/index.pug b/Pages/index.pug index f4b0f95..65549ea 100644 --- a/Pages/index.pug +++ b/Pages/index.pug @@ -5,7 +5,7 @@ // % Index = True // % Order = 10 // % Image = [staticoso:Folder:Assets:AbsoluteRoot]/RichPreview/index.png -// % UpdatedOn = 2022-10-27 +// % UpdatedOn = 2022-12-03 h1 Ciao!! (UwU) @@ -230,6 +230,8 @@ p br | Ah, si, sto dicendo "#[i altre cosette]" perché si tratta di roba che al momento della scrittura di questo capitolo della pagina è assente o incompleta, e scrivendo come scrivo mi paro le chiappette e non devo fare future modifiche. #[pre(class='Inline') #[i H e h .]] +h4 Prendi tutto! + p | Per terminare, trovate tutti i miei sorgenti sulle rispettive repo Git. br @@ -279,4 +281,4 @@ div#RingsDiv br hr -small(style="Float:Right; Opacity:0.7;"): i ❤️ Copying is an act of love. Please copy and share. +small(style="Float:Right; Opacity:0.7;"): i ❤️ Copying is an act of love. Please copy and share. diff --git a/Posts/Notes/2022-09-18-Aggirare-i-DRM-dei-Libri-di-Scuola.md b/Posts/Notes/2022-09-18-Aggirare-i-DRM-dei-Libri-di-Scuola.md index 68ad28b..13a2368 100644 --- a/Posts/Notes/2022-09-18-Aggirare-i-DRM-dei-Libri-di-Scuola.md +++ b/Posts/Notes/2022-09-18-Aggirare-i-DRM-dei-Libri-di-Scuola.md @@ -1,6 +1,9 @@ // % Categories = Note // % CreatedOn = 2022-09-18 // % EditedOn = 2022-09-19 +// % Index: None + + # Aggirare i DRM dei libri di scuola **(in una maniera che probabilmente rende possibile l'operazione anche per testi non-scolastici.)** diff --git a/Scripts/Translate.py b/Scripts/Translate.py index b8e5704..06e0d35 100755 --- a/Scripts/Translate.py +++ b/Scripts/Translate.py @@ -2,6 +2,7 @@ import hashlib import os import shutil +import time from pathlib import Path from deepl import deepl @@ -14,20 +15,34 @@ def IgnoreFiles(Dir, Files): def FindTextFiles(): List = [] - for Dir in ('Pages/', 'Posts/'): - for Ext in ('htm', 'html', 'markdown', 'md', 'pug', 'txt'): - for File in Path(Dir).rglob(f'*.{Ext}'): - List += [File] + #for Dir in ('Posts/'): #('Pages/', 'Posts/'): + for Ext in ('htm', 'html', 'markdown', 'md', 'pug', 'txt'): + for File in Path(Dir).rglob(f'*.{Ext}'): + List += [File] return List -def GetMetaComment(Paragraph, Num, Count): - return f'' +def GetMetaComment(Paragraph, Num, Count, Translation=None): + return f'' def StrReverse(Str): _ = list(Str) _.reverse() return ''.join(_) +def TryTranslate(Text): + try: + #Trans += GetMetaComment(Target, i) + '\n' + Translate.translate(Target) + '\n\n' + #Trans = GetMetaComment(Target, i, len(Paragraphs)) + '\n' + Translate.translate(Target) + '\n\n' + Trans + return Translate.translate(Text) + #Target = '' + #except deepl.DeepLCLIPageLoadError: + # raise + except Exception as e: + print(e) + return False + #Trans += GetMetaComment(Target, i) + '\n' + Target + '\n\n' + #Trans = GetMetaComment(Target, i, len(Paragraphs)) + '\n' + Target + '\n\n' + Trans + DestLangs.remove(SourceLang) for Lang in DestLangs: Translate = deepl.DeepLCLI(SourceLang, Lang) @@ -35,6 +50,9 @@ for Lang in DestLangs: shutil.copytree(Dir, f'i18n/{Lang}/{Dir}', ignore=IgnoreFiles, dirs_exist_ok=True) for File in FindTextFiles(): + if os.path.isfile(f'i18n/{Lang}/{File}'): # Skip already translated pages - This will evolve into a skip only if not updated + continue + with open(File, 'r') as f: FullSource, Target, Trans = f.read(), '', '' print(f'\n{Lang}/{File}:', end='') @@ -42,6 +60,7 @@ for Lang in DestLangs: Paragraphs = StrReverse(FullSource).split('\n\n') for i,Paragraph in enumerate(Paragraphs): # Assuming no single paragraph is > 5000 chars print(f' {i}', end='') + Backoff = 0 Target = StrReverse(Paragraph) #if len(Target+Paragraph) < 5000: # Target += GetMetaComment(Paragraph, Num) + '\n' + Paragraph + '\n\n' @@ -52,19 +71,18 @@ for Lang in DestLangs: if not Target: # There were more than 2 line breaks Trans += '\n\n' continue + Done = '' + while not Done: + time.sleep(5 + (Backoff*1.25)) + Backoff += 1.25 + Done = TryTranslate(Target) + Trans = GetMetaComment(Target, i, len(Paragraphs), Done) + '\n' + Done + '\n\n' + Trans #while True: - try: - #Trans += GetMetaComment(Target, i) + '\n' + Translate.translate(Target) + '\n\n' - Trans = GetMetaComment(Target, i, len(Paragraphs)) + '\n' + Translate.translate(Target) + '\n\n' + Trans - Target = '' - except deepl.DeepLCLIPageLoadError: - raise - except Exception as e: - print(e) - #Trans += GetMetaComment(Target, i) + '\n' + Target + '\n\n' - Trans = GetMetaComment(Target, i, len(Paragraphs)) + '\n' + Target + '\n\n' + Trans - #continue + #continue #Translate.translate(Paragraph) #Trans += os.popen(f'cat ./Translate.tmp | deepl -s --fr {SourceLang} --to {Lang}').read() - print(Trans) - exit() + + with open(f'i18n/{Lang}/{File}', 'w') as f: + f.write(Trans) + #print(Trans) + #exit()