Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
octospacc committed Sep 2, 2024
1 parent 8516703 commit 00b4dd6
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#/Scripts/package-lock.json
/Scripts/node_modules/*
/Scripts.out/*
/Scripts/Lib/translate-shell.bash
*.pyc
*.tmp
tmp.*
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cd "${swd}/.."
export sitocttEnv=Offline
export HUGO_ENV=production
sh "${swd}/Clean.sh"
sh "${swd}/Update.sh"
sh "${swd}/Build.sh"

cd ./build/public
#zip -9 -r ./offline.zip *
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Produce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cd "${swd}/.."

export HUGO_ENV=production
sh "${swd}/Clean.sh"
sh "${swd}/Update.sh"
sh "${swd}/Build.sh"
sh "${swd}/Redirects.sh"

cd "${owd}"
3 changes: 3 additions & 0 deletions Scripts/Requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ cd ./Scripts
PIP_BREAK_SYSTEM_PACKAGES=1 "${Python3}" -m pip install -U -r ./requirements.txt
#npm install

cd ./Lib
wget -O ./translate-shell.bash https://git.io/trans

cd "${owd}"
62 changes: 47 additions & 15 deletions Scripts/Translate/Main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python3
DestinationLanguages = ["it", "en"] # "fr", "de", "eo", "es"
DestinationLanguages = ["it", "en", "fr"] # "de", "eo", "es"
IncludePaths = ["/"]
ExcludePaths = ["/Categories"]
ExcludePaths = ["/categories"] # "/miscellanea"

import subprocess
from os import getcwd, listdir
from os.path import dirname, realpath, isfile, isdir
from pathlib import Path
Expand Down Expand Up @@ -53,32 +54,63 @@ def find_documents(folder_path):
documents[document].append(destination_language)
return documents

def fix_frontmatter(translated_text, reference_text):
result = ''
reference_lines = reference_text.splitlines()
for [index, translated_line] in enumerate(translated_text.splitlines()):
if translated_line.strip() and (translated_line.lstrip() == translated_line):
reference_line = reference_lines[index]
line_key = reference_line.split('=')[0]
if line_key.strip().lower() in ["draft", "date", "lastmod"]:
translated_line = reference_line
else:
line_value = '='.join(translated_line.split('=')[1:])
translated_line = line_key
if line_value:
translated_line += ('=' + line_value)
result += (translated_line + '\n')
return result

def translate_document(document_path, documents):
printf(f'* {document_path} ->')
printf(f"* {document_path} ->")
for destination_language in documents[document_path]:
source_language = get_source_language(document_path)
original_text = open(("../content/" + document_path), 'r').read()
printf('', destination_language)
try:
translated = translate(
open(('../content/' + document_path), 'r').read(),
destination_language,
source_language)
is_python_translator = True
translated = translate(original_text, destination_language, source_language)
if not len(translated.results):
raise Exception("Unhandled error")
printf('✅')
except Exception as exception:
printf('❌', exception)
continue
translated_text = translated.results[0].paraphrase
try:
is_python_translator = False
translated = subprocess.run(
("bash", "../Scripts/Lib/translate-shell.bash", "-brief",
"-t", destination_language, "-s", source_language,
("file://" + "../content/" + document_path)),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if translated.stderr:
raise Exception(translated.stderr.decode())
except Exception as exception:
printf('❌', exception)
continue
printf('✅')
translated_text = (translated.results[0].paraphrase
if is_python_translator else translated.stdout.decode())
text_header = translated_text.strip().splitlines()[0].strip()
translated_preamble = ("\n\n{{< noticeAutomaticTranslation " + source_language + " >}}\n\n")
if text_header in ["---", "+++"]:
text_tokens = translated_text.split(text_header)
translated_text = (
text_header + text_tokens[1] + text_header +
translated_preamble +
text_header.join(text_tokens[2:]))
else:
translated_body = text_header.join(text_tokens[2:])
translated_text = (text_header +
fix_frontmatter(text_tokens[1], original_text.split(text_header)[1]) +
text_header)
if translated_body.strip():
translated_text += (translated_preamble + translated_body)
elif translated_text.strip():
translated_text = (translated_preamble + translated_text)
destination_path = make_destination_path(document_path, destination_language)
Path('/'.join(destination_path.split('/')[:-1])).mkdir(parents=True, exist_ok=True)
Expand Down
5 changes: 5 additions & 0 deletions assets/ButtonBadges.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ alt = "✨sitoctt"
file = "Sites/sitoctt-1.png"
href = "/it/miscellanea/Raccolta-Siti-Internet/#il-mio"

[[10-site]]
alt = "Sign my guestoobk"
file = "Sign-guestbook.gif"
href = "https://listed.to/@u8/guestbook"

[[10-site]]
alt = "Warning: Page contains JavaScript!"
file = "Warning-Page-contains-JavaScript.png"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Date = 2023-04-16
Downsync = "/it/blog/Che-Impatto-Nuova-Legge-Anti-Pirateria-Italiana.html"
Aliases = [ "/Posts/2023-04-16-Che-Impatto-Nuova-Legge-Anti-Pirateria-Italiana.html" ]
Description = "Hanno approvato in Italia una legge per un contrasto forte alla pirateria. Il fatto è che comporta rischi importanti per gli internauti."
Featured_Image = "@/Media/Misc/Keep-Seeding-Monitor.webp"
Categories = [ "Internet" ]
Lastmod = 2023-04-17
+++
Expand Down Expand Up @@ -85,5 +86,3 @@ Forse non si obietterebbe granché nemmeno se, andando contro le piattaforme che
<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>

<hr>

<p><img src="{{< assetsRoot >}}/Media/Misc/Keep-Seeding-Monitor.webp" alt="&quot;Keep seeding&quot;"></p>
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Il diario segreto, inteso come un quaderno o un taccuino in cui si annotano pens

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

<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>
<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>

<div class="footnotes">
<ol>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Aliases = [
"/Posts/Archive/2022-05-07-Gli-Inaspettati-Vantaggi-della-Chiavetta-Linux.html",
]
Categories = [ "Tecnologia" ]
Data = 2022-05-07
Date = 2022-05-07
Lastmod = 2022-08-13
#Template = "loli-documentatrice.html"
+++
Expand Down Expand Up @@ -93,4 +93,4 @@ Riporto qui i siti Web di alcune distribuzioni che _non_ ho menzionato nel testo

### 🏷️ Note/Riferimenti

[^ 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.
**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.
Loading

0 comments on commit 00b4dd6

Please sign in to comment.