Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ coverage.xml
cover/

# Translations
*.mo
*.po
*.pot

# Django stuff:
Expand Down
1 change: 1 addition & 0 deletions babel.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[python: **.py]
19 changes: 19 additions & 0 deletions bin/translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3
import sys

import polib
from deep_translator import GoogleTranslator


def main(filename: str, language: str) -> None:
po = polib.pofile(filename)
translator = GoogleTranslator(source="en", target=language)

for entry in po:
entry.msgstr = translator.translate(entry.msgid)

po.save(filename)


if __name__ == "__main__":
main(*sys.argv[1:])
11 changes: 11 additions & 0 deletions bin/translate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
uv run pybabel extract -F babel.cfg -o messages.pot .
uv run pybabel init -i messages.pot -d translations -l es
uv run pybabel init -i messages.pot -d translations -l it
uv run pybabel init -i messages.pot -d translations -l fr
echo "Translating..."
uv run ./bin/translate.py translations/es/LC_MESSAGES/messages.po es
uv run ./bin/translate.py translations/it/LC_MESSAGES/messages.po it
uv run ./bin/translate.py translations/fr/LC_MESSAGES/messages.po fr
uv run pybabel compile -d translations
echo "Done."
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ dependencies = [
"pygit2==1.17.0",
"textual==3.1.0",
"pygithub==2.6.1",
"pyyaml>=6.0",
"platformdirs>=4.3.7",
"pyyaml==6.0.2",
"platformdirs==4.3.7",
"babel==2.17.0",
]

[project.urls]
Expand All @@ -51,9 +52,11 @@ path = "src/edit_python_pe/__about__.py"
[dependency-groups]
dev = [
"black>=25.1.0",
"deep-translator>=1.11.4",
"isort>=6.0.1",
"polib>=1.2.0",
"pytest>=8.4.1",
"textual-dev>=1.7.0",
"textual-dev==1.7.0",
]

[tool.black]
Expand Down
15 changes: 15 additions & 0 deletions src/edit_python_pe/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Locales
EN_LOCALE = "en"
ES_LOCALE = "es"
IT_LOCALE = "it"
FR_LOCALE = "fr"

# Social network options
GITHUB_OPTION = ("GitHub", "github")
GITLAB_OPTION = ("GitLab", "gitlab")
BITBUCKET_OPTION = ("Bitbucket", "bitbucket")
LINKEDIN_OPTION = ("LinkedIn", "linkedin")
FACEBOOK_OPTION = ("Facebook", "facebook")
INSTAGRAM_OPTION = ("Instagram", "instagram")
X_OPTION = ("X", "x")
YOUTUBE_OPTION = ("YouTube", "youtube")
33 changes: 18 additions & 15 deletions src/edit_python_pe/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
from textual.widgets import (Button, Input, ListItem, ListView, Select, Static,
TextArea)

from .constants import (BITBUCKET_OPTION, FACEBOOK_OPTION, GITHUB_OPTION,
GITLAB_OPTION, INSTAGRAM_OPTION, LINKEDIN_OPTION,
X_OPTION, YOUTUBE_OPTION)
from .strings import (BUTTON_ADD, BUTTON_ADD_ALIAS, BUTTON_ADD_SOCIAL,
BUTTON_BACK, BUTTON_DELETE, BUTTON_QUIT, BUTTON_SAVE,
FORM_HEADER, LIST_TITLE, MESSAGE_EXIT, MESSAGE_QUIT,
PLACEHOLDER_ALIAS, PLACEHOLDER_CITY, PLACEHOLDER_EMAIL,
FORM_HEADER, LIST_TITLE, MESSAGE_EXIT, PLACEHOLDER_ALIAS,
PLACEHOLDER_CITY, PLACEHOLDER_EMAIL,
PLACEHOLDER_HOMEPAGE, PLACEHOLDER_NAME,
PLACEHOLDER_SOCIAL_URL, SECTION_ALIASES, SECTION_AVAIL,
SECTION_CONTRIB, SECTION_PYTHON, SECTION_SOCIAL,
SECTION_WHO)
PLACEHOLDER_SOCIAL_URL, PROMPT_SOCIAL_NETWORK,
SECTION_ALIASES, SECTION_AVAIL, SECTION_CONTRIB,
SECTION_PYTHON, SECTION_SOCIAL, SECTION_WHO)
from .utils import (build_md_content, create_pr, fork_repo, get_repo,
load_file_into_form)

Expand Down Expand Up @@ -195,7 +198,7 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
self.clear_form()
self.show_list()
elif bid == "quit":
self.exit(MESSAGE_QUIT)
self.exit(message=MESSAGE_EXIT)
elif bid and bid.startswith("delete_social_"):
index = int(bid.replace("delete_social_", ""))
self.remove_social_entry(index)
Expand All @@ -222,16 +225,16 @@ def __init__(se, index):
se.index = index
se.select = Select(
options=[
("GitHub", "github"),
("GitLab", "gitlab"),
("Bitbucket", "bitbucket"),
("LinkedIn", "linkedin"),
("Facebook", "facebook"),
("Instagram", "instagram"),
("X", "x"),
("YouTube", "youtube"),
GITHUB_OPTION,
GITLAB_OPTION,
BITBUCKET_OPTION,
LINKEDIN_OPTION,
FACEBOOK_OPTION,
INSTAGRAM_OPTION,
X_OPTION,
YOUTUBE_OPTION,
],
prompt="Social Network",
prompt=PROMPT_SOCIAL_NETWORK,
)
se.url_input = Input(placeholder=PLACEHOLDER_SOCIAL_URL)
se.delete_btn = Button(
Expand Down
83 changes: 51 additions & 32 deletions src/edit_python_pe/strings.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,75 @@
import gettext
import locale
from pathlib import Path

from .constants import EN_LOCALE, ES_LOCALE, FR_LOCALE, IT_LOCALE

default_locale = locale.getlocale()[0] or EN_LOCALE
localedir = Path(__file__).parent.parent / "translations"
_ = gettext.translation(
domain="messages",
localedir=localedir,
languages=[default_locale, ES_LOCALE, IT_LOCALE, FR_LOCALE],
fallback=True,
).gettext

# Field, control, and message labels for edit_python_pe

# List and form titles
LIST_TITLE = "Files in 'blog/members':"
FORM_HEADER = "Member Form"
LIST_TITLE = _("Files in 'blog/members':")
FORM_HEADER = _("Member Form")

# Button labels
BUTTON_QUIT = "Quit"
BUTTON_ADD = "Add"
BUTTON_SAVE = "Save"
BUTTON_BACK = "Back"
BUTTON_ADD_SOCIAL = "Add Social Network"
BUTTON_ADD_ALIAS = "Add Alias"
BUTTON_DELETE = "Delete"
BUTTON_QUIT = _("Quit")
BUTTON_ADD = _("Add")
BUTTON_SAVE = _("Save")
BUTTON_BACK = _("Back")
BUTTON_ADD_SOCIAL = _("Add Social Network")
BUTTON_ADD_ALIAS = _("Add Alias")
BUTTON_DELETE = _("Delete")

# Input placeholders
PLACEHOLDER_NAME = "Name"
PLACEHOLDER_EMAIL = "Email"
PLACEHOLDER_CITY = "City"
PLACEHOLDER_HOMEPAGE = "Homepage"
PLACEHOLDER_SOCIAL_URL = "Social network URL"
PLACEHOLDER_ALIAS = "Alias"
PLACEHOLDER_NAME = _("Name")
PLACEHOLDER_EMAIL = _("Email")
PLACEHOLDER_CITY = _("City")
PLACEHOLDER_HOMEPAGE = _("Homepage")
PLACEHOLDER_SOCIAL_URL = _("Social network URL")
PLACEHOLDER_ALIAS = _("Alias")

# Control prompts
PROMPT_SOCIAL_NETWORK = _("Social Network")

# Section headers
SECTION_SOCIAL = "Social Networks"
SECTION_ALIASES = "Aliases"
SECTION_WHO = "Who are you and what do you do?"
SECTION_PYTHON = "How do you program in Python?"
SECTION_CONTRIB = "Do you have any contributions to the Python community?"
SECTION_AVAIL = "Are you available for mentoring, consulting, talks?"
SECTION_SOCIAL = _("Social Networks")
SECTION_ALIASES = _("Aliases")
SECTION_WHO = _("Who are you and what do you do?")
SECTION_PYTHON = _("How do you program in Python?")
SECTION_CONTRIB = _("Do you have any contributions to the Python community?")
SECTION_AVAIL = _("Are you available for mentoring, consulting, talks?")

# Messages
MESSAGE_PROMPT_FOR_GITHUB_TOKEN = (
MESSAGE_PROMPT_FOR_GITHUB_TOKEN = _(
"Please enter your GitHub personal access token: "
)
MESSAGE_EXIT = "See you next time!"
MESSAGE_QUIT = "Exiting the application."
MESSAGE_FILE_READ_ERROR = "Error reading file {filename}: {error}"
MESSAGE_UNAUTHORIZED = "Unauthorized access. Please check your access token."
MESSAGE_REPO_NOT_FOUND = (
MESSAGE_EXIT = _("See you next time!")
MESSAGE_FILE_READ_ERROR = _("Error reading file {filename}: {error}")
MESSAGE_UNAUTHORIZED = _(
"Unauthorized access. Please check your access token."
)
MESSAGE_REPO_NOT_FOUND = _(
"Repository not found. Please check your access token."
)
MESSAGE_FILE_EDITED_PR = (
MESSAGE_FILE_EDITED_PR = _(
"File {name_file} edited, commit and changes sent to existing PR."
)
MESSAGE_FILE_SAVED_PR = "File {name_file} saved, commit and PR ready."
MESSAGE_CREATE_ENTRY = (
MESSAGE_FILE_SAVED_PR = _("File {name_file} saved, commit and PR ready.")
MESSAGE_CREATE_ENTRY = _(
"Creating a new entry to `blog/members` for {name} (alias: {first_alias})."
)
MESSAGE_CHANGE_ENTRY = (
MESSAGE_CHANGE_ENTRY = _(
"Changing an entry to `blog/members` for {name} (alias: {first_alias})."
)
MESSAGE_LOAD_FILE_ERROR = "Error reading file {filename}: {error}"
MESSAGE_LOAD_FILE_ERROR = _("Error reading file {filename}: {error}")

# build_md_content markdown dictionary (English keys, Spanish values for now)
MD_CONTENT = {
Expand Down
Binary file added translations/es/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file added translations/fr/LC_MESSAGES/messages.mo
Binary file not shown.
Binary file added translations/it/LC_MESSAGES/messages.mo
Binary file not shown.
65 changes: 62 additions & 3 deletions uv.lock

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