Skip to content

Commit

Permalink
gettext implementation
Browse files Browse the repository at this point in the history
implemented and tested, it compiles, installs, and also runs.
  • Loading branch information
BloodSakura3774 committed Sep 29, 2024
1 parent eaa4f1a commit 90e26d4
Show file tree
Hide file tree
Showing 21 changed files with 212 additions and 197 deletions.
7 changes: 4 additions & 3 deletions MethodicConfigurator/annotate_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from os import path as os_path
from os import popen as os_popen
from MethodicConfigurator.internationalization import _

import glob
import re
Expand Down Expand Up @@ -51,8 +52,8 @@


def arg_parser():
parser = argparse.ArgumentParser(description=_('Fetches on-line ArduPilot parameter documentation and adds it to the ')
_('specified file or to all *.param and *.parm files in the specified directory.'))
parser = argparse.ArgumentParser(description=_('Fetches on-line ArduPilot parameter documentation and adds it to the '
'specified file or to all *.param and *.parm files in the specified directory.'))
parser.add_argument('target',
help=_('The target file or directory.'),
)
Expand Down Expand Up @@ -341,7 +342,7 @@ def get_xml_data(base_url: str, directory: str, filename: str, vehicle_type: str
url = base_url + filename
response = requests_get(url, timeout=5)
if response.status_code != 200:
logging.warning_("Remote URL: %s"), url)
logging.warning_("Remote URL: %s"), url
raise requests_exceptions.RequestException(_(f"HTTP status code {response.status_code}"))
except requests_exceptions.RequestException as e:
logging.warning(_("Unable to fetch XML data: %s", e))
Expand Down
22 changes: 11 additions & 11 deletions MethodicConfigurator/ardupilot_methodic_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#from logging import warning as logging_warning
from logging import error as logging_error
from sys import exit as sys_exit

from MethodicConfigurator.internationalization import _
from MethodicConfigurator.backend_filesystem import LocalFilesystem
from MethodicConfigurator.backend_flightcontroller import FlightController

