From 127289164043cc79ecfbffbbf75686976d7a3964 Mon Sep 17 00:00:00 2001 From: octospacc Date: Sun, 27 Nov 2022 23:50:22 +0100 Subject: [PATCH] Agg PicoBlog --- .gitignore | 1 + Pages/PicoBlog.md | 5 ++++ Scripts/Translate.py | 70 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100755 Scripts/Translate.py diff --git a/.gitignore b/.gitignore index 80b0a90..603f9e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +i18n/* public/* public.gmi/* public.plain/* diff --git a/Pages/PicoBlog.md b/Pages/PicoBlog.md index ec64e65..594850e 100644 --- a/Pages/PicoBlog.md +++ b/Pages/PicoBlog.md @@ -36,6 +36,11 @@ href='./PicoBlog.html'>disponibile qui. Considera di consultare quella per u +
+#### [2022-11-27] sitoctt introvabile, spero per non molto altro tempo +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:]}! 😁 diff --git a/Scripts/Translate.py b/Scripts/Translate.py new file mode 100755 index 0000000..b8e5704 --- /dev/null +++ b/Scripts/Translate.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +import hashlib +import os +import shutil +from pathlib import Path +from deepl import deepl + +SourceLang = 'it' +DestLangs = ['et', 'ja', 'lt', 'lv', 'de', 'hu', 'ru', 'zh', 'ro', 'da', 'it', 'es', 'nl', 'fr', 'sk', 'sl', 'pt', 'en', 'sv', 'fi', 'pl', 'el', 'bg', 'cs'] # All from output of `deepl --help` + +# With shutil.copytree copy only folder struct, no files; https://stackoverflow.com/a/15664273 +def IgnoreFiles(Dir, Files): + return [f for f in Files if os.path.isfile(os.path.join(Dir, f))] + +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] + return List + +def GetMetaComment(Paragraph, Num, Count): + return f'' + +def StrReverse(Str): + _ = list(Str) + _.reverse() + return ''.join(_) + +DestLangs.remove(SourceLang) +for Lang in DestLangs: + Translate = deepl.DeepLCLI(SourceLang, Lang) + for Dir in ('Pages', 'Posts/'): + shutil.copytree(Dir, f'i18n/{Lang}/{Dir}', ignore=IgnoreFiles, dirs_exist_ok=True) + + for File in FindTextFiles(): + with open(File, 'r') as f: + FullSource, Target, Trans = f.read(), '', '' + print(f'\n{Lang}/{File}:', end='') + + Paragraphs = StrReverse(FullSource).split('\n\n') + for i,Paragraph in enumerate(Paragraphs): # Assuming no single paragraph is > 5000 chars + print(f' {i}', end='') + Target = StrReverse(Paragraph) + #if len(Target+Paragraph) < 5000: + # Target += GetMetaComment(Paragraph, Num) + '\n' + Paragraph + '\n\n' + # #print(Paragraph) + # continue + #with open('Translate.tmp', 'w') as f: + # f.write(Target) + if not Target: # There were more than 2 line breaks + Trans += '\n\n' + continue + #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 + #Translate.translate(Paragraph) + #Trans += os.popen(f'cat ./Translate.tmp | deepl -s --fr {SourceLang} --to {Lang}').read() + print(Trans) + exit()