Skip to content

Commit 00b4dd6

Browse files
author
octospacc
committed
.
1 parent 8516703 commit 00b4dd6

11 files changed

+108
-51
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#/Scripts/package-lock.json
99
/Scripts/node_modules/*
1010
/Scripts.out/*
11+
/Scripts/Lib/translate-shell.bash
1112
*.pyc
1213
*.tmp
1314
tmp.*

Scripts/Package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cd "${swd}/.."
55
export sitocttEnv=Offline
66
export HUGO_ENV=production
77
sh "${swd}/Clean.sh"
8-
sh "${swd}/Update.sh"
8+
sh "${swd}/Build.sh"
99

1010
cd ./build/public
1111
#zip -9 -r ./offline.zip *

Scripts/Produce.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cd "${swd}/.."
44

55
export HUGO_ENV=production
66
sh "${swd}/Clean.sh"
7-
sh "${swd}/Update.sh"
7+
sh "${swd}/Build.sh"
88
sh "${swd}/Redirects.sh"
99

1010
cd "${owd}"

Scripts/Requirements.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,7 @@ cd ./Scripts
6161
PIP_BREAK_SYSTEM_PACKAGES=1 "${Python3}" -m pip install -U -r ./requirements.txt
6262
#npm install
6363

64+
cd ./Lib
65+
wget -O ./translate-shell.bash https://git.io/trans
66+
6467
cd "${owd}"

Scripts/Translate/Main.py

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python3
2-
DestinationLanguages = ["it", "en"] # "fr", "de", "eo", "es"
2+
DestinationLanguages = ["it", "en", "fr"] # "de", "eo", "es"
33
IncludePaths = ["/"]
4-
ExcludePaths = ["/Categories"]
4+
ExcludePaths = ["/categories"] # "/miscellanea"
55

6+
import subprocess
67
from os import getcwd, listdir
78
from os.path import dirname, realpath, isfile, isdir
89
from pathlib import Path
@@ -53,32 +54,63 @@ def find_documents(folder_path):
5354
documents[document].append(destination_language)
5455
return documents
5556

57+
def fix_frontmatter(translated_text, reference_text):
58+
result = ''
59+
reference_lines = reference_text.splitlines()
60+
for [index, translated_line] in enumerate(translated_text.splitlines()):
61+
if translated_line.strip() and (translated_line.lstrip() == translated_line):
62+
reference_line = reference_lines[index]
63+
line_key = reference_line.split('=')[0]
64+
if line_key.strip().lower() in ["draft", "date", "lastmod"]:
65+
translated_line = reference_line
66+
else:
67+
line_value = '='.join(translated_line.split('=')[1:])
68+
translated_line = line_key
69+
if line_value:
70+
translated_line += ('=' + line_value)
71+
result += (translated_line + '\n')
72+
return result
73+
5674
def translate_document(document_path, documents):
57-
printf(f'* {document_path} ->')
75+
printf(f"* {document_path} ->")
5876
for destination_language in documents[document_path]:
5977
source_language = get_source_language(document_path)
78+
original_text = open(("../content/" + document_path), 'r').read()
6079
printf('', destination_language)
6180
try:
62-
translated = translate(
63-
open(('../content/' + document_path), 'r').read(),
64-
destination_language,
65-
source_language)
81+
is_python_translator = True
82+
translated = translate(original_text, destination_language, source_language)
6683
if not len(translated.results):
6784
raise Exception("Unhandled error")
68-
printf('✅')
6985
except Exception as exception:
7086
printf('❌', exception)
71-
continue
72-
translated_text = translated.results[0].paraphrase
87+
try:
88+
is_python_translator = False
89+
translated = subprocess.run(
90+
("bash", "../Scripts/Lib/translate-shell.bash", "-brief",
91+
"-t", destination_language, "-s", source_language,
92+
("file://" + "../content/" + document_path)),
93+
stdout=subprocess.PIPE,
94+
stderr=subprocess.PIPE)
95+
if translated.stderr:
96+
raise Exception(translated.stderr.decode())
97+
except Exception as exception:
98+
printf('❌', exception)
99+
continue
100+
printf('✅')
101+
translated_text = (translated.results[0].paraphrase
102+
if is_python_translator else translated.stdout.decode())
73103
text_header = translated_text.strip().splitlines()[0].strip()
74104
translated_preamble = ("\n\n{{< noticeAutomaticTranslation " + source_language + " >}}\n\n")
75105
if text_header in ["---", "+++"]:
76106
text_tokens = translated_text.split(text_header)
77-
translated_text = (
78-
text_header + text_tokens[1] + text_header +
79-
translated_preamble +
80-
text_header.join(text_tokens[2:]))
81-
else:
107+
translated_body = text_header.join(text_tokens[2:])
108+
translated_text = (text_header +
109+
fix_frontmatter(text_tokens[1], original_text.split(text_header)[1]) +
110+
text_header)
111+
if translated_body.strip():
112+
translated_text += (translated_preamble + translated_body)
113+
elif translated_text.strip():
82114
translated_text = (translated_preamble + translated_text)
83115
destination_path = make_destination_path(document_path, destination_language)
84116
Path('/'.join(destination_path.split('/')[:-1])).mkdir(parents=True, exist_ok=True)

assets/ButtonBadges.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ alt = "✨sitoctt"
3535
file = "Sites/sitoctt-1.png"
3636
href = "/it/miscellanea/Raccolta-Siti-Internet/#il-mio"
3737

38+
[[10-site]]
39+
alt = "Sign my guestoobk"
40+
file = "Sign-guestbook.gif"
41+
href = "https://listed.to/@u8/guestbook"
42+
3843
[[10-site]]
3944
alt = "Warning: Page contains JavaScript!"
4045
file = "Warning-Page-contains-JavaScript.png"

content/it/blog/2023-04-16-Che-Impatto-Nuova-Legge-Anti-Pirateria-Italiana.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Date = 2023-04-16
44
Downsync = "/it/blog/Che-Impatto-Nuova-Legge-Anti-Pirateria-Italiana.html"
55
Aliases = [ "/Posts/2023-04-16-Che-Impatto-Nuova-Legge-Anti-Pirateria-Italiana.html" ]
66
Description = "Hanno approvato in Italia una legge per un contrasto forte alla pirateria. Il fatto è che comporta rischi importanti per gli internauti."
7+
Featured_Image = "@/Media/Misc/Keep-Seeding-Monitor.webp"
78
Categories = [ "Internet" ]
89
Lastmod = 2023-04-17
910
+++
@@ -85,5 +86,3 @@ Forse non si obietterebbe granché nemmeno se, andando contro le piattaforme che
8586
<p>Ma in Italia hanno già fatto <em>saltare in aria</em> TNTVillage, e io non voglio la <strong>decimazione</strong> anche di tutte le altre <strong>piazze online</strong> create <strong>dalla gente per la gente</strong> - senza scopo di lucro, e anzi <strong>spesso a perdere</strong>, sia in tempo che in denaro - solo perché <strong>a qualcuno da fastidio</strong> che si utilizzi la <strong>funzionalità principale del Web</strong>: i collegamenti ipertestuali, inventati per favorire la <strong>condivisione libera e gratuita</strong> di cultura ed intrattenimento, <strong>senza barriere</strong>.</p>
8687

8788
<hr>
88-
89-
<p><img src="{{< assetsRoot >}}/Media/Misc/Keep-Seeding-Monitor.webp" alt="&quot;Keep seeding&quot;"></p>

content/it/blog/2024-06-22-Diari-Blog-Social-Riflessione.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Il diario segreto, inteso come un quaderno o un taccuino in cui si annotano pens
134134

135135
<h2>{{% i18n notes-refs %}}</h2>
136136

137-
<p><em>L'immagine decorativa di copertina è ottenuta tramite <a href="https://www.bing.com/images/create/a-used2c-ruined-diary-book2c-floating-in-the-air-abo/1-6676dc0085154dc0af66cfe0083bfbc1?id=ik6UsyrKqidtvAmyv7FwFw%3d%3d&amp;view=detailv2&amp;idpp=genimg&amp;thId=OIG2.b9jZ_Y2byFXVtqOG86OY&amp;FORM=GCRIDP&amp;mode=overlay" rel="noopener nofollow" target="_blank">l'intelligenza artificiale generativa di Microsoft</a>.</em></p>
137+
<p><em>L'immagine decorativa di copertina è ottenuta tramite <a href="https://www.bing.com/images/create/a-used2c-ruined-diary-book2c-floating-in-the-air-abo/1-6676dc0085154dc0af66cfe0083bfbc1?id=%2Bsy5Em%2B0Qfp%2Bei%2BELZ579w%3D%3D&amp;view=detailv2&amp;idpp=genimg&amp;thid=OIG2.b9jZ_Y2byFXVtqOG86OY&amp;form=GCRIDP" rel="noopener nofollow" target="_blank">l'intelligenza artificiale generativa di Microsoft</a>.</em></p>
138138

139139
<div class="footnotes">
140140
<ol>

content/it/blog/Archive/2022-05-07-Gli-Inaspettati-Vantaggi-della-Chiavetta-Linux.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Aliases = [
44
"/Posts/Archive/2022-05-07-Gli-Inaspettati-Vantaggi-della-Chiavetta-Linux.html",
55
]
66
Categories = [ "Tecnologia" ]
7-
Data = 2022-05-07
7+
Date = 2022-05-07
88
Lastmod = 2022-08-13
99
#Template = "loli-documentatrice.html"
1010
+++
@@ -93,4 +93,4 @@ Riporto qui i siti Web di alcune distribuzioni che _non_ ho menzionato nel testo
9393

9494
### 🏷️ Note/Riferimenti
9595

96-
[^ Aggiornamento 2022-08-13]: **Aggiornamento del 2022-08-13**: Ho importato questo articolo dal mio vecchio blog (<https://noblogo.org/loli-documentatrice/gli-inaspettati-vantaggi-della-chiavetta-linux>), per preservarlo meglio e per testare alcune cose. Ne ho approfittato per, oltre a migliorare la formattazione, cambiare in parte la forma di alcune frasi. Il contenuto resta praticamente uguale.
96+
**Aggiornamento del 2022-08-13**: Ho importato questo articolo dal mio vecchio blog (<https://noblogo.org/loli-documentatrice/gli-inaspettati-vantaggi-della-chiavetta-linux>), per preservarlo meglio e per testare alcune cose. Ne ho approfittato per, oltre a migliorare la formattazione, cambiare in parte la forma di alcune frasi. Il contenuto resta praticamente uguale.

0 commit comments

Comments
 (0)