-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Terminal supporting controller with multiple languages #1730
Conversation
DidierRLopes
commented
Apr 23, 2022
•
edited
Loading
edited
- Need to add i18n to requirements and poetry
- Need to make the language to be selected a feature flag
- Add documentation on this
- Still missing helpers for commands. T.b.d. in another PR.
@DidierRLopes There was a Pygments update that was not pushed up the chain. Trying to fix it in #1737 |
I've looked a bit into this, here are some exploration results We have the following text that can be translated:
A brief search revealed: The strings can be parsed with regexp console\.print\((.*?)\) or xgettext xgettext openbb_terminal/stocks/stocks_controller.py -o 1test.txt -L Python -j -a It would be cool if ... but ... f-stings spoil all the fun with this scenario. with f-strings the keys to the translation dictionary would be dynamic. In addition I don't have a clear understanding of how to maintain without significant effort. Any ideas here are welcome. |
Thanks for this @piiq. This all makes sense. My initial idea was to just translate: controller menu, and command helper (and its arguments). That by itself would already be a very good step forward. Not sure about the ROI of modifying the f-string to My initial idea was to have keys for these 3 type of cases as I mention in the
And my biggest concern can be minimised by introducing a test that checks if all keys on |
@piiq I will try to summarize the idea let me know if this is accurate. You are suggesting using |
@Chavithra , yep like rationale:
on the other hand we would need to maintain a dictionary for english and I find it hard to come up with an automation for this at the moment |
check my comment above regarding maintainability. I think that's a 10min break task for @colin99d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs some serious documentation on the contributing guide as to how you add a new feature to the help menu text.
openbb_terminal/rich_config.py
Outdated
|
||
def init_menu(self, path: str = ""): | ||
self.menu_text = "" | ||
self.menu_path = path | ||
|
||
def add_raw(self, raw: str): | ||
self.menu_text += raw | ||
|
||
def add_raw_translation(self, raw: str): | ||
self.menu_text += f"{i18n.t(self.menu_path + raw)}" | ||
|
||
def add_info_translation(self, info: str): | ||
self.menu_text += f"[info]{i18n.t(self.menu_path + info)}:[/info]\n" | ||
|
||
def add_param_translation(self, param: str, value: str): | ||
self.menu_text += f"[param]{i18n.t(self.menu_path + param)}:[/param] {value}\n" | ||
|
||
def add_cmd_translation(self, key: str, source: str = "", cond: bool = True): | ||
if source: | ||
source = f" [src][{source}][/src]" | ||
spacing = (22 - (len(key) + 4)) * " " | ||
if cond: | ||
self.menu_text += f"[cmds] {key}{spacing}{i18n.t(self.menu_path + key)}{source}[/cmds]\n" | ||
else: | ||
self.menu_text += f"[unvl] {key}{spacing}{i18n.t(self.menu_path + key)}{source}[/unvl]\n" | ||
|
||
def add_menu_translation(self, key: str, cond: bool = True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no docstrings anywhere
openbb_terminal/rich_config.py
Outdated
def __init__(self, path: str = "", col_src: int = 100): | ||
self.menu_text = "" | ||
self.menu_path = path | ||
self.col_src = col_src | ||
|
||
def add_raw(self, raw: str): | ||
self.menu_text += raw | ||
|
||
def add_raw_translation(self, raw: str): | ||
self.menu_text += f"{i18n.t(self.menu_path + raw)}" | ||
|
||
def add_info_translation(self, info: str): | ||
self.menu_text += f"[info]{i18n.t(self.menu_path + info)}:[/info]\n" | ||
|
||
def add_param_translation(self, param: str, value: str, spacing: int = 0): | ||
par = i18n.t(self.menu_path + param) | ||
if spacing > len(par): | ||
space = (spacing - len(par)) * " " | ||
else: | ||
space = "" | ||
self.menu_text += f"[param]{par}{space}:[/param] {value}\n" | ||
|
||
def add_cmd_translation(self, key: str, source: str = "", cond: bool = True): | ||
spacing = (23 - (len(key) + 4)) * " " | ||
if cond: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
Yup, was missing it. Now it should be good. Let me know what you think |