forked from openlp/openlp
The def create_separated_list now uses the perfectly made and re-formatted code by the mastermind alisonken1
This commit is contained in:
parent
c7a682ebfb
commit
946fb02d57
@ -310,39 +310,24 @@ def expand_tags(text):
|
|||||||
def create_separated_list(string_list):
|
def create_separated_list(string_list):
|
||||||
"""
|
"""
|
||||||
Returns a string that represents a join of a list of strings with a localized separator. This function corresponds
|
Returns a string that represents a join of a list of strings with a localized separator. This function corresponds
|
||||||
|
|
||||||
to QLocale::createSeparatedList which was introduced in Qt 4.8 and implements the algorithm from
|
to QLocale::createSeparatedList which was introduced in Qt 4.8 and implements the algorithm from
|
||||||
http://www.unicode.org/reports/tr35/#ListPatterns
|
http://www.unicode.org/reports/tr35/#ListPatterns
|
||||||
|
NOTE: translate() can change the format based on language styling (ex: Finnish not using "{} and {}" rather than
|
||||||
:param string_list: List of unicode strings
|
english style "{} , and {}").
|
||||||
|
:param string_list: List of unicode strings
|
||||||
|
:return: Formatted string
|
||||||
"""
|
"""
|
||||||
if LooseVersion(Qt.PYQT_VERSION_STR) >= LooseVersion('4.9') and LooseVersion(Qt.qVersion()) >= LooseVersion('4.8'):
|
list_length = len(string_list)
|
||||||
# Separate items with multiple same type creators with ',' and the last with ', and ' ' If we have two creators,
|
if list_length == 1:
|
||||||
# ',' is not used by proper grammar, however in some languages ',' is not used at all before 'and'.
|
return_list = string_list[0]
|
||||||
and_translated = translate('OpenLP.Ui', 'and')
|
elif list_length == 2:
|
||||||
comma_and = translate ('OpenLP.ui', ', and')
|
return_list = translate('OpenLP.core.lib', '{one} & {two}').format(one=string_list[0], two=string_list[1])
|
||||||
if len(string_list) == 2:
|
elif list_length > 2:
|
||||||
string_list = ', '.join(string_list[:-1]) + ' ' + and_translated + ' ' + string_list[-1]
|
return_list = translate('OpenLP.core.lib', '{first}, & {last}').format(first=', '.join(string_list[:-1]),
|
||||||
elif len(string_list) > 2:
|
last=string_list[-1])
|
||||||
string_list = ', '.join(string_list[:-1]) + comma_and + ' ' + string_list[-1]
|
|
||||||
else:
|
|
||||||
string_list = ''.join(string_list)
|
|
||||||
return string_list
|
|
||||||
if not string_list:
|
|
||||||
return ''
|
|
||||||
elif len(string_list) == 1:
|
|
||||||
return string_list[0]
|
|
||||||
# TODO: Verify mocking of translate() test before conversion
|
|
||||||
elif len(string_list) == 2:
|
|
||||||
return translate('OpenLP.core.lib', '%s and %s',
|
|
||||||
'Locale list separator: 2 items') % (string_list[0], string_list[1])
|
|
||||||
else:
|
else:
|
||||||
merged = translate('OpenLP.core.lib', '%s, and %s',
|
return_list = ""
|
||||||
'Locale list separator: end') % (string_list[-2], string_list[-1])
|
return return_list
|
||||||
for index in reversed(list(range(1, len(string_list) - 2))):
|
|
||||||
merged = translate('OpenLP.core.lib', '%s, %s',
|
|
||||||
'Locale list separator: middle') % (string_list[index], merged)
|
|
||||||
return translate('OpenLP.core.lib', '%s, %s', 'Locale list separator: start') % (string_list[0], merged)
|
|
||||||
|
|
||||||
from .exceptions import ValidationError
|
from .exceptions import ValidationError
|
||||||
from .filedialog import FileDialog
|
from .filedialog import FileDialog
|
||||||
|
Loading…
Reference in New Issue
Block a user