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>
This commit is contained in:
parent
7c28fa7717
commit
17701a95f8
@ -3957,7 +3957,7 @@ QString QLocale::currencySymbol(QLocale::CurrencySymbolFormat format) const
|
||||
case CurrencySymbol:
|
||||
return d->m_data->currencySymbol().getData(currency_symbol_data);
|
||||
case CurrencyDisplayName:
|
||||
return d->m_data->currencyDisplayName().getListEntry(currency_display_name_data, 0);
|
||||
return d->m_data->currencyDisplayName().getData(currency_display_name_data);
|
||||
case CurrencyIsoCode: {
|
||||
const char *code = d->m_data->m_currency_iso_code;
|
||||
if (auto len = qstrnlen(code, 3))
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user