mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Help translate terminal language (#2100)
* minor stylistic improvement * Add help translation Co-authored-by: James Maslek <jmaslek11@gmail.com>
This commit is contained in:
3
i18n/en.yml
vendored
3
i18n/en.yml
vendored
@@ -1,6 +1,5 @@
|
||||
en:
|
||||
_home_: >
|
||||
[info]Information, guides and support for the OpenBB Terminal[/info]
|
||||
_home_: Information, guides and support for the OpenBB Terminal
|
||||
about: discover the capabilities of the OpenBB Terminal (https://openbb.co/docs)
|
||||
support: pre-populate a support ticket for our team to evaluate
|
||||
update: attempt to update the terminal automatically (GitHub version)
|
||||
|
||||
181
i18n/help_translation.ipynb
vendored
Normal file
181
i18n/help_translation.ipynb
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4233a439-35bf-49d8-bf3f-eebd26f8def5",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Help translating terminal to other languages"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "20093add-f935-4007-b984-cf883e1c0ce8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Install libraries if they are not installed locally\n",
|
||||
"# !pip install pyyaml\n",
|
||||
"# !pip install txtai[pipeline]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "45a25f43-fcd3-4ed4-8a4c-fed3cd536cb5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"import yaml\n",
|
||||
"from txtai.pipeline import Translation\n",
|
||||
"\n",
|
||||
"translate = Translation()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7f52cc10-293e-48d6-b405-3a4e5fff990c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Select language to translate\n",
|
||||
"language_to_translate = 'pt'"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "d9978930-cc32-4fb9-b799-144d1de7b574",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Read default english dictionary\n",
|
||||
"english_dictionary = {}\n",
|
||||
"with open(\"en.yml\", \"r\") as stream:\n",
|
||||
" try:\n",
|
||||
" english_dictionary = yaml.safe_load(stream)['en']\n",
|
||||
" except yaml.YAMLError as exc:\n",
|
||||
" print(exc)\n",
|
||||
"\n",
|
||||
"# Translated file\n",
|
||||
"translated_file = f'{language_to_translate}.yml'"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "154f36cf-b260-432f-b9c7-0997ee970795",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"## Update other language dictionary or create from scratch"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b76629e7-9b85-41bf-be59-d21af4dd465c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"language_dictionary = {}\n",
|
||||
"\n",
|
||||
"if os.path.exists(translated_file):\n",
|
||||
" # Read already translated dictionary\n",
|
||||
" with open(translated_file, \"r\") as stream:\n",
|
||||
" try:\n",
|
||||
" language_dictionary = yaml.safe_load(stream)[language_to_translate]\n",
|
||||
" except yaml.YAMLError as exc:\n",
|
||||
" print(exc)\n",
|
||||
" \n",
|
||||
" # Iterate through english dictionary\n",
|
||||
" for k in english_dictionary:\n",
|
||||
" # Check if that variable doesn't existed on the already translated dictionary\n",
|
||||
" if k not in language_dictionary:\n",
|
||||
" # If the variable doesn't exist, let's update it to it's default\n",
|
||||
" language_dictionary[k] = translate(english_dictionary[k], language_to_translate)\n",
|
||||
" \n",
|
||||
"else:\n",
|
||||
" # Iterate through english dictionary\n",
|
||||
" for k in english_dictionary:\n",
|
||||
" try:\n",
|
||||
" # Replace english value by its translation\n",
|
||||
" language_dictionary[k] = translate(english_dictionary[k], language_to_translate)\n",
|
||||
" except:\n",
|
||||
" # Keep english language because there was an issue with the convertion\n",
|
||||
" language_dictionary[k] = english_dictionary[k]\n",
|
||||
"\n",
|
||||
"# Save dictionary to another language\n",
|
||||
"with open(f'{language_to_translate}.yml', 'w') as file:\n",
|
||||
" yaml.dump({language_to_translate: language_dictionary}, stream=file, allow_unicode=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "beb0bb1a-aca2-43c8-80b0-466919b46c79",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Update all other languages based on english dictionary"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "8dac2d8b-a429-4350-8b34-5143d02f35a2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"for language_to_translate in [val.split(\".\")[0] for val in os.listdir() if val.endswith(\"yml\") and val != \"en.yml\"]:\n",
|
||||
" # Read already translated dictionary\n",
|
||||
" with open(translated_file, \"r\") as stream:\n",
|
||||
" try:\n",
|
||||
" language_dictionary = yaml.safe_load(stream)[language_to_translate]\n",
|
||||
" except yaml.YAMLError as exc:\n",
|
||||
" print(exc)\n",
|
||||
" \n",
|
||||
" # Iterate through english dictionary\n",
|
||||
" for k in english_dictionary:\n",
|
||||
" # Check if that variable doesn't existed on the already translated dictionary\n",
|
||||
" if k not in language_dictionary:\n",
|
||||
" # If the variable doesn't exist, let's update it to it's default\n",
|
||||
" language_dictionary[k] = translate(english_dictionary[k], language_to_translate)\n",
|
||||
"\n",
|
||||
" # Save dictionary to another language\n",
|
||||
" with open(f'{language_to_translate}.yml', 'w') as file:\n",
|
||||
" yaml.dump({language_to_translate: language_dictionary}, stream=file, allow_unicode=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "116e615b-cc8f-4694-ab87-a422b3cd5c89",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
@@ -102,7 +102,7 @@ class TerminalController(BaseController):
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
mt = MenuText("")
|
||||
mt.add_custom("_home_")
|
||||
mt.add_info("_home_")
|
||||
mt.add_cmd("about")
|
||||
mt.add_cmd("support")
|
||||
mt.add_cmd("update")
|
||||
|
||||
Reference in New Issue
Block a user