Skip to content

Commit

Permalink
Refactor translation handling in the plugin by introducing a utility …
Browse files Browse the repository at this point in the history
…function and updating UI elements to use it for localization.
  • Loading branch information
alukach committed Feb 13, 2025
1 parent ca7d52c commit 34d9236
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
3 changes: 1 addition & 2 deletions ee_plugin/ee_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ def tr(self, message):
:returns: Translated version of message.
:rtype: QString
"""
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate("GoogleEarthEngine", message)
return utils.translate(message)

def initGui(self):
"""Initialize the plugin GUI."""
Expand Down
42 changes: 27 additions & 15 deletions ee_plugin/ui/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)

from .. import Map, utils
from ..utils import translate as _


def DefaultNullQgsDateEdit(
Expand All @@ -36,53 +37,61 @@ def add_feature_collection_form(
) -> QtWidgets.QDialog:
"""Add a GEE Feature Collection to the map."""
dialog = build_vbox_dialog(
windowTitle="Add Feature Collection",
windowTitle=_("Add Feature Collection"),
widgets=[
build_form_group_box(
title="Source",
title=_("Source"),
rows=[
(
QtWidgets.QLabel(
toolTip=_("The Earth Engine Feature Collection ID."),
text="<br />".join(
[
"Add GEE Feature Collection to Map",
_("Feature Collection ID"),
"e.g. <code>USGS/WBD/2017/HUC06</code>",
]
),
),
QtWidgets.QLineEdit(
objectName="feature_collection_id",
whatsThis=(
),
),
(
QtWidgets.QLabel(
_("Retain as a vector layer"),
toolTip=_(
"Store as a vector layer rather than WMS Raster layer."
),
whatsThis=_(
"Attempt to retain the layer as a vector layer, running "
"the risk of encountering Earth Engine API limitations if "
"the layer is large. Otherwise, the layer will be added as "
"a WMS raster layer."
),
),
),
(
"Retain as a vector layer",
QtWidgets.QCheckBox(objectName="as_vector"),
QtWidgets.QCheckBox(
objectName="as_vector",
),
),
],
),
build_form_group_box(
title="Filter by Properties",
title=_("Filter by Properties"),
collapsable=True,
collapsed=True,
rows=[
(
"Name",
_("Name"),
QtWidgets.QLineEdit(objectName="filter_name"),
),
(
"Value",
_("Value"),
QtWidgets.QLineEdit(objectName="filter_value"),
),
],
),
build_form_group_box(
title="Filter by Dates",
title=_("Filter by Dates"),
collapsable=True,
collapsed=True,
rows=[
Expand All @@ -98,15 +107,18 @@ def add_feature_collection_form(
),
gui.QgsExtentGroupBox(
objectName="extent",
title="Filter by Coordinates",
title=_("Filter by Coordinates"),
collapsed=True,
),
build_form_group_box(
title="Visualization",
title=_("Visualization"),
collapsable=True,
collapsed=True,
rows=[
("Color", gui.QgsColorButton(objectName="viz_color_hex")),
(
_("Color"),
gui.QgsColorButton(objectName="viz_color_hex"),
),
],
),
],
Expand Down
8 changes: 8 additions & 0 deletions ee_plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ee
import qgis
from qgis.core import QgsProject, QgsRasterLayer, QgsVectorLayer, QgsMapLayer
from qgis.PyQt.QtCore import QCoreApplication


class VisualizeParams(TypedDict, total=False):
Expand Down Expand Up @@ -293,3 +294,10 @@ def check_version() -> None:
Check if we have the latest plugin version.
"""
qgis.utils.plugins["ee_plugin"].check_version()


def translate(message: str) -> str:
"""
Helper to translate messages.
"""
return QCoreApplication.translate("GoogleEarthEngine", message)

0 comments on commit 34d9236

Please sign in to comment.