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

220 Bug: Translated footer is static and timestamp has another format #222

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 8 additions & 6 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ function getLastUpdate() {
const date = execSync("git log -1 --pretty=%cd --date=format:%Y-%m-%d")
.toString()
.trim();
return new Date(date).toLocaleDateString(undefined, {
year: "numeric",
month: "2-digit",
day: "2-digit",
});
return new Date(date)
.toLocaleDateString(undefined, {
year: "numeric",
month: "2-digit",
day: "2-digit",
})
.replace(/\//g, ".");
}

const config: Config = {
Expand Down Expand Up @@ -142,7 +144,7 @@ const config: Config = {
footer: {
style: "dark",
copyright: `Version <a href="https://github.com/mowi12/bierpongregeln/releases/tag/v${version}"
target="_blank" rel="noreferrer">${version}</a> (last update ${getLastUpdate()}) <br>
target="_blank" rel="noreferrer">${version}</a> (Letztes Update ${getLastUpdate()}) <br>
Copyright © ${new Date().getFullYear()} Felix Schlegel, Moritz Wieland. Built with Docusaurus.`,
},
prism: {
Expand Down
2 changes: 1 addition & 1 deletion i18n/en/docusaurus-theme-classic/footer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"copyright": {
"message": "Version <a href=\"https://github.com/mowi12/bierpongregeln/releases/tag/v2.9.0\"\n target=\"_blank\" rel=\"noreferrer\">2.9.0</a> (last update 01.12.2024) <br>\n Copyright © 2024 Felix Schlegel, Moritz Wieland. Built with Docusaurus.",
"message": "Version <a href=\"https://github.com/mowi12/bierpongregeln/releases/tag/v2.9.0\"\n target=\"_blank\" rel=\"noreferrer\">2.9.0</a> (Last Update 10.12.2024) <br>\n Copyright © 2024 Felix Schlegel, Moritz Wieland. Built with Docusaurus.",
"description": "The footer copyright"
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bierpongregeln",
"description": "This is a collection of rulesets for beer pong that is built using Docusaurus 2 and served with GitHub Pages.",
"version": "2.9.0",
"version": "2.9.2",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
Expand All @@ -11,7 +11,7 @@
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
"serve": "docusaurus serve",
"write-translations": "rm -f i18n/en/docusaurus-theme-classic/footer.json && docusaurus write-translations",
"write-translations": "python3 update-footer-en.py",
"write-heading-ids": "docusaurus write-heading-ids",
"validate-json": "ajv -s tournaments.schema.json -d tournaments.json",
"lint": "eslint .",
Expand Down
56 changes: 56 additions & 0 deletions scripts/update-footer-en.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import subprocess
import sys


# Step 1: Parse the locale from command-line arguments
def get_locale_from_args():
locale = "en" # Default locale
if "--locale" in sys.argv:
locale_index = sys.argv.index("--locale") + 1
if locale_index < len(sys.argv):
locale = sys.argv[locale_index]
return locale


locale = get_locale_from_args()
print(f"Using locale: {locale}")

# Define the file path
file_path = f"i18n/{locale}/docusaurus-theme-classic/footer.json"

# Step 2: Remove the file
if os.path.exists(file_path):
os.remove(file_path)
print(f"Removed file: {file_path}")
else:
print(f"File does not exist: {file_path}")

# Step 3: Run the 'docusaurus write-translations' command with the locale
try:
subprocess.run(["docusaurus", "write-translations", "--locale", locale], check=True)
print("Executed 'docusaurus write-translations' successfully.")
except subprocess.CalledProcessError as e:
print(f"Error running 'docusaurus write-translations': {e}")
exit(1)


# Step 4: Replace the string in the file
def replace_string_in_file(file_path, old_string, new_string):
if not os.path.exists(file_path):
print(f"File not found for replacement: {file_path}")
return

with open(file_path, "r", encoding="utf-8") as file:
content = file.read()

content = content.replace(old_string, new_string)

with open(file_path, "w", encoding="utf-8") as file:
file.write(content)

print(f"Replaced '{old_string}' with '{new_string}' in {file_path}")


# Replace 'Letztes Update' with 'Last Update'
replace_string_in_file(file_path, "Letztes Update", "Last Update")
File renamed without changes.
Loading