Merge lp:~raoul-snyman/openlp/fix-translations-2.4 into lp:openlp/2.4

Proposed by Raoul Snyman
Status: Merged
Merged at revision: 2679
Proposed branch: lp:~raoul-snyman/openlp/fix-translations-2.4
Merge into: lp:openlp/2.4
Diff against target: 262 lines (+146/-16)
5 files modified
CHANGELOG.rst (+1/-0)
openlp/core/__init__.py (+6/-7)
openlp/core/utils/languagemanager.py (+5/-3)
openlp/plugins/songs/forms/songmaintenanceform.py (+4/-5)
tests/interfaces/openlp_plugins/songs/forms/test_songmaintenanceform.py (+130/-1)
To merge this branch: bzr merge lp:~raoul-snyman/openlp/fix-translations-2.4
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Tomas Groth Approve
Review via email: mp+321131@code.launchpad.net

This proposal supersedes a proposal from 2017-03-28.

Commit message

Fix a problem with loading Qt's translation files, bug #1676163

To post a comment you must log in.
Revision history for this message
Tomas Groth (tomasgroth) :
review: Approve
Revision history for this message
Tim Bentley (trb143) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CHANGELOG.rst'
--- CHANGELOG.rst 2017-03-22 06:21:02 +0000
+++ CHANGELOG.rst 2017-03-28 00:33:42 +0000
@@ -8,3 +8,4 @@
8* Fix opening the data folder (KDE thought the old way was an SMB share)8* Fix opening the data folder (KDE thought the old way was an SMB share)
9* Fix a problem with the new QMediaPlayer not controlling the playlist anymore9* Fix a problem with the new QMediaPlayer not controlling the playlist anymore
10* Added importing of author types to the OpenLP 2 song importer10* Added importing of author types to the OpenLP 2 song importer
11* Fix a problem with loading Qt's translation files, bug #1676163
1112
=== modified file 'openlp/core/__init__.py'
--- openlp/core/__init__.py 2017-03-01 18:24:27 +0000
+++ openlp/core/__init__.py 2017-03-28 00:33:42 +0000
@@ -426,13 +426,12 @@
426 sys.exit()426 sys.exit()
427 # i18n Set Language427 # i18n Set Language
428 language = LanguageManager.get_language()428 language = LanguageManager.get_language()
429 application_translator, default_translator = LanguageManager.get_translator(language)429 translators = LanguageManager.get_translator(language)
430 if not application_translator.isEmpty():430 for translator in translators:
431 application.installTranslator(application_translator)431 if not translator.isEmpty():
432 if not default_translator.isEmpty():432 application.installTranslator(translator)
433 application.installTranslator(default_translator)433 if not translators:
434 else:434 log.debug('Could not find translators.')
435 log.debug('Could not find default_translator.')
436 if args and not args.no_error_form:435 if args and not args.no_error_form:
437 sys.excepthook = application.hook_exception436 sys.excepthook = application.hook_exception
438 sys.exit(application.run(qt_args))437 sys.exit(application.run(qt_args))
439438
=== modified file 'openlp/core/utils/languagemanager.py'
--- openlp/core/utils/languagemanager.py 2016-12-31 11:05:48 +0000
+++ openlp/core/utils/languagemanager.py 2017-03-28 00:33:42 +0000
@@ -24,7 +24,6 @@
24"""24"""
25import logging25import logging
26import re26import re
27import sys
2827
29from PyQt5 import QtCore, QtWidgets28from PyQt5 import QtCore, QtWidgets
3029
@@ -56,9 +55,12 @@
56 # A translator for buttons and other default strings provided by Qt.55 # A translator for buttons and other default strings provided by Qt.
57 if not is_win() and not is_macosx():56 if not is_win() and not is_macosx():
58 lang_path = QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)57 lang_path = QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)
58 # As of Qt5, the core translations come in 2 files per language
59 default_translator = QtCore.QTranslator()59 default_translator = QtCore.QTranslator()
60 default_translator.load('qt_%s' % language, lang_path)60 default_translator.load('qt_%s' % language, lang_path)
61 return app_translator, default_translator61 base_translator = QtCore.QTranslator()
62 base_translator.load('qtbase_%s' % language, lang_path)
63 return app_translator, default_translator, base_translator
6264
63 @staticmethod65 @staticmethod
64 def find_qm_files():66 def find_qm_files():
@@ -69,7 +71,7 @@
69 trans_dir = QtCore.QDir(AppLocation.get_directory(AppLocation.LanguageDir))71 trans_dir = QtCore.QDir(AppLocation.get_directory(AppLocation.LanguageDir))
70 file_names = trans_dir.entryList(['*.qm'], QtCore.QDir.Files, QtCore.QDir.Name)72 file_names = trans_dir.entryList(['*.qm'], QtCore.QDir.Files, QtCore.QDir.Name)
71 # Remove qm files from the list which start with "qt_".73 # Remove qm files from the list which start with "qt_".
72 file_names = [file_ for file_ in file_names if not file_.startswith('qt_')]74 file_names = [file_ for file_ in file_names if not file_.startswith('qt_') or file_.startswith('qtbase_')]
73 return list(map(trans_dir.filePath, file_names))75 return list(map(trans_dir.filePath, file_names))
7476
75 @staticmethod77 @staticmethod
7678
=== modified file 'openlp/plugins/songs/forms/songmaintenanceform.py'
--- openlp/plugins/songs/forms/songmaintenanceform.py 2016-12-31 11:05:48 +0000
+++ openlp/plugins/songs/forms/songmaintenanceform.py 2017-03-28 00:33:42 +0000
@@ -20,7 +20,6 @@
20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #20# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21###############################################################################21###############################################################################
22import logging22import logging
23import os
2423
25from PyQt5 import QtCore, QtWidgets24from PyQt5 import QtCore, QtWidgets
26from sqlalchemy.sql import and_25from sqlalchemy.sql import and_
@@ -167,7 +166,7 @@
167 Author.display_name == new_author.display_name166 Author.display_name == new_author.display_name
168 )167 )
169 )168 )
170 return self.__check_object_exists(authors, new_author, edit)169 return self._check_object_exists(authors, new_author, edit)
171170
172 def check_topic_exists(self, new_topic, edit=False):171 def check_topic_exists(self, new_topic, edit=False):
173 """172 """
@@ -177,7 +176,7 @@
177 :param edit: Are we editing the song?176 :param edit: Are we editing the song?
178 """177 """
179 topics = self.manager.get_all_objects(Topic, Topic.name == new_topic.name)178 topics = self.manager.get_all_objects(Topic, Topic.name == new_topic.name)
180 return self.__check_object_exists(topics, new_topic, edit)179 return self._check_object_exists(topics, new_topic, edit)
181180
182 def check_song_book_exists(self, new_book, edit=False):181 def check_song_book_exists(self, new_book, edit=False):
183 """182 """
@@ -188,9 +187,9 @@
188 """187 """
189 books = self.manager.get_all_objects(188 books = self.manager.get_all_objects(
190 Book, and_(Book.name == new_book.name, Book.publisher == new_book.publisher))189 Book, and_(Book.name == new_book.name, Book.publisher == new_book.publisher))
191 return self.__check_object_exists(books, new_book, edit)190 return self._check_object_exists(books, new_book, edit)
192191
193 def __check_object_exists(self, existing_objects, new_object, edit):192 def _check_object_exists(self, existing_objects, new_object, edit):
194 """193 """
195 Utility method to check for an existing object.194 Utility method to check for an existing object.
196195
197196
=== modified file 'tests/interfaces/openlp_plugins/songs/forms/test_songmaintenanceform.py'
--- tests/interfaces/openlp_plugins/songs/forms/test_songmaintenanceform.py 2017-03-22 06:13:12 +0000
+++ tests/interfaces/openlp_plugins/songs/forms/test_songmaintenanceform.py 2017-03-28 00:33:42 +0000
@@ -25,7 +25,7 @@
25from unittest import TestCase25from unittest import TestCase
26from unittest.mock import MagicMock, patch, call26from unittest.mock import MagicMock, patch, call
2727
28from PyQt5 import QtCore, QtTest, QtWidgets28from PyQt5 import QtCore, QtWidgets
2929
30from openlp.core.common import Registry, UiStrings30from openlp.core.common import Registry, UiStrings
31from openlp.plugins.songs.forms.songmaintenanceform import SongMaintenanceForm31from openlp.plugins.songs.forms.songmaintenanceform import SongMaintenanceForm
@@ -89,6 +89,7 @@
89 mocked_reset_song_books.assert_called_once_with()89 mocked_reset_song_books.assert_called_once_with()
90 mocked_type_list_widget.setFocus.assert_called_once_with()90 mocked_type_list_widget.setFocus.assert_called_once_with()
91 mocked_exec.assert_called_once_with(self.form)91 mocked_exec.assert_called_once_with(self.form)
92 assert result is True
9293
93 def test_get_current_item_id_no_item(self):94 def test_get_current_item_id_no_item(self):
94 """95 """
@@ -291,3 +292,131 @@
291 MockedQListWidgetItem.assert_called_once_with('Hymnal (Hymns and Psalms, Inc.)')292 MockedQListWidgetItem.assert_called_once_with('Hymnal (Hymns and Psalms, Inc.)')
292 mocked_song_book_item.setData.assert_called_once_with(QtCore.Qt.UserRole, 1)293 mocked_song_book_item.setData.assert_called_once_with(QtCore.Qt.UserRole, 1)
293 mocked_song_book_list_widget.addItem.assert_called_once_with(mocked_song_book_item)294 mocked_song_book_list_widget.addItem.assert_called_once_with(mocked_song_book_item)
295
296 @patch('openlp.plugins.songs.forms.songmaintenanceform.and_')
297 @patch('openlp.plugins.songs.forms.songmaintenanceform.Author')
298 def test_check_author_exists(self, MockedAuthor, mocked_and):
299 """
300 Test the check_author_exists() method
301 """
302 # GIVEN: A bunch of mocked out stuff
303 MockedAuthor.first_name = 'John'
304 MockedAuthor.last_name = 'Newton'
305 MockedAuthor.display_name = 'John Newton'
306 mocked_new_author = MagicMock()
307 mocked_new_author.first_name = 'John'
308 mocked_new_author.last_name = 'Newton'
309 mocked_new_author.display_name = 'John Newton'
310 mocked_and.return_value = True
311 mocked_authors = [MagicMock(), MagicMock()]
312 self.mocked_manager.get_all_objects.return_value = mocked_authors
313
314 # WHEN: check_author_exists() is called
315 with patch.object(self.form, '_check_object_exists') as mocked_check_object_exists:
316 mocked_check_object_exists.return_value = True
317 result = self.form.check_author_exists(mocked_new_author, edit=True)
318
319 # THEN: The correct result is returned
320 mocked_and.assert_called_once_with(True, True, True)
321 self.mocked_manager.get_all_objects.assert_called_once_with(MockedAuthor, True)
322 mocked_check_object_exists.assert_called_once_with(mocked_authors, mocked_new_author, True)
323 assert result is True
324
325 @patch('openlp.plugins.songs.forms.songmaintenanceform.Topic')
326 def test_check_topic_exists(self, MockedTopic):
327 """
328 Test the check_topic_exists() method
329 """
330 # GIVEN: Some mocked stuff
331 MockedTopic.name = 'Grace'
332 mocked_new_topic = MagicMock()
333 mocked_new_topic.name = 'Grace'
334 mocked_topics = [MagicMock(), MagicMock()]
335 self.mocked_manager.get_all_objects.return_value = mocked_topics
336
337 # WHEN: check_topic_exists() is run
338 with patch.object(self.form, '_check_object_exists') as mocked_check_object_exists:
339 mocked_check_object_exists.return_value = True
340 result = self.form.check_topic_exists(mocked_new_topic, True)
341
342 # THEN: The correct things should have been called
343 self.mocked_manager.get_all_objects.assert_called_once_with(MockedTopic, True)
344 mocked_check_object_exists.assert_called_once_with(mocked_topics, mocked_new_topic, True)
345 assert result is True
346
347 @patch('openlp.plugins.songs.forms.songmaintenanceform.and_')
348 @patch('openlp.plugins.songs.forms.songmaintenanceform.Book')
349 def test_check_song_book_exists(self, MockedBook, mocked_and):
350 """
351 Test the check_song_book_exists() method
352 """
353 # GIVEN: Some mocked stuff
354 MockedBook.name = 'Hymns'
355 MockedBook.publisher = 'Christian Songs'
356 mocked_new_book = MagicMock()
357 mocked_new_book.name = 'Hymns'
358 mocked_new_book.publisher = 'Christian Songs'
359 mocked_and.return_value = True
360 mocked_books = [MagicMock(), MagicMock()]
361 self.mocked_manager.get_all_objects.return_value = mocked_books
362
363 # WHEN: check_book_exists() is run
364 with patch.object(self.form, '_check_object_exists') as mocked_check_object_exists:
365 mocked_check_object_exists.return_value = True
366 result = self.form.check_song_book_exists(mocked_new_book, True)
367
368 # THEN: The correct things should have been called
369 mocked_and.assert_called_once_with(True, True)
370 self.mocked_manager.get_all_objects.assert_called_once_with(MockedBook, True)
371 mocked_check_object_exists.assert_called_once_with(mocked_books, mocked_new_book, True)
372 assert result is True
373
374 def test_check_object_exists_no_existing_objects(self):
375 """
376 Test the _check_object_exists() method when there are no existing objects
377 """
378 # GIVEN: A SongMaintenanceForm instance
379 # WHEN: _check_object_exists() is called without existing objects
380 result = self.form._check_object_exists([], None, False)
381
382 # THEN: The result should be True
383 assert result is True
384
385 def test_check_object_exists_without_edit(self):
386 """
387 Test the _check_object_exists() method when edit is false
388 """
389 # GIVEN: A SongMaintenanceForm instance
390 # WHEN: _check_object_exists() is called with edit set to false
391 result = self.form._check_object_exists([MagicMock()], None, False)
392
393 # THEN: The result should be False
394 assert result is False
395
396 def test_check_object_exists_not_found(self):
397 """
398 Test the _check_object_exists() method when the object is not found
399 """
400 # GIVEN: A SongMaintenanceForm instance and some mocked objects
401 mocked_existing_objects = [MagicMock(id=1)]
402 mocked_new_object = MagicMock(id=2)
403
404 # WHEN: _check_object_exists() is called with edit set to false
405 result = self.form._check_object_exists(mocked_existing_objects, mocked_new_object, True)
406
407 # THEN: The result should be False
408 assert result is False
409
410 def test_check_object_exists(self):
411 """
412 Test the _check_object_exists() method
413 """
414 # GIVEN: A SongMaintenanceForm instance and some mocked objects
415 mocked_existing_objects = [MagicMock(id=1)]
416 mocked_new_object = MagicMock(id=1)
417
418 # WHEN: _check_object_exists() is called with edit set to false
419 result = self.form._check_object_exists(mocked_existing_objects, mocked_new_object, True)
420
421 # THEN: The result should be False
422 assert result is True

Subscribers

People subscribed via source and target branches

to all changes: