diff --git a/README.md b/README.md index 783e994..05d1be7 100644 --- a/README.md +++ b/README.md @@ -198,8 +198,6 @@ options: Merge output. Defaults to --no-merge -s {front,back,both}, --side {front,back,both} Side(s) to generate. Defaults to both. - -l {en,nl}, --lang {en,nl} - Language. 'en' and 'nl' supported. Defaults to 'en'. -f {pdf,png}, --format {pdf,png} Output format. 'pdf' and 'png' supported. Defaults to 'pdf'. -r, --rank, --no-rank diff --git a/pyproject.toml b/pyproject.toml index cf6ad0b..5e2cdb0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=61.0", "babel"] +requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [project] @@ -44,7 +44,7 @@ exclude = ["shithappens.opensans"] namespaces = false [tool.setuptools.package-data] -shithappens = ["opensans/fonts/ttf/*.ttf", "images/*.png", "locales/*/LC_MESSAGES/*.mo"] +shithappens = ["opensans/fonts/ttf/*.ttf", "images/*.png"] [tool.setuptools.dynamic] dependencies = {file = ["requirements.txt"]} diff --git a/requirements.txt b/requirements.txt index f7aef4c..1fe7e5e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,4 @@ matplotlib pandas openpyxl PyPDF2 -tqdm -babel \ No newline at end of file +tqdm \ No newline at end of file diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 457a984..0000000 --- a/setup.cfg +++ /dev/null @@ -1,20 +0,0 @@ -[extract_messages] -input-dirs = src -output-file = src/shithappens/locales/shithappens.pot -keywords = _ gettext ngettext -width = 80 - -[compile_catalog] -domain = shithappens -directory = src/shithappens/locales -statistics = true - -[init_catalog] -domain = shithappens -input-file = src/shithappens/locales/shithappens.pot -output-dir = src/shithappens/locales - -[update_catalog] -domain = shithappens -input-file = src/shithappens/locales/shithappens.pot -output-dir = src/shithappens/locales \ No newline at end of file diff --git a/src/app/main.py b/src/app/main.py index cf0ee90..ce8e399 100644 --- a/src/app/main.py +++ b/src/app/main.py @@ -5,7 +5,6 @@ import pandas as pd import tkinter as tk from tkinter import filedialog -from pathlib import Path sys.path.append(str(Path(__file__).absolute().parent.parent)) @@ -36,7 +35,6 @@ def select_folder(): merge = st.checkbox("Merge output", value=True) side = st.selectbox("Side(s) to generate", ["both", "front", "back"]) - lang = st.selectbox("Language", ["en", "nl"]) format = st.selectbox("Output format", ["pdf", "png"]) workers = st.number_input("Number of workers", value=4) chunks = st.number_input("Number of chunks for the workers to process", value=30) @@ -50,6 +48,5 @@ def select_folder(): format=format, workers=workers, chunks=chunks, - lang=lang, ) st.write("Cards written to ", output_dir) diff --git a/src/shithappens/cli/__init__.py b/src/shithappens/cli/__init__.py index 838bc31..f9f2f5c 100644 --- a/src/shithappens/cli/__init__.py +++ b/src/shithappens/cli/__init__.py @@ -26,14 +26,6 @@ def cli(): default="both", help="Side(s) to generate.", ) -@click.option( - "-l", - "--language", - "lang", - type=click.Choice(["en", "nl"], case_sensitive=False), - default="en", - help="Language.", -) @click.option( "-f", "--format", diff --git a/src/shithappens/cli/utils.py b/src/shithappens/cli/utils.py index 1d39843..0fbeace 100644 --- a/src/shithappens/cli/utils.py +++ b/src/shithappens/cli/utils.py @@ -2,10 +2,6 @@ from glob import glob import click -from shithappens.utils import install_lang - -_ = install_lang("en") - def verify_input_dir(input_dir: Path): while True: @@ -13,24 +9,23 @@ def verify_input_dir(input_dir: Path): break input_dir = Path( input( - _( - "Input directory {} does not exist. Please specify an existing input directory.\n" - ).format(input_dir) + f"Input directory {input_dir} does not exist. " + "Please specify an existing input directory.\n" ) ) output_dir = input_dir / "outputs" - print(_("Reading files from {}.").format(input_dir)) - print(_("Output files in {}.").format(output_dir)) + print(f"Reading files from {input_dir}.") + print(f"Output files in {output_dir}.") xlsx_paths = glob(f"{input_dir / '*.xlsx'}") xlsx_paths_num = len(xlsx_paths) if not xlsx_paths_num: - print(_("Please provide an Excel file in {}.").format(input_dir)) + print("Please provide an Excel file in {input_dir}.") exit(1) elif xlsx_paths_num > 1: while True: - print(_("\nMore than one input file found.")) + print("\nMore than one input file found.") for i, xlsx_path in enumerate(xlsx_paths, 1): print(f"[{i}] {xlsx_path}") try: diff --git a/src/shithappens/create_cards.py b/src/shithappens/create_cards.py index 76d4445..2d29af2 100644 --- a/src/shithappens/create_cards.py +++ b/src/shithappens/create_cards.py @@ -1,5 +1,4 @@ import argparse -import gettext import textwrap from functools import partial from glob import glob @@ -16,28 +15,14 @@ from matplotlib.patches import Rectangle from matplotlib.text import Annotation from matplotlib.transforms import Bbox - -try: - from tqdm import tqdm -except ImportError: - - def tqdm(iterable, *args, **kwargs): - del args, kwargs - return iterable +from tqdm import tqdm from shithappens.card import Card +from shithappens.cli.utils import verify_input_dir from shithappens.utils import merge_pdfs, slugify -def install_lang(locale: str): - localedir = Path(__file__).parent.resolve() / "locales" - lang = gettext.translation("shithappens", localedir=localedir, languages=[locale]) - lang.install() - global _ - _ = lang.gettext - - def text_with_wrap_autofit( ax: plt.Axes, txt: str, @@ -133,7 +118,6 @@ class ShitHappensArgs(argparse.Namespace): merge: bool rank: bool side: Literal["front", "back", "both"] - lang: Literal["en", "nl"] format: Literal["pdf", "png"] workers: int chunks: int @@ -156,7 +140,7 @@ def parse_excel(input_path: Path, desc_col: int, misery_index_col: int) -> pd.Da input_path, usecols=[desc_col, misery_index_col], engine="openpyxl" ) except Exception: - print(_("{} is not an excel file.").format(input_path)) + print(f"{input_path} is not an excel file.") exit() return df @@ -241,7 +225,7 @@ def plot_card_front(card: Card) -> Figure: color="yellow", ) - mi_desc = _("misery index") + mi_desc = "misery index" ax.text( x_total / 2, 1.3 * y_size / 8 + bleed, @@ -309,7 +293,7 @@ def plot_card_back(card: Card, input_dir: Path) -> Figure: ) game_name = "Shit Happens" - expansion_text = _("edition") + expansion_text = "edition" expansion_text_full = card.expansion_name + " " + expansion_text ax.text( @@ -374,7 +358,7 @@ def save_card( dpi: int = 300, format: str = "pdf", ) -> None: - side_fn = _("front") if side == "front" else _("back") + side_fn = "front" if side == "front" else "back" output_dir = output_dir / side_fn @@ -416,10 +400,6 @@ def create_card( save_card(card, output_dir, "back", format=ext) -def _init(locale): - install_lang(locale) - - def create_cards( df: pd.DataFrame, expansion_name: str, @@ -442,9 +422,9 @@ def create_cards( side=side, ext=ext, ) - desc = _("Plotting cards") + desc = "Plotting cards" if chunksize: - with Pool(workers, _init, initargs=(locale,)) as p: + with Pool(workers) as p: list( tqdm( p.imap_unordered(create_card_par, df.iterrows(), chunksize), @@ -457,23 +437,12 @@ def create_cards( if merge: if side == "front" or side == "both": - merge_pdfs(output_dir / _("front")) + merge_pdfs(output_dir / "front") if side == "back" or side == "both": - merge_pdfs(output_dir / _("back")) + merge_pdfs(output_dir / "back") def main(**args) -> None: - install_lang(args["lang"]) - - try: - import tqdm - except ImportError: - print(_("'pip install shithappens[pbar]' to show a progress bar.")) - else: - del tqdm - - from shithappens.cli.utils import verify_input_dir - input_dir = Path(args["input_dir"]) xlsx_path, output_dir = verify_input_dir(input_dir) @@ -489,24 +458,12 @@ def main(**args) -> None: else: expansion_name = input_dir.stem print( - _( - "Argument -n/--name not given. " "Expansion name inferred to be {}." - ).format(expansion_name) + "Argument -n/--name not given. " + f"Expansion name inferred to be {expansion_name}." ) df = parse_excel(xlsx_path, 0, 1) - if args["merge"]: - try: - import PyPDF2 - - args["merge"] = True - except ImportError: - args["merge"] = False - print(_("'pip install shithappens[merge]' for pdf merging.")) - else: - del PyPDF2 - create_cards( df, expansion_name, @@ -517,7 +474,6 @@ def main(**args) -> None: args["format"], args["workers"], args["chunks"], - args["lang"], ) @@ -525,7 +481,7 @@ def main_cli(**kwargs): try: main(**kwargs) except KeyboardInterrupt: - print(_("Interrupted.")) + print("Interrupted.") if __name__ == "__main__": diff --git a/src/shithappens/locales/en/LC_MESSAGES/shithappens.po b/src/shithappens/locales/en/LC_MESSAGES/shithappens.po deleted file mode 100644 index 1870e71..0000000 --- a/src/shithappens/locales/en/LC_MESSAGES/shithappens.po +++ /dev/null @@ -1,136 +0,0 @@ -# English translations for shithappens. -# Copyright (C) 2023 ORGANIZATION -# This file is distributed under the same license as the shithappens -# project. -# FIRST AUTHOR , 2023. -# -msgid "" -msgstr "" -"Project-Id-Version: shithappens 0.4.0\n" -"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2023-03-13 22:16+0100\n" -"PO-Revision-Date: 2023-01-07 15:33+0100\n" -"Last-Translator: FULL NAME \n" -"Language: en\n" -"Language-Team: en \n" -"Plural-Forms: nplurals=2; plural=(n != 1);\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.11.0\n" - -#: src/shithappens/create_cards.py:148 -msgid "{} is not an excel file." -msgstr "" - -#: src/shithappens/create_cards.py:233 -msgid "misery index" -msgstr "" - -#: src/shithappens/create_cards.py:301 -msgid "edition" -msgstr "" - -#: src/shithappens/create_cards.py:367 src/shithappens/create_cards.py:448 -msgid "front" -msgstr "" - -#: src/shithappens/create_cards.py:367 src/shithappens/create_cards.py:450 -msgid "back" -msgstr "" - -#: src/shithappens/create_cards.py:433 -msgid "Plotting cards" -msgstr "" - -#: src/shithappens/create_cards.py:460 -msgid "'pip install shithappens[pbar]' to show a progress bar." -msgstr "" - -#: src/shithappens/create_cards.py:482 -msgid "Argument -n/--name not given. Expansion name inferred to be {}." -msgstr "" - -#: src/shithappens/create_cards.py:496 -msgid "'pip install shithappens[merge]' for pdf merging." -msgstr "" - -#: src/shithappens/create_cards.py:518 src/shithappens/sort_situations.py:182 -msgid "Interrupted." -msgstr "" - -#: src/shithappens/sort_situations.py:30 -msgid "{} does not contain any Excel files." -msgstr "" - -#: src/shithappens/sort_situations.py:65 -msgid "Some items have equal ranking score. Please check the output file ({})." -msgstr "" - -#: src/shithappens/sort_situations.py:69 -msgid "Manually assign a misery-index to situations." -msgstr "" - -#: src/shithappens/sort_situations.py:149 -msgid "Continuing from situation {}" -msgstr "" - -#: src/shithappens/sort_situations.py:157 -msgid "" -"\n" -"Which situation is most miserable?\n" -"\n" -msgstr "" - -#: src/shithappens/sort_situations.py:164 -msgid "Do you want to save your progress? [y]/n" -msgstr "" - -#: src/shithappens/cli/utils.py:15 -msgid "" -"Input directory {} does not exist. Please specify an existing input " -"directory.\n" -msgstr "" - -#: src/shithappens/cli/utils.py:22 -msgid "Reading files from {}." -msgstr "" - -#: src/shithappens/cli/utils.py:23 -msgid "Output files in {}." -msgstr "" - -#: src/shithappens/cli/utils.py:28 -msgid "Please provide an Excel file in {}." -msgstr "" - -#: src/shithappens/cli/utils.py:32 -msgid "" -"\n" -"More than one input file found." -msgstr "" - -#~ msgid "Expansion name inferred to be {}." -#~ msgstr "" - -#~ msgid "Expansion name inferred to be {expansion_name}." -#~ msgstr "" - -#~ msgid "Argument -n/--name not given. " -#~ msgstr "" - -#~ msgid "'pip install shithappens[pbar]' to add a progress bar." -#~ msgstr "" - -#~ msgid "More than one input file found." -#~ msgstr "" - -#~ msgid "Select: " -#~ msgstr "" - -#~ msgid "Manually assign a misery score to situations." -#~ msgstr "" - -#~ msgid "expansion" -#~ msgstr "" - diff --git a/src/shithappens/locales/nl/LC_MESSAGES/shithappens.po b/src/shithappens/locales/nl/LC_MESSAGES/shithappens.po deleted file mode 100644 index 43ac7b7..0000000 --- a/src/shithappens/locales/nl/LC_MESSAGES/shithappens.po +++ /dev/null @@ -1,116 +0,0 @@ -# Dutch translations for shithappens. -# Copyright (C) 2023 ORGANIZATION -# This file is distributed under the same license as the shithappens -# project. -# FIRST AUTHOR , 2023. -# -msgid "" -msgstr "" -"Project-Id-Version: shithappens 0.4.0\n" -"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2023-03-13 22:16+0100\n" -"PO-Revision-Date: 2023-01-07 15:32+0100\n" -"Last-Translator: FULL NAME \n" -"Language: nl\n" -"Language-Team: nl \n" -"Plural-Forms: nplurals=2; plural=(n != 1);\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.11.0\n" - -#: src/shithappens/create_cards.py:148 -msgid "{} is not an excel file." -msgstr "{} is geen excelbestand." - -#: src/shithappens/create_cards.py:233 -msgid "misery index" -msgstr "ellende-index" - -#: src/shithappens/create_cards.py:301 -msgid "edition" -msgstr "editie" - -#: src/shithappens/create_cards.py:367 src/shithappens/create_cards.py:448 -msgid "front" -msgstr "voorkant" - -#: src/shithappens/create_cards.py:367 src/shithappens/create_cards.py:450 -msgid "back" -msgstr "achterkant" - -#: src/shithappens/create_cards.py:433 -msgid "Plotting cards" -msgstr "Plot kaarten" - -#: src/shithappens/create_cards.py:460 -msgid "'pip install shithappens[pbar]' to show a progress bar." -msgstr "'pip install shithappens[pbar]' om een voortgangsbalk te tonen." - -#: src/shithappens/create_cards.py:482 -msgid "Argument -n/--name not given. Expansion name inferred to be {}." -msgstr "Argument -n/--name is niet gegeven. Uitbreidingsnaam is afgeleid als {}." - -#: src/shithappens/create_cards.py:496 -msgid "'pip install shithappens[merge]' for pdf merging." -msgstr "'pip' install shithappens[merge]' voor pdf-samenvoeging." - -#: src/shithappens/create_cards.py:518 src/shithappens/sort_situations.py:182 -msgid "Interrupted." -msgstr "Onderbroken." - -#: src/shithappens/sort_situations.py:30 -msgid "{} does not contain any Excel files." -msgstr "{} bevat geen excelbestanden." - -#: src/shithappens/sort_situations.py:65 -msgid "Some items have equal ranking score. Please check the output file ({})." -msgstr "Sommige items hebben dezelfde ranking. Check het outputbestand ({})." - -#: src/shithappens/sort_situations.py:69 -msgid "Manually assign a misery-index to situations." -msgstr "Wijs handmatig een ellende-index toe aan de situaties." - -#: src/shithappens/sort_situations.py:149 -msgid "Continuing from situation {}" -msgstr "Verdergaan vanaf situatie {}" - -#: src/shithappens/sort_situations.py:157 -msgid "" -"\n" -"Which situation is most miserable?\n" -"\n" -msgstr "" -"\n" -"Welke situatie is het vervelendst?\n" -"\n" - -#: src/shithappens/sort_situations.py:164 -msgid "Do you want to save your progress? [y]/n" -msgstr "Wil je je voortgang opslaan? [y]/n" - -#: src/shithappens/cli/utils.py:15 -msgid "" -"Input directory {} does not exist. Please specify an existing input " -"directory.\n" -msgstr "Inputmap {} bestaat niet. Specificeer een bestaande map." - -#: src/shithappens/cli/utils.py:22 -msgid "Reading files from {}." -msgstr "Lees bestanden uit {}." - -#: src/shithappens/cli/utils.py:23 -msgid "Output files in {}." -msgstr "Output bestanden in {}." - -#: src/shithappens/cli/utils.py:28 -msgid "Please provide an Excel file in {}." -msgstr "Voorzie {} van een excelbestand." - -#: src/shithappens/cli/utils.py:32 -msgid "" -"\n" -"More than one input file found." -msgstr "" -"\n" -"Meer dan één inputbestand gevonden." diff --git a/src/shithappens/sort_situations.py b/src/shithappens/sort_situations.py index b7cb4bd..9a0f403 100644 --- a/src/shithappens/sort_situations.py +++ b/src/shithappens/sort_situations.py @@ -9,9 +9,6 @@ UP = "\x1b[3A" ERASE = "\x1b[2A" -def _(message): - return message - def parse_excel(input_path: Path, desc_col: int, score_col: int = 2) -> pd.DataFrame: """Parse an Excel file. @@ -28,7 +25,7 @@ def parse_excel(input_path: Path, desc_col: int, score_col: int = 2) -> pd.DataF try: df = pd.read_excel(input_path, usecols=[desc_col, score_col], engine="openpyxl") except Exception: - print(_("{} does not contain any Excel files.".format(input_path))) + print(f"{input_path} does not contain any Excel files.") exit() return df @@ -64,11 +61,10 @@ def save(xlsx_path, df): if len(df["score"].unique()) != len(df): print( - _( - "Some items have equal ranking score. Please check the output file ({})." - ).format(output_file) + "Some items have equal ranking score. " + f"Please check the output file ({output_file})." ) - print(_("Manually assign a misery-index to situations.")) + print("Manually assign a misery-index to situations.") def sort( @@ -179,7 +175,7 @@ def sort( elif strategy == "round-robin": try: continue_from = df["score"].sum() - print(_("Continuing from situation {}".format(continue_from))) + print(f"Continuing from situation {continue_from}") except KeyError: df["misery_index"] = 0 df["score"] = 0 @@ -187,7 +183,7 @@ def sort( combinations = list(itertools.combinations(df.index, 2))[continue_from:] - print(_("\nWhich situation is most miserable?\n\n")) + print("\nWhich situation is most miserable?\n\n") try: with tqdm( @@ -199,7 +195,7 @@ def sort( for combination in progress_iterator: prompt_question(df, combination) except KeyboardInterrupt: - print(_("Do you want to save your progress? [y]/n")) + print("Do you want to save your progress? [y]/n") save_progress = click.getchar() if not save_progress: save_progress = True @@ -225,4 +221,4 @@ def main_cli(**kwargs): kwargs["prescore"], ) except KeyboardInterrupt: - print(_("Interrupted.")) + print("Interrupted.") diff --git a/src/shithappens/utils.py b/src/shithappens/utils.py index 0b2426a..b8eb6bc 100644 --- a/src/shithappens/utils.py +++ b/src/shithappens/utils.py @@ -3,7 +3,6 @@ from glob import glob from pathlib import Path from typing import Optional -import gettext def sort_pdfs_by_mi(fn: str): @@ -60,12 +59,3 @@ def slugify(value, allow_unicode=False): ) value = re.sub(r"[^\w\s-]", "", value.lower()) return re.sub(r"[-\s]+", "-", value).strip("-_") - - -def install_lang(locale: str): - localedir = Path(__file__).parent.resolve() / "locales" - lang = gettext.translation("shithappens", localedir=localedir, languages=[locale]) - lang.install() - global _ - _ = lang.gettext - return _