Skip to content

Commit

Permalink
[Feature] Remove i18n (#6390)
Browse files Browse the repository at this point in the history
* remove i18n

* poetry lock

---------

Co-authored-by: montezdesousa <[email protected]>
  • Loading branch information
hjoaquim and montezdesousa authored May 10, 2024
1 parent ac3f10a commit ac745ad
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 119 deletions.
36 changes: 0 additions & 36 deletions cli/openbb_cli/assets/i18n/en.yml

This file was deleted.

1 change: 0 additions & 1 deletion cli/openbb_cli/config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
STYLES_DIRECTORY = ASSETS_DIRECTORY / "styles"
ENV_FILE_SETTINGS = SETTINGS_DIRECTORY / ".cli.env"
HIST_FILE_PROMPT = SETTINGS_DIRECTORY / ".cli.his"
I18N_FILE = ASSETS_DIRECTORY / "i18n"


DEFAULT_ROUTINES_URL = "https://openbb-cms.directus.app/items/Routines"
Expand Down
36 changes: 10 additions & 26 deletions cli/openbb_cli/config/menu_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from typing import Dict, List

import i18n
from openbb import obb

# https://rich.readthedocs.io/en/stable/appendix/colors.html#appendix-colors
Expand Down Expand Up @@ -92,10 +91,8 @@ def _format_cmd_description(
self, name: str, description: str, trim: bool = True
) -> str:
"""Truncate command description length if it is too long."""
if not description:
description = i18n.t(self.menu_path + name)
if description == self.menu_path + name:
description = ""
if not description or description == f"{self.menu_path}{name}":
description = ""
return (
description[: self.CMD_DESCRIPTION_LENGTH - 3] + "..."
if len(description) > self.CMD_DESCRIPTION_LENGTH and trim
Expand All @@ -122,23 +119,9 @@ def add_section(
else:
self.menu_text += text

def add_custom(self, name: str):
"""Append custom text (after translation)."""
self.menu_text += f"{i18n.t(self.menu_path + name)}"

def add_info(self, text: str):
"""Append information text (after translation)."""
self.menu_text += f"[info]{i18n.t(self.menu_path + text)}:[/info]\n"

def add_param(self, name: str, value: str, col_align: int = 0):
"""Append parameter (after translation)."""
parameter_translated = i18n.t(self.menu_path + name)
space = (
(col_align - len(parameter_translated)) * " "
if col_align > len(parameter_translated)
else ""
)
self.menu_text += f"[param]{parameter_translated}{space}:[/param] {value}\n"
self.menu_text += f"[info]{text}:[/info]\n"

def add_cmd(self, name: str, description: str = "", disable: bool = False):
"""Append command text (after translation)."""
Expand Down Expand Up @@ -174,10 +157,8 @@ def add_menu(
"""Append menu text (after translation)."""
spacing = (self.CMD_NAME_LENGTH - len(name) + self.SECTION_SPACING) * " "

if not description:
description = i18n.t(self.menu_path + name)
if description == self.menu_path + name:
description = ""
if not description or description == f"{self.menu_path}{name}":
description = ""

if len(description) > self.CMD_DESCRIPTION_LENGTH:
description = description[: self.CMD_DESCRIPTION_LENGTH - 3] + "..."
Expand All @@ -186,9 +167,12 @@ def add_menu(
tag = "unvl" if disable else "menu"
self.menu_text += f"[{tag}]> {menu}[/{tag}]\n"

def add_setting(self, name: str, status: bool = True):
def add_setting(self, name: str, status: bool = True, description: str = ""):
"""Append menu text (after translation)."""
spacing = (self.CMD_NAME_LENGTH - len(name) + self.SECTION_SPACING) * " "
indentation = self.SECTION_SPACING * " "
color = "green" if status else "red"
self.menu_text += f"[{color}]{indentation}{name}{spacing}{i18n.t(self.menu_path + name)}[/{color}]\n"

self.menu_text += (
f"[{color}]{indentation}{name}{spacing}{description}[/{color}]\n"
)
11 changes: 1 addition & 10 deletions cli/openbb_cli/config/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, List, Optional, TypeVar

import i18n

from openbb_cli.config.constants import ENV_FILE_SETTINGS, I18N_FILE, SETTINGS_DIRECTORY
from openbb_cli.config.constants import ENV_FILE_SETTINGS, SETTINGS_DIRECTORY

if TYPE_CHECKING:
from openbb_charting.core.openbb_figure import OpenBBFigure
Expand Down Expand Up @@ -69,13 +67,6 @@ def set_current_figure(fig: Optional[OpenBBFigureT] = None):
current_figure = fig


def setup_i18n(i18n_path: Path = I18N_FILE, lang: str = "en"):
"""Select the CLI translation language."""
i18n.load_path.append(i18n_path)
i18n.set("locale", lang)
i18n.set("filename_format", "{locale}.{format}")


def bootstrap():
"""Setup pre-launch configurations for the CLI."""
SETTINGS_DIRECTORY.mkdir(parents=True, exist_ok=True)
Expand Down
20 changes: 14 additions & 6 deletions cli/openbb_cli/controllers/cli_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,21 @@ def update_runtime_choices(self):
def print_help(self):
"""Print help."""
mt = MenuText("")
mt.add_info("_configure_")
mt.add_menu("settings")
mt.add_info("Configure your own CLI")
mt.add_menu(
"settings",
description="enable and disable feature flags, preferences and settings",
)
mt.add_raw("\n")
mt.add_info("_scripts_")
mt.add_cmd("record")
mt.add_cmd("stop")
mt.add_cmd("exe")
mt.add_info("Record and execute your own .openbb routine scripts")
mt.add_cmd("record", description="start recording current session")
mt.add_cmd(
"stop", description="stop session recording and convert to .openbb routine"
)
mt.add_cmd(
"exe",
description="execute .openbb routine scripts (use exe --example for an example)",
)
mt.add_raw("\n")
mt.add_info("Retrieve data from different asset classes and providers")

Expand Down
89 changes: 69 additions & 20 deletions cli/openbb_cli/controllers/settings_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class SettingsController(BaseController):
"""Settings Controller class."""

CHOICES_COMMANDS: List[str] = [
"retryload",
"tab",
"interactive",
"cls",
Expand Down Expand Up @@ -56,26 +55,76 @@ def print_help(self):
settings = session.settings

mt = MenuText("settings/")
mt.add_info("_feature_flags_")
mt.add_setting("interactive", settings.USE_INTERACTIVE_DF)
mt.add_setting("cls", settings.USE_CLEAR_AFTER_CMD)
mt.add_setting("promptkit", settings.USE_PROMPT_TOOLKIT)
mt.add_setting("exithelp", settings.ENABLE_EXIT_AUTO_HELP)
mt.add_setting("rcontext", settings.REMEMBER_CONTEXTS)
mt.add_setting("richpanel", settings.ENABLE_RICH_PANEL)
mt.add_setting("tbhint", settings.TOOLBAR_HINT)
mt.add_setting("overwrite", settings.FILE_OVERWRITE)
mt.add_setting("version", settings.SHOW_VERSION)
mt.add_setting("obbject_msg", settings.SHOW_MSG_OBBJECT_REGISTRY)
mt.add_info("Feature flags")
mt.add_setting(
"interactive",
settings.USE_INTERACTIVE_DF,
description="open dataframes in interactive window",
)
mt.add_setting(
"cls",
settings.USE_CLEAR_AFTER_CMD,
description="clear console after each command",
)
mt.add_setting(
"promptkit",
settings.USE_PROMPT_TOOLKIT,
description="enable prompt toolkit (autocomplete and history)",
)
mt.add_setting(
"exithelp",
settings.ENABLE_EXIT_AUTO_HELP,
description="automatically print help when quitting menu",
)
mt.add_setting(
"rcontext",
settings.REMEMBER_CONTEXTS,
description="remember contexts between menus",
)
mt.add_setting(
"richpanel",
settings.ENABLE_RICH_PANEL,
description="colorful rich CLI panel",
)
mt.add_setting(
"tbhint",
settings.TOOLBAR_HINT,
description="displays usage hints in the bottom toolbar",
)
mt.add_setting(
"overwrite",
settings.FILE_OVERWRITE,
description="whether to overwrite Excel files if they already exists",
)
mt.add_setting(
"version",
settings.SHOW_VERSION,
description="whether to show the version in the bottom right corner",
)
mt.add_setting(
"obbject_msg",
settings.SHOW_MSG_OBBJECT_REGISTRY,
description="show obbject registry message after a new result is added",
)
mt.add_raw("\n")
mt.add_info("_preferences_")
mt.add_cmd("console_style")
mt.add_cmd("flair")
mt.add_cmd("timezone")
mt.add_cmd("n_rows")
mt.add_cmd("n_cols")
mt.add_cmd("obbject_res")
mt.add_cmd("obbject_display")
mt.add_info("Preferences")
mt.add_cmd("console_style", description="apply a custom rich style to the CLI")
mt.add_cmd("flair", description="choose flair icon")
mt.add_cmd("timezone", description="pick timezone")
mt.add_cmd(
"n_rows", description="number of rows to show on non interactive tables"
)
mt.add_cmd(
"n_cols", description="number of columns to show on non interactive tables"
)
mt.add_cmd(
"obbject_res",
description="define the maximum number of obbjects allowed in the registry",
)
mt.add_cmd(
"obbject_display",
description="define the maximum number of cached results to display on the help menu",
)

session.console.print(text=mt.menu_text, menu="Settings")

Expand Down
24 changes: 5 additions & 19 deletions cli/poetry.lock

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

1 change: 0 additions & 1 deletion cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ openbb-charting = "^2.0.2"
prompt-toolkit = "^3.0.16"
rich = "^13"
python-dotenv = "^1.0.0"
python-i18n = "^0.3.9"

[tool.poetry.group.dev.dependencies]
openbb-devtools = "^1.1.3"
Expand Down

0 comments on commit ac745ad

Please sign in to comment.