Skip to content

Commit

Permalink
update string translation
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis authored and nyalldawson committed Oct 3, 2024
1 parent e421f08 commit e9695d8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 25 deletions.
14 changes: 10 additions & 4 deletions python/plugins/MetaSearch/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from qgis.PyQt.QtWidgets import QAction
from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsApplication
from qgis.core import Qgis, QgsApplication
from MetaSearch.dialogs.maindialog import MetaSearchDialog
from MetaSearch.util import get_help_url, log_message, open_url, StaticContext

Expand All @@ -50,7 +50,9 @@ def initGui(self):
"""startup"""

# run
log_message('Initializing plugin', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', 'Initializing plugin'), Qgis.Info)

run_icon = QIcon('{}/{}'.format(self.context.ppath, 'images/MetaSearch.svg'))
self.action_run = QAction(run_icon, 'MetaSearch',
self.iface.mainWindow())
Expand Down Expand Up @@ -81,7 +83,9 @@ def initGui(self):
def unload(self):
"""teardown"""

log_message('Unloading plugin', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', 'Unloading plugin'), Qgis.Info)

# remove the plugin menu item and icon
self.iface.removePluginWebMenu(self.web_menu, self.action_run)
self.iface.removePluginWebMenu(self.web_menu, self.action_help)
Expand All @@ -90,7 +94,9 @@ def unload(self):
def run(self):
"""open MetaSearch"""

log_message('Running plugin', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', 'Running plugin'), Qgis.Info)

self.dialog.exec()

def help(self):
Expand Down
57 changes: 40 additions & 17 deletions python/plugins/MetaSearch/search_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
warnings.filterwarnings("ignore", category=ImportWarning)
from owslib.csw import CatalogueServiceWeb # spellok

from qgis.core import Qgis
from qgis.PyQt.QtCore import QCoreApplication

if owslib.__version__ < '0.25':
OWSLIB_OAREC_SUPPORTED = False
else:
Expand Down Expand Up @@ -86,7 +89,8 @@ def __init__(self, url, timeout, username, password, auth):
self.record_info_template = 'record_metadata_dc.html'
self.constraints = []

log_message(f'Connecting to CSW: {self.url}', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', f'Connecting to CSW: {self.url}'), Qgis.Info)
self.conn = CatalogueServiceWeb(self.url, # spellok
timeout=self.timeout,
username=self.username,
Expand All @@ -104,28 +108,34 @@ def query_records(self, bbox=[], keywords=None, limit=10, offset=1):
# even for a global bbox, if a spatial filter is applied, then
# the CSW server will skip records without a bbox
if bbox and bbox != ['-180', '-90', '180', '90']:
log_message(f'Setting bbox filter ({bbox})', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', f'Setting bbox filter ({bbox})'), Qgis.Info)
minx, miny, maxx, maxy = bbox
self.constraints.append(BBox([miny, minx, maxy, maxx],
crs='urn:ogc:def:crs:EPSG::4326'))

# keywords
if keywords:
# TODO: handle multiple word searches
log_message(f'Setting csw:AnyText filter {keywords}', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', f'Setting csw:AnyText filter {keywords}'),
Qgis.Info)
self.constraints.append(PropertyIsLike('csw:AnyText', keywords))

if len(self.constraints) > 1: # exclusive search (a && b)
self.constraints = [self.constraints]

log_message(f'Searching CSW: {self.url}', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', f'Searching CSW: {self.url}'), Qgis.Info)
self.conn.getrecords2(constraints=self.constraints, maxrecords=limit,
startposition=offset, esn='full')

self.matches = self.conn.results['matches']
self.returned = self.conn.results['returned']
log_message(f'Matches: {self.matches}', 'Info')
log_message(f'Returned: {self.returned}', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', f'Matches: {self.matches}'), Qgis.Info)
log_message(QCoreApplication.translate(
'MetaSearch', f'Returned: {self.returned}'), Qgis.Info)

self.request = self.conn.request
self.response = self.conn.response
Expand Down Expand Up @@ -159,7 +169,9 @@ def records(self):
return recs

def get_record(self, identifier):
log_message(f'Searching CSW for record: {identifier}', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', f'Searching CSW for record: {identifier}'),
Qgis.Info)
self.conn.getrecordbyid([identifier])

return self.conn.records[identifier]
Expand All @@ -183,7 +195,8 @@ def __init__(self, url, timeout, auth):
self.record_collection = None

if '/collections/' in self.url: # catalog is a collection
log_message('OARec endpoint is a collection', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', 'OARec endpoint is a collection'), Qgis.Info)
self.base_url, self.record_collection = self.url.split('/collections/') # noqa
self.conn = Records(
self.base_url, timeout=self.timeout, auth=self.auth)
Expand All @@ -196,7 +209,8 @@ def __init__(self, url, timeout, auth):
pass
self.request = self.conn.request
else:
log_message('OARec endpoint is not a collection', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', 'OARec endpoint is not a collection'), Qgis.Info)
self.conn = Records(self.url, timeout=self.timeout, auth=self.auth)
self.request = None

Expand All @@ -214,21 +228,26 @@ def query_records(self, bbox=[], keywords=None, limit=10, offset=1):
}

if keywords:
log_message(f'Setting keyword search {keywords}', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', f'Setting keyword search {keywords}'), Qgis.Info)
params['q'] = keywords
if bbox and bbox != ['-180', '-90', '180', '90']:
log_message(f'Setting bbox search {bbox}', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', f'Setting bbox search {bbox}'), Qgis.Info)
params['bbox'] = bbox

log_message(f'Searching OARec: {self.url}', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', f'Searching OARec: {self.url}'), Qgis.Info)
self.response = self.conn.collection_items(**params)

self.matches = self.response.get('numberMatched', 0)
self.returned = self.response.get('numberReturned', 0)
self.request = self.conn.request

log_message(f'Matches: {self.matches}', 'Info')
log_message(f'Returned: {self.returned}', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', f'Matches: {self.matches}'), Qgis.Info)
log_message(QCoreApplication.translate(
'MetaSearch', f'Returned: {self.returned}'), Qgis.Info)

def records(self):
recs = []
Expand Down Expand Up @@ -257,7 +276,9 @@ def records(self):
return recs

def get_record(self, identifier):
log_message(f'Searching OARec endpoint for item {identifier}', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', f'Searching OARec endpoint for item {identifier}'),
Qgis.Info)
return self.conn.collection_item(self.record_collection, identifier)

def parse_link(self, link):
Expand All @@ -276,10 +297,12 @@ def parse_link(self, link):
def get_catalog_service(url, catalog_type, timeout, username, password,
auth=None):
if catalog_type in [None, CATALOG_TYPES[0]]:
log_message('CSW endpoint detected', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', 'CSW endpoint detected'), Qgis.Info)
return CSW202Search(url, timeout, username, password, auth)
elif catalog_type == CATALOG_TYPES[1]:
log_message('OARec endpoint detected', 'Info')
log_message(QCoreApplication.translate(
'MetaSearch', 'OARec endpoint detected'), Qgis.Info)
if not OWSLIB_OAREC_SUPPORTED:
raise ValueError("OGC API - Records requires OWSLib 0.25 or above")
return OARecSearch(url, timeout, auth)
Expand Down
7 changes: 3 additions & 4 deletions python/plugins/MetaSearch/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from jinja2 import Environment, FileSystemLoader

from qgis.core import Qgis, QgsMessageLog, QgsSettings
from qgis.PyQt.QtCore import QCoreApplication, QUrl, QUrlQuery
from qgis.PyQt.QtCore import QUrl, QUrlQuery
from qgis.PyQt.QtWidgets import QMessageBox
from qgis.PyQt.uic import loadUiType

Expand Down Expand Up @@ -168,8 +168,7 @@ def clean_ows_url(url):
return url.toString()


def log_message(message, level='Info'):
def log_message(message, level=Qgis.Info):
"""helper function to emit logging messages"""

message_translated = QCoreApplication.translate('MetaSearch', message)
LOGGER.logMessage(message_translated, 'MetaSearch', getattr(Qgis, level, 'Info'))
LOGGER.logMessage(message, 'MetaSearch', level)

0 comments on commit e9695d8

Please sign in to comment.