Skip to content

Commit

Permalink
Make more strings translatable, #2595
Browse files Browse the repository at this point in the history
  • Loading branch information
aivarannamaa committed May 30, 2024
1 parent fc19581 commit ab05397
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 40 deletions.
5 changes: 3 additions & 2 deletions thonny/codeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from thonny import get_workbench, roughparse, tktextext, ui_utils
from thonny.common import TextRange
from thonny.languages import tr
from thonny.tktextext import EnhancedText
from thonny.ui_utils import EnhancedTextWithLogging, ask_string, compute_tab_stops

Expand Down Expand Up @@ -247,8 +248,8 @@ def set_content_as_bytes(self, data, keep_undo=False):
pass

encoding = ask_string(
"Bad encoding",
"Could not read as %s text.\nYou could try another encoding" % encoding,
tr("Bad encoding"),
tr("Could not read as %s text.\nYou could try another encoding") % encoding,
initial_value=encoding,
options=get_proposed_encodings(),
master=self.winfo_toplevel(),
Expand Down
12 changes: 7 additions & 5 deletions thonny/plugins/cpython_frontend/cp_front.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def __init__(self, master):
"You can activate an existing virtual environment also"
+ " via the right-click context menu in the file navagation"
+ " when selecting a virtual environment folder,"
+ " or the 'pyveng.cfg' file inside."
+ " or the 'pyvenv.cfg' file inside."
)
venv_text = "\n".join(textwrap.wrap(venv_text, 80))

Expand All @@ -310,7 +310,7 @@ def __init__(self, master):
last_row.columnconfigure(1, weight=1)
new_venv_link = ui_utils.create_action_label(
last_row,
"New virtual environment",
tr("New virtual environment"),
self._create_venv,
)
new_venv_link.grid(row=0, column=1, sticky="e", pady=10)
Expand Down Expand Up @@ -341,9 +341,11 @@ def _create_venv(self, event=None):
return

messagebox.showinfo(
"Creating new virtual environment",
"After clicking 'OK' you need to choose an empty directory, "
"which will be the root of your new virtual environment.",
tr("Creating new virtual environment"),
tr(
"After clicking 'OK' you need to choose an empty directory, "
"which will be the root of your new virtual environment."
),
parent=self,
)
path = None
Expand Down
4 changes: 2 additions & 2 deletions thonny/plugins/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ def pick_transfer_items(
return []
elif overwrites:
if askokcancel(
"Overwrite?",
"This operation will overwrite\n\n" + format_items(overwrites),
tr("Overwrite?"),
tr("This operation will overwrite %s") % format_items(overwrites) + "\n\n",
master=master,
):
return prepared_items
Expand Down
26 changes: 13 additions & 13 deletions thonny/plugins/micropython/base_flashing_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def populate_main_frame(self):
)
self._target_combo.bind("<<ComboboxSelected>>", self.register_settings_changed, True)

self._target_info_label = ttk.Label(self.main_frame, text="model")
self._target_info_label = ttk.Label(self.main_frame, text=tr("model"))
self._target_info_label.grid(row=2, column=1, sticky="e", padx=(epadx, 0), pady=(ipady, 0))
self._target_info_content_label = ttk.Label(self.main_frame)
self._target_info_content_label.grid(
Expand Down Expand Up @@ -112,7 +112,7 @@ def populate_main_frame(self):
)
self._variant_combo.bind("<<ComboboxSelected>>", self.register_settings_changed, True)

version_label = ttk.Label(self.main_frame, text="version")
version_label = ttk.Label(self.main_frame, text=tr("version"))
version_label.grid(row=7, column=1, sticky="e", padx=(epadx, 0), pady=(ipady, 0))
self._version_combo = MappingCombobox(
self.main_frame, mapping={}, exportselection=False, state="disabled"
Expand All @@ -122,7 +122,7 @@ def populate_main_frame(self):
)
self._version_combo.bind("<<ComboboxSelected>>", self.register_settings_changed, True)

variant_info_label = ttk.Label(self.main_frame, text="info")
variant_info_label = ttk.Label(self.main_frame, text=tr("info"))
variant_info_label.grid(row=8, column=1, sticky="e", padx=(epadx, 0), pady=(ipady, 0))
self._variant_info_content_label = AdvancedLabel(self.main_frame)
self._variant_info_content_label.grid(
Expand Down Expand Up @@ -218,13 +218,13 @@ def _update_variant_info(self):
current_variant = self._variant_combo.get_selected_value()
if not self._downloaded_variants:
url = None
text = "[downloading variants info ...]"
text = "[" + tr("downloading variants info") + "...]"
elif current_variant:
url = current_variant["info_url"]
text = url
elif self._variant_combo.mapping:
url = None
text = f"[select one from {len(self._variant_combo.mapping)} variants]"
text = "[" + tr("select one from %d variants") % len(self._variant_combo.mapping)
else:
url = None
text = ""
Expand All @@ -251,15 +251,15 @@ def on_change_family(self, family: Optional[str]) -> None:
if variant.get("popular", False)
}
if populars and len(populars) < len(filtered_mapping):
enhanced_mapping = {"--- MOST POPULAR " + "-" * 100: {}}
enhanced_mapping = {"--- " + tr("MOST POPULAR") + " " + "-" * 100: {}}
for variant in populars.values():
popular_variant = variant.copy()
# need different title to distinguish it from the same item in ALL VARIANTS
popular_title = self._create_variant_description(variant) + " "
popular_variant["title"] = popular_title
enhanced_mapping[popular_title] = popular_variant

enhanced_mapping["--- ALL VARIANTS " + "-" * 100] = {}
enhanced_mapping["--- " + tr("ALL VARIANTS") + " " + "-" * 100] = {}
enhanced_mapping.update(filtered_mapping)
else:
enhanced_mapping = filtered_mapping
Expand Down Expand Up @@ -354,7 +354,7 @@ def _tweak_variants(self, variants):
msg = f"Could not download variants info from {self.get_variants_url()}"
logger.exception(msg)
self.append_text(msg + "\n")
self.set_action_text("Error!")
self.set_action_text(tr("Error!"))
self.grid_progress_widgets()

if latest_prerelease_substitute:
Expand Down Expand Up @@ -421,17 +421,17 @@ def _perform_work_and_update_status(
self.append_text("\n" + str(e))
else:
self.append_text("\n" + "".join(traceback.format_exc()))
self.set_action_text("Error...")
self.set_action_text(tr("Error") + "...")
self.report_done(False)
return
finally:
if temp_file:
os.remove(temp_file)

if core_result:
self.set_action_text("Done!")
self.set_action_text(tr("Done!"))
else:
self.set_action_text("Error...")
self.set_action_text(tr("Error") + "...")

self.report_done(core_result)

Expand Down Expand Up @@ -459,7 +459,7 @@ def _download_to_temp(self, download_info: Dict[str, str]) -> Optional[str]:

logger.debug("Downloading from %s", download_url)

self.set_action_text("Starting...")
self.set_action_text(tr("Starting") + "...")
self.append_text("Downloading from %s\n" % download_url)

req = urllib.request.Request(
Expand Down Expand Up @@ -495,7 +495,7 @@ def _download_to_temp(self, download_info: Dict[str, str]) -> Optional[str]:
bytes_copied += len(block)
percent_done = bytes_copied / size * 100
percent_str = "%.0f%%" % (percent_done)
self.set_action_text("Downloading... " + percent_str)
self.set_action_text(tr("Downloading") + "... " + percent_str)

# leaving left half of the progressbar for downloading
self.report_progress(percent_done, 200)
Expand Down
28 changes: 16 additions & 12 deletions thonny/plugins/micropython/uf2dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, Dict, List, Optional, Set, Tuple

from thonny.common import UserError
from thonny.languages import tr
from thonny.misc_utils import get_win_volume_name, list_volumes
from thonny.plugins.micropython.base_flashing_dialog import (
BaseFlashingDialog,
Expand All @@ -18,7 +19,7 @@

class Uf2FlashingDialog(BaseFlashingDialog):
def get_target_label(self) -> str:
return "Target volume"
return tr("Target volume")

def get_variants_url(self) -> str:
return f"https://raw.githubusercontent.com/thonny/thonny/master/data/{self.firmware_name.lower()}-variants-uf2.json"
Expand Down Expand Up @@ -122,20 +123,23 @@ def get_info_file_name(self):

def get_instructions(self) -> Optional[str]:
return (
f"Here you can install or update {self.firmware_name} for devices having an UF2 bootloader\n"
"(this includes most boards meant for beginners).\n"
"\n"
"1. Put your device into bootloader mode: \n"
" - some devices have to be plugged in while holding the BOOTSEL button,\n"
" - some require double-tapping the RESET button with proper rhythm.\n"
"2. Wait for couple of seconds until the target volume appears.\n"
"3. Select desired variant and version.\n"
"4. Click 'Install' and wait for some seconds until done.\n"
"5. Close the dialog and start programming!"
tr(
"Here you can install or update %s for devices having an UF2 bootloader\n"
"(this includes most boards meant for beginners).\n"
"\n"
"1. Put your device into bootloader mode: \n"
" - some devices have to be plugged in while holding the BOOTSEL button,\n"
" - some require double-tapping the RESET button with proper rhythm.\n"
"2. Wait for couple of seconds until the target volume appears.\n"
"3. Select desired variant and version.\n"
"4. Click 'Install' and wait for some seconds until done.\n"
"5. Close the dialog and start programming!"
)
% self.firmware_name
)

def get_title(self):
return f"Install or update {self.firmware_name} (UF2)"
return tr("Install or update %s (UF2)") % self.firmware_name

def perform_core_operation(
self,
Expand Down
12 changes: 7 additions & 5 deletions thonny/plugins/pip_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,15 +951,17 @@ def _fetch_search_results(self, query: str) -> List[DistInfo]: ...

def _advertise_pipkin(self):
self._append_info_text("\n\n")
self._append_info_text("Under the hood " + "\n", ("caption", "right"))
self._append_info_text(tr("Under the hood") + " \n", ("caption", "right"))
self._append_info_text(
"This dialog uses `pipkin`, a new command line tool for managing "
"MicroPython and CircuitPython packages. ",
tr(
"This dialog uses `pipkin`, a command line tool for managing "
"MicroPython and CircuitPython packages."
)
+ " \n",
("right",),
)
self._append_info_text("See ", ("right",))
self._append_info_text("https://pypi.org/project/pipkin/", ("url", "right"))
self._append_info_text(" for more info. \n", ("right",))
self._append_info_text(" \n", ("right",))

def get_large_padding(self):
return ems_to_pixels(1.5)
Expand Down
2 changes: 1 addition & 1 deletion thonny/running.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ def ready_for_remote_file_operations(self, show_message=False):
"Device is busy -- can't perform this action now."
+ "\nPlease wait or cancel current work and try again!"
)
messagebox.showerror("Can't complete", msg, master=get_workbench())
messagebox.showerror(tr("Can't complete"), msg, master=get_workbench())

return ready

Expand Down

0 comments on commit ab05397

Please sign in to comment.