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

Feature choose language #22

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
54 changes: 54 additions & 0 deletions pls_cli/please.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Union

import typer
from enum import Enum
from rich import box
from rich.align import Align
from rich.console import Console, RenderableType
Expand Down Expand Up @@ -131,6 +132,45 @@ def quotes(show: bool = True) -> None:
)


class language(str, Enum):
english = "english"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to use the short form, like en for english and es for spanish, what do you think?

spanish = "spanish"


@app.command("language", rich_help_panel="Utils and Configs")
def language(
lang: language = typer.Option(language.english, case_sensitive=False)
) -> None:
"""Choose language 🛩️"""
settings = Settings().get_settings()
if settings["language"] == lang:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here it would be better to have just an if with the comparison of different. And in the end have only one center_print to avoid code duplication, like this:

if settings["language"] != lang:
    settings["language"] = lang
    Settings().write_settings(settings)
    # Here function Dowload quotes
    center_print(
        Rule(
            "Thanks for letting me know that!",
            style=insert_or_delete_line_style,
        ),
        style=insert_or_delete_text_style,
    )

cener_print(
    Rule(
        f"Current language is: {lang}",
        style=insert_or_delete_line_style,
    ),
    style=insert_or_delete_text_style,
)

center_print(
Rule(
f"Current language is: {lang}",
style=insert_or_delete_line_style,
),
style=insert_or_delete_text_style,
)
else:
settings["language"] = lang
Settings().write_settings(settings)
# Here function Dowload quotes
center_print(
Rule(
"Thanks for letting me know that!",
style=insert_or_delete_line_style,
),
style=insert_or_delete_text_style,
)
center_print(
Rule(
f"Current language is: {lang}",
style=insert_or_delete_line_style,
),
style=insert_or_delete_text_style,
)


@app.command('tasks', short_help='Show all Tasks :open_book:')
@app.command(short_help='[s]Show all Tasks :open_book:[/]', deprecated=True)
def showtasks() -> None:
Expand Down Expand Up @@ -481,6 +521,18 @@ def setup() -> None:
)
console.print(code_markdown)

code_markdown = Markdown(
"""
pls language --lang <language>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is correct? pls language --lang <language>

"""
)

center_print(
'If you want to change the language of quotes, please use:',
style='red',
)
console.print(code_markdown)

center_print(
'To apply the changes restart the terminal or use this command:',
style='red',
Expand All @@ -503,6 +555,8 @@ def setup() -> None:
else:
settings['show_quotes'] = True

settings['language'] = 'english'

settings['tasks'] = []
Settings().write_settings(settings)

Expand Down
Loading