Skip to content

Commit

Permalink
V0.4 rc2 (#23)
Browse files Browse the repository at this point in the history
* fix bash scripts for compiling translations

* fix translation fallback

* update zip

* fix: cache dir not saved

* fix: check file size for big downloads

* v0.3.94 update zip
  • Loading branch information
Wilhelm Berg committed Jul 24, 2019
1 parent 672ff68 commit 3c52750
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 39 deletions.
4 changes: 3 additions & 1 deletion CKAN-Browser/Makefile
Expand Up @@ -24,7 +24,7 @@


#Add iso code for any locales you want to support here (space separated)
LOCALES = CKANBrowser_en CKANBrowser_de CKANBrowser_fi CKANBrowser_fr CKANBrowser_ja
LOCALES = 'CKANBrowser_en CKANBrowser_de CKANBrowser_fi CKANBrowser_fr CKANBrowser_ja'

LRELEASE = lrelease

Expand Down Expand Up @@ -179,6 +179,7 @@ transup:
@echo "------------------------------------------------"
@echo "Updating translation files with any new strings."
@echo "------------------------------------------------"
@echo $(LOCALES)
@chmod +x scripts/update-strings.sh
@scripts/update-strings.sh $(LOCALES)

Expand All @@ -187,6 +188,7 @@ transcompile:
@echo "----------------------------------------"
@echo "Compiled translation files to .qm files."
@echo "----------------------------------------"
@echo $(LOCALES)
@chmod +x scripts/compile-strings.sh
@scripts/compile-strings.sh $(LRELEASE) $(LOCALES)

Expand Down
57 changes: 38 additions & 19 deletions CKAN-Browser/ckan_browser.py
Expand Up @@ -23,17 +23,14 @@
from PyQt5.QtCore import QSettings, QTranslator, qVersion, QCoreApplication
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QAction
# Initialize Qt resources from file resources.py
#import resources_rc
# Import the code for the dialog
from qgis.core import QgsMessageLog, Qgis
from .ckan_browser_dialog import CKANBrowserDialog
from .ckan_browser_dialog_settings import CKANBrowserDialogSettings
import os.path
from .settings import Settings
from .util import Util



class CKANBrowser:
"""QGIS Plugin Implementation."""

Expand All @@ -45,41 +42,63 @@ def __init__(self, iface):
application at run time.
:type iface: QgsInterface
"""
QgsMessageLog.logMessage('__init__', 'CKAN-Browser', Qgis.Info)
QSettings().setValue("ckan_browser/isopen", False)
# Save reference to the QGIS interface
self.iface = iface

# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
QgsMessageLog.logMessage(u'plugin directory: {}'.format(self.plugin_dir), 'CKAN-Browser', Qgis.Info)

# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
QgsMessageLog.logMessage(u'locale: {}'.format(locale), 'CKAN-Browser', Qgis.Info)
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'CKANBrowser_{}.qm'.format(locale))

# load english file for testing
# locale_path = os.path.join(
# self.plugin_dir,
# 'i18n',
# 'CKANBrowser_en.qm')

QgsMessageLog.logMessage(u'locale_path: {}'.format(locale_path), 'CKAN-Browser', Qgis.Info)

locale_path_en = os.path.join(
self.plugin_dir,
'i18n',
'CKANBrowser_en.qm'
)

# if we don't have translation for current locale, completely switch to English
if not os.path.exists(locale_path):
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'CKANBrowser_en.qm')

locale = 'en'
locale_path = locale_path_en

# if locale is not 'en' then additionally load 'en' as fallback for untranslated elements.
# !!! this has to be done before(!) adding the actual locale:
# https://doc.qt.io/qt-5/qcoreapplication.html#installTranslator
# "Translations are searched for in the reverse order in which they were installed, so the most recently
# installed translation file is searched first and the first translation file installed is searched last."
if locale != 'en':
QgsMessageLog.logMessage(u'loading "en" fallback: {}'.format(locale_path_en), 'CKAN-Browser', Qgis.Info)
self.translator_en = QTranslator()
self.translator_en.load(locale_path_en)
if not QCoreApplication.installTranslator(self.translator_en):
QgsMessageLog.logMessage(u'could not install translator: {}'.format(locale_path_en), 'CKAN-Browser', Qgis.Critical)
else:
QgsMessageLog.logMessage(u'locale "en" installed', 'CKAN-Browser', Qgis.Info)

if os.path.exists(locale_path):
self.translator = QTranslator()

# load translations according to locale
self.translator.load(locale_path)

if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
if not QCoreApplication.installTranslator(self.translator):
QgsMessageLog.logMessage(u'could not install translator: {}'.format(locale_path), 'CKAN-Browser', Qgis.Critical)
else:
QgsMessageLog.logMessage(u'locale "{}" installed'.format(locale), 'CKAN-Browser', Qgis.Info)

self.settings = Settings()
self.settings.load()
self.util = Util(self.settings, self.iface.mainWindow())
self.util.msg_log_debug('__init__')

# TODO ping API

Expand Down
1 change: 1 addition & 0 deletions CKAN-Browser/ckan_browser_dialog_settings.py
Expand Up @@ -96,6 +96,7 @@ def save(self):
)
return

self.settings.cache_dir = cache_dir
self.settings.debug = self.IDC_chkbox_show_debug_info.isChecked()

authcfg = self.IDC_leAuthCfg.text()
Expand Down
14 changes: 3 additions & 11 deletions CKAN-Browser/ckanconnector.py
Expand Up @@ -146,21 +146,13 @@ def get_file_size(self, url):
except:
return False, self.util.tr(u'cc_url_error').format(url, sys.exc_info()[1]), Exception(self.util.tr(u'cc_url_error'))

# HACK
# headers and their values are returned as strings like this:
# "b'95140771'"
# how to fix this properly???
if "b'Content-Length'" not in request_head.headers:
self.util.msg_log_debug(u'No content-length in response header! Returning 0.')
if 'Content-Length' not in request_head.headers:
self.util.msg_log_warning(u'No content-length in response header! Returning 0.')
for h in request_head.headers:
self.util.msg_log_debug(u'{}'.format(h))
return True, 0, None

# HACK
# headers are returned as strings like this: "b'95140771'"
# how to fix this properly???
#content_length = request_head.headers[b'content-length']
content_length = request_head.headers["b'Content-Length'"].replace('b', '').replace("'", '')
content_length = request_head.headers['Content-Length']
file_size = int(content_length) / 1000000 # divide to get MB

self.util.msg_log_debug(u'Content-Length: {0} MB'.format(file_size))
Expand Down
Binary file added CKAN-Browser/i18n/CKANBrowser_de.qm
Binary file not shown.
Binary file added CKAN-Browser/i18n/CKANBrowser_fi.qm
Binary file not shown.
2 changes: 1 addition & 1 deletion CKAN-Browser/i18n/CKANBrowser_fi.ts
Expand Up @@ -121,7 +121,7 @@
<message>
<location filename="../ckan_browser_dialog_base.ui" line="517"/>
<source>?</source>
<translation type="unfinished">?</translation>
<translation>?</translation>
</message>
<message>
<location filename="../ckan_browser_dialog_base.ui" line="259"/>
Expand Down
Binary file added CKAN-Browser/i18n/CKANBrowser_fr.qm
Binary file not shown.
4 changes: 2 additions & 2 deletions CKAN-Browser/i18n/CKANBrowser_fr.ts
Expand Up @@ -56,7 +56,7 @@
<message>
<location filename="../ckan_browser_dialog_base.ui" line="299"/>
<source>dlg_base_srch_rslt</source>
<translation type="unfinished">Résultats:</translation>
<translation>Résultats:</translation>
</message>
<message>
<location filename="../ckan_browser_dialog_base.ui" line="316"/>
Expand Down Expand Up @@ -91,7 +91,7 @@
<message>
<location filename="../ckan_browser_dialog_base.ui" line="408"/>
<source>dlg_base_data_list</source>
<translation type="unfinished">&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Données trouvées:&lt;br /&gt;Choisir le jeu de données à télécharger.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</translation>
<translation>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Données trouvées:&lt;br /&gt;Choisir le jeu de données à télécharger.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</translation>
</message>
<message>
<location filename="../ckan_browser_dialog_base.ui" line="449"/>
Expand Down
Binary file added CKAN-Browser/i18n/CKANBrowser_ja.qm
Binary file not shown.
2 changes: 1 addition & 1 deletion CKAN-Browser/i18n/CKANBrowser_ja.ts
Expand Up @@ -121,7 +121,7 @@
<message>
<location filename="../ckan_browser_dialog_base.ui" line="517"/>
<source>?</source>
<translation type="unfinished">?</translation>
<translation>?</translation>
</message>
<message>
<location filename="../ckan_browser_dialog_base.ui" line="259"/>
Expand Down
2 changes: 1 addition & 1 deletion CKAN-Browser/metadata.txt
Expand Up @@ -11,7 +11,7 @@ name=CKAN-Browser
qgisMinimumVersion=3.0
about=Download and display Open Data from CKAN Metadata Servers
description=Download and display Open Data from CKAN Metadata Servers
version=0.3.93
version=0.3.94
author=BergWerkGIS
email=wb@BergWerk-GIS.at

Expand Down
2 changes: 1 addition & 1 deletion CKAN-Browser/scripts/compile-strings.sh
Expand Up @@ -2,7 +2,7 @@
LRELEASE=$1
LOCALES=$2


echo ${LOCALES}
for LOCALE in ${LOCALES}
do
echo "Processing: ${LOCALE}.ts"
Expand Down
Binary file modified CKANBrowser.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions plugins.xml
@@ -1,8 +1,8 @@
<?xml version = '1.0' encoding = 'UTF-8'?>
<plugins>
<pyqgis_plugin name="CKAN-Browser" version="0.3.93">
<pyqgis_plugin name="CKAN-Browser" version="0.3.94">
<description><![CDATA[Download and display CKAN enabled Open Data Portals]]></description>
<version>0.3.93</version>
<version>0.3.94</version>
<qgis_minimum_version>3.0.0</qgis_minimum_version>
<qgis_maximum_version>3.99.0</qgis_maximum_version>
<homepage>https://github.com/BergWerkGIS/QGIS-CKAN-Browser</homepage>
Expand Down

0 comments on commit 3c52750

Please sign in to comment.