diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2020-11-12 11:30:01 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2020-11-17 19:55:04 +0100 |
commit | 17701a95f8612865191f7719df1879c4114d8f6c (patch) | |
tree | 42ad4ef8b9c816cb2a0a6d4e897cf26432b5f94e /util | |
parent | 7c28fa7717b4bad67a4d1795cb79dc4160925694 (diff) |
QLocale: simplify currency display name lookup
We were extracting several candidate display names from CLDR for each
currency, joining them with semicolons, storing in a table, then using
only the first entry from the list - where we should probably have
used the first non-empty entry in any case.
So instead extract the first non-empty candidate name from CLDR and
store that simply, saving the need for semicolon-joining or parsing
out the first entry from the thus-joined list. This significantly
reduces the size of the currency name data table.
Change-Id: I201d0528348d5fcb9eceb5df86211b9c77de3485
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'util')
-rw-r--r-- | util/locale_database/ldml.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/util/locale_database/ldml.py b/util/locale_database/ldml.py index 0f08884d4b..110e5b7573 100644 --- a/util/locale_database/ldml.py +++ b/util/locale_database/ldml.py @@ -265,13 +265,7 @@ class LocaleScanner (object): if isoCode: stem = 'numbers/currencies/currency[{}]/'.format(isoCode) symbol = self.find(stem + 'symbol', '') - displays = tuple(self.find(stem + 'displayName' + tail, '') - for tail in ('',) + tuple( - '[count={}]'.format(x) for x in ('zero', 'one', 'two', - 'few', 'many', 'other'))) - while displays and not displays[-1]: - displays = displays[:-1] - name = ';'.join(displays) + name = self.__currencyDisplayName(stem) else: symbol = name = '' yield 'currencySymbol', symbol @@ -463,6 +457,18 @@ class LocaleScanner (object): sought += ' (for {})'.format(xpath) raise Error('No {} in {}'.format(sought, self.name)) + def __currencyDisplayName(self, stem): + try: + return self.find(stem + 'displayName') + except Error: + pass + for x in ('zero', 'one', 'two', 'few', 'many', 'other'): + try: + return self.find(stem + 'displayName[count={}]'.format(x)) + except Error: + pass + return '' + def __findUnit(self, keySuffix, quantify, fallback=''): # The displayName for a quantified unit in en.xml is kByte # (even for unitLength[narrow]) instead of kB (etc.), so |