Expand Down Expand Up @@ -46,16 +46,16 @@ def argument_parser():
Returns:
argparse.Namespace: An object containing the parsed arguments.
"""
parser = argparse.ArgumentParser(description=_('ArduPilot methodic configurator is a simple GUI with a table that lists ')
_('parameters. The GUI reads intermediate parameter files from a directory and ')
_('displays their parameters in a table. Each row displays the parameter name, ')
_('its current value on the flight controller, its new value from the selected ')
_('intermediate parameter file, and an "Upload" checkbox. The GUI includes "Upload ')
_('selected params to FC" and "Skip" buttons at the bottom. ')
_('When "Upload Selected to FC" is clicked, it uploads the selected parameters to the ')
_('flight controller. ')
_('When "Skip" is pressed, it skips to the next intermediate parameter file. ')
_('The process gets repeated for each intermediate parameter file.'))
parser = argparse.ArgumentParser(description=_('ArduPilot methodic configurator is a simple GUI with a table that lists '
'parameters. The GUI reads intermediate parameter files from a directory and '
'displays their parameters in a table. Each row displays the parameter name, '
'its current value on the flight controller, its new value from the selected '
'intermediate parameter file, and an "Upload" checkbox. The GUI includes "Upload '
'selected params to FC" and "Skip" buttons at the bottom. '
'When "Upload Selected to FC" is clicked, it uploads the selected parameters to the '
'flight controller. '
'When "Skip" is pressed, it skips to the next intermediate parameter file. '
'The process gets repeated for each intermediate parameter file.'))
parser = FlightController.add_argparse_arguments(parser)
parser = LocalFilesystem.add_argparse_arguments(parser)
parser = ComponentEditorWindow.add_argparse_arguments(parser)
Expand Down
2 changes: 1 addition & 1 deletion MethodicConfigurator/argparse_check_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from operator import ge
from operator import lt
from operator import le

from MethodicConfigurator.internationalization import _

class CheckRange(Action):
'''
Expand Down
16 changes: 8 additions & 8 deletions MethodicConfigurator/backend_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from os import rename as os_rename

from platform import system as platform_system

from MethodicConfigurator.internationalization import _
from shutil import copy2 as shutil_copy2
from shutil import copytree as shutil_copytree

Expand Down Expand Up @@ -611,16 +611,16 @@ def add_argparse_arguments(parser):
parser.add_argument('--vehicle-dir',
type=str,
default=os_getcwd(),
help=_('Directory containing vehicle-specific intermediate parameter files. ')
_('Defaults to the current working directory'))
help=_('Directory containing vehicle-specific intermediate parameter files. '
'Defaults to the current working directory'))
parser.add_argument('--n',
type=int,
default=-1,
help=_('Start directly on the nth intermediate parameter file (skips previous files). ')
_('Default is to start on the file next to the last that you wrote to the flight controller.')
_('If the file does not exist, it will start on the first file.'))
help=_('Start directly on the nth intermediate parameter file (skips previous files). '
'Default is to start on the file next to the last that you wrote to the flight controller.'
'If the file does not exist, it will start on the first file.'))
parser.add_argument('--allow-editing-template-files',
action='store_true',
help=_('Allow opening and editing template files directly. ')
_('Only for software developers that know what they are doing.'))
help=_('Allow opening and editing template files directly. '
'Only for software developers that know what they are doing.'))
return parser
30 changes: 15 additions & 15 deletions MethodicConfigurator/backend_filesystem_configuration_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from json import load as json_load
from json import JSONDecodeError

from MethodicConfigurator.internationalization import _
from typing import Tuple

from MethodicConfigurator.annotate_params import Par
Expand Down Expand Up @@ -56,8 +56,8 @@ def re_init(self, vehicle_dir: str, vehicle_type: str):
file_found = True
if self.log_loaded_file:
if i == 0:
logging_warning(_("Configuration steps '%s' loaded from %s ") \
_("(overwriting default configuration steps)."),
logging_warning(_("Configuration steps '%s' loaded from %s " \
"(overwriting default configuration steps)."),
self.configuration_steps_filename, directory)
if i == 1:
logging_info(_("Configuration steps '%s' loaded from %s."),
Expand Down Expand Up @@ -90,12 +90,12 @@ def __validate_parameters_in_configuration_steps(self, filename: str, file_info:
return
for parameter, parameter_info in file_info[parameter_type + '_parameters'].items():
if "New Value" not in parameter_info:
logging_error(_("Error in file '%s': '%s' %s parameter '%s'")
_(" 'New Value' attribute not found."),
logging_error(_("Error in file '%s': '%s' %s parameter '%s'"
" 'New Value' attribute not found."),
self.configuration_steps_filename, filename, parameter_type, parameter)
if "Change Reason" not in parameter_info:
logging_error(_("Error in file '%s': '%s' %s parameter '%s'")
_(" 'Change Reason' attribute not found."),
logging_error(_("Error in file '%s': '%s' %s parameter '%s'"
" 'Change Reason' attribute not found."),
self.configuration_steps_filename, filename, parameter_type, parameter)

def compute_parameters(self, filename: str, file_info: dict, parameter_type: str, variables: dict) -> str:
Expand All @@ -112,8 +112,8 @@ def compute_parameters(self, filename: str, file_info: dict, parameter_type: str
try:
if ('fc_parameters' in str(parameter_info["New Value"])) and \
('fc_parameters' not in variables or variables['fc_parameters'] == {}):
error_msg = f"In file '{self.configuration_steps_filename}': '{filename}' {parameter_type} " \
_(f"parameter '{parameter}' could not be computed: 'fc_parameters' not found, is an FC connected?")
error_msg = _(f"In file '{self.configuration_steps_filename}': '{filename}' {parameter_type} " \
f"parameter '{parameter}' could not be computed: 'fc_parameters' not found, is an FC connected?")
if parameter_type == 'forced':
logging_error(error_msg)
return error_msg
Expand All @@ -136,8 +136,8 @@ def compute_parameters(self, filename: str, file_info: dict, parameter_type: str
destination[filename] = {}
destination[filename][parameter] = Par(float(result), parameter_info["Change Reason"])
except (SyntaxError, NameError, KeyError, StopIteration) as e:
error_msg = f"In file '{self.configuration_steps_filename}': '{filename}' {parameter_type} " \
_(f"parameter '{parameter}' could not be computed: {e}")
error_msg = _(f"In file '{self.configuration_steps_filename}': '{filename}' {parameter_type} " \
f"parameter '{parameter}' could not be computed: {e}")
if parameter_type == 'forced':
logging_error(error_msg)
return error_msg
Expand All @@ -158,11 +158,11 @@ def get_documentation_text_and_url(self, selected_file: str, prefix_key: str) ->
documentation = self.configuration_steps.get(selected_file, {}) if \
self.configuration_steps else None
if documentation is None:
text = _(f"File '{self.configuration_steps_filename}' not found. ") \
_("No intermediate parameter configuration steps available")
text = _(f"File '{self.configuration_steps_filename}' not found. " \
"No intermediate parameter configuration steps available")
url = None
else:
text = documentation.get(prefix_key + "_text", _(f"No documentation available for {selected_file} in the ")
_(f"{self.configuration_steps_filename} file"))
text = documentation.get(prefix_key + "_text", _(f"No documentation available for {selected_file} in the "
f"{self.configuration_steps_filename} file"))
url = documentation.get(prefix_key + "_url", None)
return text, url
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from re import match as re_match
from re import escape as re_escape
from re import sub as re_sub

from MethodicConfigurator.internationalization import _
# from sys import exit as sys_exit
from logging import error as logging_error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#from logging import info as logging_info
#from logging import warning as logging_warning
from logging import error as logging_error

from MethodicConfigurator.internationalization import _
from re import match as re_match

from json import load as json_load
Expand Down
12 changes: 6 additions & 6 deletions MethodicConfigurator/backend_flightcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from logging import info as logging_info
from logging import warning as logging_warning
from logging import error as logging_error

from MethodicConfigurator.internationalization import _
from time import sleep as time_sleep
from time import time as time_time
from os import path as os_path
Expand Down Expand Up @@ -273,9 +273,9 @@ def __create_connection_with_retry(self, progress_callback, retries: int = 3,

def __process_autopilot_version(self, m, banner_msgs) -> str:
if m is None:
return _("No AUTOPILOT_VERSION MAVLink message received, connection failed.\n") \
_("Only ArduPilot versions newer than 4.3.8 are supported.\n") \
_("Make sure parameter SERIAL0_PROTOCOL is set to 2")
return _("No AUTOPILOT_VERSION MAVLink message received, connection failed.\n" \
"Only ArduPilot versions newer than 4.3.8 are supported.\n" \
"Make sure parameter SERIAL0_PROTOCOL is set to 2")
self.info.set_capabilities(m.capabilities)
self.info.set_flight_sw_version(m.flight_sw_version)
self.info.set_board_version(m.board_version)
Expand Down Expand Up @@ -538,6 +538,6 @@ def add_argparse_arguments(parser):
max=50,
action=CheckRange,
default=7,
help=_('Flight controller reboot time. ')
_('Default is %(default)s'))
help=_('Flight controller reboot time. '
'Default is %(default)s'))
return parser
12 changes: 6 additions & 6 deletions MethodicConfigurator/backend_mavftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import time
import random
import os

from MethodicConfigurator.internationalization import _
from io import BytesIO as SIO

import sys
Expand Down Expand Up @@ -1332,14 +1332,14 @@ def argument_parser():

This function sets up an argument parser to handle the command-line arguments for the script.
"""
parser = ArgumentParser(description=_('MAVFTP - MAVLink File Transfer Protocol https://mavlink.io/en/services/ftp.html')
_(' A tool to do file operations between a ground control station and a drone using the MAVLink')
_(' protocol.'))
parser = ArgumentParser(description=_('MAVFTP - MAVLink File Transfer Protocol https://mavlink.io/en/services/ftp.html'
' A tool to do file operations between a ground control station and a drone using the MAVLink'
' protocol.'))
parser.add_argument("--baudrate", type=int, default=115200,
help=_("master port baud rate. Defaults to %(default)s"))
parser.add_argument("--device", type=str, default='',
help=_("serial device. For windows use COMx where x is the port number. ")
_("For Unix use /dev/ttyUSBx where x is the port number. Defaults to autodetection"))
help=_("serial device. For windows use COMx where x is the port number. "
"For Unix use /dev/ttyUSBx where x is the port number. Defaults to autodetection"))
parser.add_argument("--source-system", type=int, default=250,
help=_('MAVLink source system for this GCS. Defaults to %(default)s'))
parser.add_argument("--loglevel", default="INFO",
Expand Down
2 changes: 1 addition & 1 deletion MethodicConfigurator/common_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'''

from MethodicConfigurator.version import VERSION

from MethodicConfigurator.internationalization import _

def add_common_arguments_and_parse(parser):
parser.add_argument('--loglevel',
Expand Down
12 changes: 6 additions & 6 deletions MethodicConfigurator/frontend_tkinter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from logging import error as logging_error

from platform import system as platform_system

from MethodicConfigurator.internationalization import _
from PIL import Image
from PIL import ImageTk

Expand All @@ -39,15 +39,15 @@ def show_error_message(title: str, message: str):


def show_no_param_files_error(dirname: str):
error_message = _(f"No intermediate parameter files found in the selected '{dirname}' vehicle directory.\n") \
_("Please select and step inside a vehicle directory containing valid ArduPilot intermediate parameter files.\n\n") \
_("Make sure to step inside the directory (double-click) and not just select it.")
error_message = _(f"No intermediate parameter files found in the selected '{dirname}' vehicle directory.\n" \
"Please select and step inside a vehicle directory containing valid ArduPilot intermediate parameter files.\n\n" \
"Make sure to step inside the directory (double-click) and not just select it.")
show_error_message(_("No Parameter Files Found"), error_message)


def show_no_connection_error(error_string: str):
error_message = _(f"{error_string}\n\nPlease connect a flight controller to the PC,\n") \
_("wait at least 7 seconds and retry.")
error_message = _(f"{error_string}\n\nPlease connect a flight controller to the PC,\n" \
"wait at least 7 seconds and retry.")
show_error_message(_("No Connection to the Flight Controller"), error_message)


Expand Down
Loading

0 comments on commit 90e26d4

Please sign in to comment.