2022-05-10 10:06:48 +00:00
|
|
|
|
# Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
|
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2017-05-30 13:50:47 +00:00
|
|
|
|
"""Shared serialization-scanning code for QLocaleXML format.
|
|
|
|
|
|
2020-02-19 14:17:16 +00:00
|
|
|
|
Provides classes:
|
|
|
|
|
Locale -- common data-type representing one locale as a namespace
|
|
|
|
|
QLocaleXmlWriter -- helper to write a QLocaleXML file
|
2020-02-25 11:30:06 +00:00
|
|
|
|
QLocaleXmlReader -- helper to read a QLocaleXML file back in
|
2020-02-19 14:17:16 +00:00
|
|
|
|
|
|
|
|
|
Support:
|
|
|
|
|
Spacer -- provides control over indentation of the output.
|
2021-07-07 14:38:49 +00:00
|
|
|
|
|
|
|
|
|
RelaxNG schema for the used file format can be found in qlocalexml.rnc.
|
|
|
|
|
QLocaleXML files can be validated using:
|
|
|
|
|
|
|
|
|
|
jing -c qlocalexml.rnc <file.xml>
|
|
|
|
|
|
|
|
|
|
You can download jing from https://relaxng.org/jclark/jing.html if your
|
|
|
|
|
package manager lacks the jing package.
|
2017-05-30 13:50:47 +00:00
|
|
|
|
"""
|
2021-07-05 15:45:26 +00:00
|
|
|
|
|
2017-05-30 13:50:47 +00:00
|
|
|
|
from xml.sax.saxutils import escape
|
|
|
|
|
|
2024-06-03 15:29:47 +00:00
|
|
|
|
from localetools import Error, qtVersion
|
2017-05-30 13:50:47 +00:00
|
|
|
|
|
|
|
|
|
# Tools used by Locale:
|
|
|
|
|
def camel(seq):
|
2021-07-05 15:45:26 +00:00
|
|
|
|
yield next(seq)
|
2017-05-30 13:50:47 +00:00
|
|
|
|
for word in seq:
|
|
|
|
|
yield word.capitalize()
|
|
|
|
|
|
|
|
|
|
def camelCase(words):
|
|
|
|
|
return ''.join(camel(iter(words)))
|
|
|
|
|
|
2020-02-19 14:17:16 +00:00
|
|
|
|
def addEscapes(s):
|
2021-07-06 14:22:07 +00:00
|
|
|
|
return ''.join(c if n < 128 else f'\\x{n:02x}'
|
2020-02-19 14:17:16 +00:00
|
|
|
|
for n, c in ((ord(c), c) for c in s))
|
|
|
|
|
|
2018-09-12 10:41:23 +00:00
|
|
|
|
def startCount(c, text): # strspn
|
|
|
|
|
"""First index in text where it doesn't have a character in c"""
|
|
|
|
|
assert text and text[0] in c
|
|
|
|
|
try:
|
2021-07-05 15:45:26 +00:00
|
|
|
|
return next((j for j, d in enumerate(text) if d not in c))
|
2018-09-12 10:41:23 +00:00
|
|
|
|
except StopIteration:
|
|
|
|
|
return len(text)
|
|
|
|
|
|
2020-02-25 11:30:06 +00:00
|
|
|
|
class QLocaleXmlReader (object):
|
|
|
|
|
def __init__(self, filename):
|
|
|
|
|
self.root = self.__parse(filename)
|
2023-08-01 10:35:26 +00:00
|
|
|
|
|
|
|
|
|
from enumdata import language_map, script_map, territory_map
|
|
|
|
|
# Lists of (id, enum name, code, en.xml name) tuples:
|
|
|
|
|
languages = tuple(self.__loadMap('language', language_map))
|
|
|
|
|
scripts = tuple(self.__loadMap('script', script_map))
|
|
|
|
|
territories = tuple(self.__loadMap('territory', territory_map))
|
2024-05-07 13:19:25 +00:00
|
|
|
|
self.__likely = tuple(self.__likelySubtagsMap()) # in enum name form
|
2023-08-01 10:35:26 +00:00
|
|
|
|
|
|
|
|
|
# Mappings {ID: (enum name, code, en.xml name)}
|
2024-03-22 13:48:53 +00:00
|
|
|
|
self.languages = {v[0]: v[1:] for v in languages}
|
|
|
|
|
self.scripts = {v[0]: v[1:] for v in scripts}
|
|
|
|
|
self.territories = {v[0]: v[1:] for v in territories}
|
2023-08-01 10:35:26 +00:00
|
|
|
|
|
|
|
|
|
# Private mappings {enum name: (ID, code)}
|
2024-03-22 13:48:53 +00:00
|
|
|
|
self.__langByName = {v[1]: (v[0], v[2]) for v in languages}
|
|
|
|
|
self.__textByName = {v[1]: (v[0], v[2]) for v in scripts}
|
|
|
|
|
self.__landByName = {v[1]: (v[0], v[2]) for v in territories}
|
2020-02-25 11:30:06 +00:00
|
|
|
|
# Other properties:
|
2023-08-01 10:03:18 +00:00
|
|
|
|
self.__dupes = set(v[1] for v in languages) & set(v[1] for v in territories)
|
2024-06-03 15:29:47 +00:00
|
|
|
|
|
|
|
|
|
self.cldrVersion = self.root.attributes['versionCldr'].nodeValue
|
|
|
|
|
self.qtVersion = self.root.attributes['versionQt'].nodeValue
|
|
|
|
|
assert self.qtVersion == qtVersion, (
|
|
|
|
|
'Using QLocaleXml file from incompatible Qt version',
|
|
|
|
|
self.qtVersion, qtVersion
|
|
|
|
|
)
|
2020-02-25 11:30:06 +00:00
|
|
|
|
|
|
|
|
|
def loadLocaleMap(self, calendars, grumble = lambda text: None):
|
|
|
|
|
kid = self.__firstChildText
|
|
|
|
|
likely = dict(self.__likely)
|
|
|
|
|
for elt in self.__eachEltInGroup(self.root, 'localeList', 'locale'):
|
|
|
|
|
locale = Locale.fromXmlData(lambda k: kid(elt, k), calendars)
|
|
|
|
|
language = self.__langByName[locale.language][0]
|
|
|
|
|
script = self.__textByName[locale.script][0]
|
2021-05-04 11:20:32 +00:00
|
|
|
|
territory = self.__landByName[locale.territory][0]
|
2020-02-25 11:30:06 +00:00
|
|
|
|
|
|
|
|
|
if language != 1: # C
|
2021-05-04 11:20:32 +00:00
|
|
|
|
if territory == 0:
|
2021-07-06 14:22:07 +00:00
|
|
|
|
grumble(f'loadLocaleMap: No territory id for "{locale.language}"\n')
|
2020-02-25 11:30:06 +00:00
|
|
|
|
|
|
|
|
|
if script == 0:
|
2021-05-04 11:20:32 +00:00
|
|
|
|
# Find default script for the given language and territory - see:
|
2020-02-25 11:30:06 +00:00
|
|
|
|
# http://www.unicode.org/reports/tr35/#Likely_Subtags
|
|
|
|
|
try:
|
|
|
|
|
try:
|
2021-05-04 11:20:32 +00:00
|
|
|
|
to = likely[(locale.language, 'AnyScript', locale.territory)]
|
2020-02-25 11:30:06 +00:00
|
|
|
|
except KeyError:
|
2021-03-09 08:19:54 +00:00
|
|
|
|
to = likely[(locale.language, 'AnyScript', 'AnyTerritory')]
|
2020-02-25 11:30:06 +00:00
|
|
|
|
except KeyError:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
locale.script = to[1]
|
|
|
|
|
script = self.__textByName[locale.script][0]
|
|
|
|
|
|
2021-05-04 11:20:32 +00:00
|
|
|
|
yield (language, script, territory), locale
|
2020-02-25 11:30:06 +00:00
|
|
|
|
|
2024-03-22 12:57:28 +00:00
|
|
|
|
def aliasToIana(self):
|
|
|
|
|
kid = self.__firstChildText
|
|
|
|
|
for elt in self.__eachEltInGroup(self.root, 'zoneAliases', 'zoneAlias'):
|
|
|
|
|
yield kid(elt, 'alias'), kid(elt, 'iana')
|
|
|
|
|
|
|
|
|
|
def msToIana(self):
|
|
|
|
|
kid = self.__firstChildText
|
|
|
|
|
for elt in self.__eachEltInGroup(self.root, 'windowsZone', 'msZoneIana'):
|
|
|
|
|
yield kid(elt, 'msid'), kid(elt, 'iana')
|
|
|
|
|
|
|
|
|
|
def msLandIanas(self):
|
|
|
|
|
kid = self.__firstChildText
|
|
|
|
|
for elt in self.__eachEltInGroup(self.root, 'windowsZone', 'msLandZones'):
|
2024-04-23 13:50:59 +00:00
|
|
|
|
yield kid(elt, 'msid'), kid(elt, 'territorycode'), kid(elt, 'ianaids')
|
2024-03-22 12:57:28 +00:00
|
|
|
|
|
2020-02-25 11:30:06 +00:00
|
|
|
|
def languageIndices(self, locales):
|
|
|
|
|
index = 0
|
2021-07-05 15:45:26 +00:00
|
|
|
|
for key, value in self.languages.items():
|
2020-02-25 11:30:06 +00:00
|
|
|
|
i, count = 0, locales.count(key)
|
|
|
|
|
if count > 0:
|
|
|
|
|
i = index
|
|
|
|
|
index += count
|
|
|
|
|
yield i, value[0]
|
|
|
|
|
|
|
|
|
|
def likelyMap(self):
|
|
|
|
|
def tag(t):
|
|
|
|
|
lang, script, land = t
|
|
|
|
|
yield lang[1] if lang[0] else 'und'
|
|
|
|
|
if script[0]: yield script[1]
|
|
|
|
|
if land[0]: yield land[1]
|
|
|
|
|
|
|
|
|
|
def ids(t):
|
|
|
|
|
return tuple(x[0] for x in t)
|
|
|
|
|
|
2024-05-07 13:19:25 +00:00
|
|
|
|
def keyLikely(pair, kl=self.__keyLikely):
|
|
|
|
|
"""Sort by IDs from first entry in pair
|
|
|
|
|
|
|
|
|
|
We're passed a pair (h, g) of triplets (lang, script, territory) of
|
|
|
|
|
pairs (ID, name); we extract the ID from each entry in the first
|
|
|
|
|
triplet, then hand that triplet of IDs off to __keyLikely()."""
|
|
|
|
|
return kl(tuple(x[0] for x in pair[0]))
|
|
|
|
|
|
|
|
|
|
# Sort self.__likely to enable binary search in C++ code.
|
|
|
|
|
for have, give in sorted(((self.__fromNames(has),
|
|
|
|
|
self.__fromNames(got))
|
|
|
|
|
for has, got in self.__likely),
|
|
|
|
|
key = keyLikely):
|
2020-02-25 11:30:06 +00:00
|
|
|
|
yield ('_'.join(tag(have)), ids(have),
|
2020-10-12 11:12:48 +00:00
|
|
|
|
'_'.join(tag(give)), ids(give))
|
2020-02-25 11:30:06 +00:00
|
|
|
|
|
|
|
|
|
def defaultMap(self):
|
2021-05-04 11:20:32 +00:00
|
|
|
|
"""Map language and script to their default territory by ID.
|
2020-02-25 11:30:06 +00:00
|
|
|
|
|
2021-05-04 11:20:32 +00:00
|
|
|
|
Yields ((language, script), territory) wherever the likely
|
2020-02-25 11:30:06 +00:00
|
|
|
|
sub-tags mapping says language's default locale uses the given
|
2021-05-04 11:20:32 +00:00
|
|
|
|
script and territory."""
|
2020-02-25 11:30:06 +00:00
|
|
|
|
for have, give in self.__likely:
|
2021-03-09 08:19:54 +00:00
|
|
|
|
if have[1:] == ('AnyScript', 'AnyTerritory') and give[2] != 'AnyTerritory':
|
2020-02-25 11:30:06 +00:00
|
|
|
|
assert have[0] == give[0], (have, give)
|
|
|
|
|
yield ((self.__langByName[give[0]][0],
|
|
|
|
|
self.__textByName[give[1]][0]),
|
|
|
|
|
self.__landByName[give[2]][0])
|
|
|
|
|
|
2023-08-01 10:03:18 +00:00
|
|
|
|
def enumify(self, name, suffix):
|
|
|
|
|
"""Stick together the parts of an enumdata.py name.
|
|
|
|
|
|
|
|
|
|
Names given in enumdata.py include spaces and hyphens that we
|
|
|
|
|
can't include in an identifier, such as the name of a member
|
|
|
|
|
of an enum type. Removing those would lose the word
|
|
|
|
|
boundaries, so make sure each word starts with a capital (but
|
|
|
|
|
don't simply capitalize() as some names contain words,
|
|
|
|
|
e.g. McDonald, that have later capitals in them).
|
|
|
|
|
|
|
|
|
|
We also need to resolve duplication between languages and
|
|
|
|
|
territories (by adding a suffix to each) and add Script to the
|
|
|
|
|
ends of script-names that don't already end in it."""
|
|
|
|
|
name = name.replace('-', ' ')
|
|
|
|
|
# Don't .capitalize() as McDonald is already camel-case (see enumdata.py):
|
|
|
|
|
name = ''.join(word[0].upper() + word[1:] for word in name.split())
|
|
|
|
|
if suffix != 'Script':
|
|
|
|
|
assert not(name in self.__dupes and name.endswith(suffix))
|
|
|
|
|
return name + suffix if name in self.__dupes else name
|
|
|
|
|
|
|
|
|
|
if not name.endswith(suffix):
|
|
|
|
|
name += suffix
|
|
|
|
|
if name in self.__dupes:
|
|
|
|
|
raise Error(f'The script name "{name}" is messy')
|
|
|
|
|
return name
|
|
|
|
|
|
2020-02-25 11:30:06 +00:00
|
|
|
|
# Implementation details:
|
2023-08-01 10:35:26 +00:00
|
|
|
|
def __loadMap(self, category, enum):
|
2024-06-03 15:51:29 +00:00
|
|
|
|
"""Load the language-, script- or territory-map.
|
|
|
|
|
|
|
|
|
|
First parameter, category, names the map to load, second is the
|
|
|
|
|
enumdata.py map that corresponds to it. Yields 4-tuples (id, enum,
|
|
|
|
|
code, name) where id and enum are the enumdata numeric index and name
|
|
|
|
|
(on which the QLocale enums are based), code is the ISO code and name
|
|
|
|
|
is CLDR's en.xml name for the language, script or territory."""
|
2020-02-25 11:30:06 +00:00
|
|
|
|
kid = self.__firstChildText
|
2024-06-03 15:51:29 +00:00
|
|
|
|
for element in self.__eachEltInGroup(self.root, f'{category}List', 'naming'):
|
|
|
|
|
name, key, code = self.__textThenAttrs(element, 'id', 'code')
|
|
|
|
|
key = int(key)
|
|
|
|
|
yield key, enum[key][0], code, name
|
2020-02-25 11:30:06 +00:00
|
|
|
|
|
2024-05-07 13:19:25 +00:00
|
|
|
|
def __fromNames(self, names):
|
|
|
|
|
# Three (ID, code) pairs:
|
|
|
|
|
return self.__langByName[names[0]], self.__textByName[names[1]], self.__landByName[names[2]]
|
|
|
|
|
|
|
|
|
|
# Likely subtag management:
|
2020-02-25 11:30:06 +00:00
|
|
|
|
def __likelySubtagsMap(self):
|
2021-05-04 11:20:32 +00:00
|
|
|
|
def triplet(element, keys=('language', 'script', 'territory'), kid = self.__firstChildText):
|
2020-02-25 11:30:06 +00:00
|
|
|
|
return tuple(kid(element, key) for key in keys)
|
|
|
|
|
|
|
|
|
|
kid = self.__firstChildElt
|
|
|
|
|
for elt in self.__eachEltInGroup(self.root, 'likelySubtags', 'likelySubtag'):
|
|
|
|
|
yield triplet(kid(elt, "from")), triplet(kid(elt, "to"))
|
|
|
|
|
|
2024-05-07 13:19:25 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def __keyLikely(key, huge=0x10000):
|
|
|
|
|
"""Sort order key for a likely subtag key
|
|
|
|
|
|
|
|
|
|
Although the entries are (lang, script, region), sort by (lang, region,
|
|
|
|
|
script) and sort 0 after all non-zero values, in each position. This
|
|
|
|
|
ensures that, when several mappings partially match a requested locale,
|
|
|
|
|
the one we should prefer to use appears first.
|
|
|
|
|
|
|
|
|
|
We use 0x10000 as replacement for 0, as all IDs are unsigned short, so
|
|
|
|
|
less than 2^16."""
|
|
|
|
|
# Map zero to huge:
|
|
|
|
|
have = tuple(x or huge for x in key)
|
|
|
|
|
# Use language, territory, script for sort order:
|
|
|
|
|
return have[0], have[2], have[1]
|
2020-02-25 11:30:06 +00:00
|
|
|
|
|
|
|
|
|
# DOM access:
|
|
|
|
|
from xml.dom import minidom
|
|
|
|
|
@staticmethod
|
|
|
|
|
def __parse(filename, read = minidom.parse):
|
|
|
|
|
return read(filename).documentElement
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def __isNodeNamed(elt, name, TYPE=minidom.Node.ELEMENT_NODE):
|
|
|
|
|
return elt.nodeType == TYPE and elt.nodeName == name
|
|
|
|
|
del minidom
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def __eltWords(elt):
|
|
|
|
|
child = elt.firstChild
|
|
|
|
|
while child:
|
|
|
|
|
if child.nodeType == elt.TEXT_NODE:
|
2024-03-13 17:02:33 +00:00
|
|
|
|
# Note: do not strip(), as some group separators are
|
|
|
|
|
# non-breaking spaces, that strip() will discard.
|
2020-02-25 11:30:06 +00:00
|
|
|
|
yield child.nodeValue
|
|
|
|
|
child = child.nextSibling
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def __firstChildElt(cls, parent, name):
|
|
|
|
|
child = parent.firstChild
|
|
|
|
|
while child:
|
|
|
|
|
if cls.__isNodeNamed(child, name):
|
|
|
|
|
return child
|
|
|
|
|
child = child.nextSibling
|
|
|
|
|
|
2021-07-06 14:22:07 +00:00
|
|
|
|
raise Error(f'No {name} child found')
|
2020-02-25 11:30:06 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def __firstChildText(cls, elt, key):
|
|
|
|
|
return ' '.join(cls.__eltWords(cls.__firstChildElt(elt, key)))
|
|
|
|
|
|
2024-06-03 15:51:29 +00:00
|
|
|
|
@classmethod
|
|
|
|
|
def __textThenAttrs(cls, elt, *names):
|
|
|
|
|
"""Read an elements text than a sequence of its attributes.
|
|
|
|
|
|
|
|
|
|
First parameter is the XML element, subsequent parameters name
|
|
|
|
|
attributes of it. Yields the text of the element, followed by the text
|
|
|
|
|
of each of the attributes in turn."""
|
|
|
|
|
yield ' '.join(cls.__eltWords(elt))
|
|
|
|
|
for name in names:
|
|
|
|
|
yield elt.attributes[name].nodeValue
|
|
|
|
|
|
2020-02-25 11:30:06 +00:00
|
|
|
|
@classmethod
|
|
|
|
|
def __eachEltInGroup(cls, parent, group, key):
|
|
|
|
|
try:
|
|
|
|
|
element = cls.__firstChildElt(parent, group).firstChild
|
|
|
|
|
except Error:
|
|
|
|
|
element = None
|
|
|
|
|
|
|
|
|
|
while element:
|
|
|
|
|
if cls.__isNodeNamed(element, key):
|
|
|
|
|
yield element
|
|
|
|
|
element = element.nextSibling
|
|
|
|
|
|
|
|
|
|
|
2020-02-19 14:17:16 +00:00
|
|
|
|
class Spacer (object):
|
|
|
|
|
def __init__(self, indent = None, initial = ''):
|
|
|
|
|
"""Prepare to manage indentation and line breaks.
|
|
|
|
|
|
|
|
|
|
Arguments are both optional.
|
|
|
|
|
|
|
|
|
|
First argument, indent, is either None (its default, for
|
|
|
|
|
'minifying'), an ingeter (number of spaces) or the unit of
|
|
|
|
|
text that is to be used for each indentation level (e.g. '\t'
|
2024-04-23 13:50:59 +00:00
|
|
|
|
to use tabs). If indent is None, no indentation is added, nor
|
2020-02-19 14:17:16 +00:00
|
|
|
|
are line-breaks; otherwise, self(text), for non-empty text,
|
|
|
|
|
shall end with a newline and begin with indentation.
|
|
|
|
|
|
|
|
|
|
Second argument, initial, is the initial indentation; it is
|
2024-04-23 13:50:59 +00:00
|
|
|
|
ignored if indent is None. Indentation increases after each
|
2020-02-19 14:17:16 +00:00
|
|
|
|
call to self(text) in which text starts with a tag and doesn't
|
|
|
|
|
include its end-tag; indentation decreases if text starts with
|
2024-04-23 13:50:59 +00:00
|
|
|
|
an end-tag. The text is not parsed any more carefully than
|
|
|
|
|
just described."""
|
2020-02-19 14:17:16 +00:00
|
|
|
|
if indent is None:
|
|
|
|
|
self.__call = lambda x: x
|
|
|
|
|
else:
|
|
|
|
|
self.__each = ' ' * indent if isinstance(indent, int) else indent
|
|
|
|
|
self.current = initial
|
|
|
|
|
self.__call = self.__wrap
|
|
|
|
|
|
|
|
|
|
def __wrap(self, line):
|
|
|
|
|
if not line:
|
|
|
|
|
return '\n'
|
|
|
|
|
|
|
|
|
|
indent = self.current
|
|
|
|
|
if line.startswith('</'):
|
|
|
|
|
indent = self.current = indent[:-len(self.__each)]
|
2024-06-03 15:10:41 +00:00
|
|
|
|
elif line.startswith('<') and line[1:2] not in '!?':
|
2020-02-19 14:17:16 +00:00
|
|
|
|
cut = line.find('>')
|
|
|
|
|
tag = (line[1:] if cut < 0 else line[1 : cut]).strip().split()[0]
|
2021-07-06 14:22:07 +00:00
|
|
|
|
if f'</{tag}>' not in line:
|
2020-02-19 14:17:16 +00:00
|
|
|
|
self.current += self.__each
|
|
|
|
|
return indent + line + '\n'
|
|
|
|
|
|
|
|
|
|
def __call__(self, line):
|
|
|
|
|
return self.__call(line)
|
|
|
|
|
|
|
|
|
|
class QLocaleXmlWriter (object):
|
2024-04-23 13:50:59 +00:00
|
|
|
|
"""Save the full set of locale data to a QLocaleXML file.
|
|
|
|
|
|
|
|
|
|
The output saved by this should conform to qlocalexml.rnc's
|
|
|
|
|
schema."""
|
2024-06-03 15:11:47 +00:00
|
|
|
|
def __init__(self, cldrVersion, save = None, space = Spacer('\t')):
|
2020-02-19 14:17:16 +00:00
|
|
|
|
"""Set up to write digested CLDR data as QLocale XML.
|
|
|
|
|
|
2024-06-03 15:29:47 +00:00
|
|
|
|
First argument is the version of CLDR whose data we'll be
|
|
|
|
|
writing. Other arguments are optional.
|
|
|
|
|
|
|
|
|
|
Second argument, save, is None (its default) or a callable that will
|
|
|
|
|
write content to where you intend to save it. If None, it is replaced
|
|
|
|
|
with a callable that prints the given content, suppressing the newline
|
|
|
|
|
(but see the following); this is equivalent to passing
|
|
|
|
|
sys.stdout.write.
|
|
|
|
|
|
|
|
|
|
Third argument, space, is an object to call on each text output to
|
|
|
|
|
prepend indentation and append newlines, or not as the case may be. The
|
2024-06-03 15:11:47 +00:00
|
|
|
|
default is a Spacer('\t'), which grows indent by a tab after each
|
2024-06-03 15:29:47 +00:00
|
|
|
|
unmatched new tag and shrinks back on a close-tag (its parsing is
|
|
|
|
|
naive, but adequate to how this class uses it), while adding a newline
|
|
|
|
|
to each line."""
|
2020-02-19 14:17:16 +00:00
|
|
|
|
self.__rawOutput = self.__printit if save is None else save
|
|
|
|
|
self.__wrap = space
|
2024-06-03 15:11:47 +00:00
|
|
|
|
self.__write('<?xml version="1.0" encoding="UTF-8" ?>'
|
|
|
|
|
# A hint to emacs to make display nicer:
|
|
|
|
|
'<!--*- tab-width: 4 -*-->')
|
2024-06-03 15:29:47 +00:00
|
|
|
|
self.__openTag('localeDatabase', versionCldr = cldrVersion,
|
|
|
|
|
versionQt = qtVersion)
|
2020-02-19 14:17:16 +00:00
|
|
|
|
|
|
|
|
|
# Output of various sections, in their usual order:
|
2023-08-01 10:35:26 +00:00
|
|
|
|
def enumData(self, code2name):
|
|
|
|
|
"""Output name/id/code tables for language, script and territory.
|
|
|
|
|
|
|
|
|
|
Parameter, code2name, is a function taking 'language',
|
|
|
|
|
'script' or 'territory' and returning a lookup function that
|
|
|
|
|
maps codes, of the relevant type, to their English names. This
|
|
|
|
|
lookup function is passed a code and the name, both taken from
|
|
|
|
|
enumdata.py, that QLocale uses, so the .get() of a dict will
|
|
|
|
|
work. The English name from this lookup will be used by
|
|
|
|
|
QLocale::*ToString() for the enum member whose name is based
|
|
|
|
|
on the enumdata.py name passed as fallback to the lookup."""
|
2021-05-04 11:20:32 +00:00
|
|
|
|
from enumdata import language_map, script_map, territory_map
|
2023-08-01 10:35:26 +00:00
|
|
|
|
self.__enumTable('language', language_map, code2name)
|
|
|
|
|
self.__enumTable('script', script_map, code2name)
|
|
|
|
|
self.__enumTable('territory', territory_map, code2name)
|
2021-05-04 10:06:42 +00:00
|
|
|
|
# Prepare to detect any unused codes (see __writeLocale(), close()):
|
|
|
|
|
self.__languages = set(p[1] for p in language_map.values()
|
|
|
|
|
if not p[1].isspace())
|
|
|
|
|
self.__scripts = set(p[1] for p in script_map.values()
|
2023-07-27 16:57:40 +00:00
|
|
|
|
if p[1] != 'Zzzz')
|
2021-05-04 10:06:42 +00:00
|
|
|
|
self.__territories = set(p[1] for p in territory_map.values()
|
2023-07-27 16:57:40 +00:00
|
|
|
|
if p[1] != 'ZZ')
|
2020-02-19 14:17:16 +00:00
|
|
|
|
|
|
|
|
|
def likelySubTags(self, entries):
|
|
|
|
|
self.__openTag('likelySubtags')
|
|
|
|
|
for have, give in entries:
|
|
|
|
|
self.__openTag('likelySubtag')
|
|
|
|
|
self.__likelySubTag('from', have)
|
|
|
|
|
self.__likelySubTag('to', give)
|
|
|
|
|
self.__closeTag('likelySubtag')
|
|
|
|
|
self.__closeTag('likelySubtags')
|
|
|
|
|
|
2024-03-22 12:57:28 +00:00
|
|
|
|
def zoneData(self, alias, defaults, windowsIds):
|
|
|
|
|
self.__openTag('zoneAliases')
|
|
|
|
|
# iana is a single IANA ID
|
|
|
|
|
# name has the same form, but has been made redundant
|
|
|
|
|
for name, iana in sorted(alias.items()):
|
2024-05-23 19:38:02 +00:00
|
|
|
|
if name == iana:
|
|
|
|
|
continue
|
2024-03-22 12:57:28 +00:00
|
|
|
|
self.__openTag('zoneAlias')
|
|
|
|
|
self.inTag('alias', name)
|
|
|
|
|
self.inTag('iana', iana)
|
|
|
|
|
self.__closeTag('zoneAlias')
|
|
|
|
|
self.__closeTag('zoneAliases')
|
|
|
|
|
|
|
|
|
|
self.__openTag('windowsZone')
|
|
|
|
|
for (msid, code), ids in windowsIds.items():
|
|
|
|
|
# ianaids is a space-joined sequence of IANA IDs
|
|
|
|
|
self.__openTag('msLandZones')
|
|
|
|
|
self.inTag('msid', msid)
|
|
|
|
|
self.inTag('territorycode', code)
|
|
|
|
|
self.inTag('ianaids', ids)
|
|
|
|
|
self.__closeTag('msLandZones')
|
|
|
|
|
|
|
|
|
|
for winid, iana in defaults.items():
|
|
|
|
|
self.__openTag('msZoneIana')
|
|
|
|
|
self.inTag('msid', winid)
|
|
|
|
|
self.inTag('iana', iana)
|
|
|
|
|
self.__closeTag('msZoneIana')
|
|
|
|
|
self.__closeTag('windowsZone')
|
|
|
|
|
|
2024-04-26 10:27:10 +00:00
|
|
|
|
def locales(self, locales, calendars, en_US):
|
|
|
|
|
"""Write the data for each locale.
|
|
|
|
|
|
|
|
|
|
First argument, locales, is the mapping whose values are the
|
|
|
|
|
Locale objects, with each key being the matching tuple of
|
|
|
|
|
numeric IDs for language, script, territory and variant.
|
|
|
|
|
Second argument is a tuple of calendar names. Third is the
|
|
|
|
|
tuple of numeric IDs that corresponds to en_US (needed to
|
|
|
|
|
provide fallbacks for the C locale)."""
|
|
|
|
|
|
2020-02-19 14:17:16 +00:00
|
|
|
|
self.__openTag('localeList')
|
|
|
|
|
self.__openTag('locale')
|
2024-04-26 10:27:10 +00:00
|
|
|
|
self.__writeLocale(Locale.C(locales[en_US]), calendars)
|
2020-02-19 14:17:16 +00:00
|
|
|
|
self.__closeTag('locale')
|
2021-07-05 15:45:26 +00:00
|
|
|
|
for key in sorted(locales.keys()):
|
2020-02-19 14:17:16 +00:00
|
|
|
|
self.__openTag('locale')
|
2021-05-04 10:06:42 +00:00
|
|
|
|
self.__writeLocale(locales[key], calendars)
|
2020-02-19 14:17:16 +00:00
|
|
|
|
self.__closeTag('locale')
|
|
|
|
|
self.__closeTag('localeList')
|
|
|
|
|
|
2024-06-03 15:51:29 +00:00
|
|
|
|
def inTag(self, tag, text, **attrs):
|
|
|
|
|
"""Writes an XML element with the given content.
|
|
|
|
|
|
|
|
|
|
First parameter, tag, is the element type; second, text, is the content
|
|
|
|
|
of its body. Any keyword parameters passed specify attributes to
|
|
|
|
|
include in the opening tag."""
|
|
|
|
|
if attrs:
|
|
|
|
|
head = ' '.join(f'{k}="{v}"' for k, v in attrs.items())
|
|
|
|
|
head = f'{tag} {head}'
|
|
|
|
|
else:
|
|
|
|
|
head = tag
|
|
|
|
|
self.__write(f'<{head}>{text}</{tag}>')
|
2020-02-19 14:17:16 +00:00
|
|
|
|
|
2021-05-04 10:06:42 +00:00
|
|
|
|
def close(self, grumble):
|
2024-03-22 13:50:19 +00:00
|
|
|
|
"""Finish writing and grumble about any issues discovered."""
|
2020-02-19 14:17:16 +00:00
|
|
|
|
if self.__rawOutput != self.__complain:
|
2024-06-03 15:29:47 +00:00
|
|
|
|
self.__closeTag('localeDatabase')
|
2020-02-19 14:17:16 +00:00
|
|
|
|
self.__rawOutput = self.__complain
|
|
|
|
|
|
2023-07-27 16:57:40 +00:00
|
|
|
|
if self.__languages or self.__scripts or self.__territories:
|
2021-05-04 10:06:42 +00:00
|
|
|
|
grumble('Some enum members are unused, corresponding to these tags:\n')
|
|
|
|
|
import textwrap
|
|
|
|
|
def kvetch(kind, seq, g = grumble, w = textwrap.wrap):
|
2021-07-06 14:22:07 +00:00
|
|
|
|
g('\n\t'.join(w(f' {kind}: {", ".join(sorted(seq))}', width=80)) + '\n')
|
2021-05-04 10:06:42 +00:00
|
|
|
|
if self.__languages:
|
|
|
|
|
kvetch('Languages', self.__languages)
|
|
|
|
|
if self.__scripts:
|
|
|
|
|
kvetch('Scripts', self.__scripts)
|
|
|
|
|
if self.__territories:
|
|
|
|
|
kvetch('Territories', self.__territories)
|
2021-07-06 07:39:15 +00:00
|
|
|
|
grumble('It may make sense to deprecate them.\n')
|
2021-05-04 10:06:42 +00:00
|
|
|
|
|
2020-02-19 14:17:16 +00:00
|
|
|
|
# Implementation details
|
|
|
|
|
@staticmethod
|
|
|
|
|
def __printit(text):
|
|
|
|
|
print(text, end='')
|
|
|
|
|
@staticmethod
|
|
|
|
|
def __complain(text):
|
|
|
|
|
raise Error('Attempted to write data after closing :-(')
|
|
|
|
|
|
2023-08-01 10:35:26 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def __xmlSafe(text):
|
|
|
|
|
return text.replace('&', '&').replace('<', '<').replace('>', '>')
|
|
|
|
|
|
|
|
|
|
def __enumTable(self, tag, table, code2name):
|
2024-06-03 15:51:29 +00:00
|
|
|
|
"""Writes a table of QLocale-enum-related data.
|
|
|
|
|
|
|
|
|
|
First parameter, tag, is 'language', 'script' or 'territory',
|
|
|
|
|
identifying the relevant table. Second, table, is the enumdata.py
|
|
|
|
|
mapping from numeric enum value to (enum name, ISO code) pairs for that
|
|
|
|
|
type. Last is the englishNaming method of the CldrAccess being used to
|
|
|
|
|
read CLDR data; it is used to map ISO codes to en.xml names."""
|
2021-07-06 14:22:07 +00:00
|
|
|
|
self.__openTag(f'{tag}List')
|
2023-08-01 10:35:26 +00:00
|
|
|
|
enname, safe = code2name(tag), self.__xmlSafe
|
|
|
|
|
for key, (name, code) in table.items():
|
2024-06-03 15:51:29 +00:00
|
|
|
|
self.inTag('naming', safe(enname(code, name)), id = key, code = code)
|
2021-07-06 14:22:07 +00:00
|
|
|
|
self.__closeTag(f'{tag}List')
|
2020-02-19 14:17:16 +00:00
|
|
|
|
|
|
|
|
|
def __likelySubTag(self, tag, likely):
|
|
|
|
|
self.__openTag(tag)
|
|
|
|
|
self.inTag('language', likely[0])
|
|
|
|
|
self.inTag('script', likely[1])
|
2021-05-04 11:20:32 +00:00
|
|
|
|
self.inTag('territory', likely[2])
|
2020-02-19 14:17:16 +00:00
|
|
|
|
# self.inTag('variant', likely[3])
|
|
|
|
|
self.__closeTag(tag)
|
|
|
|
|
|
2021-05-04 10:06:42 +00:00
|
|
|
|
def __writeLocale(self, locale, calendars):
|
|
|
|
|
locale.toXml(self.inTag, calendars)
|
|
|
|
|
self.__languages.discard(locale.language_code)
|
|
|
|
|
self.__scripts.discard(locale.script_code)
|
|
|
|
|
self.__territories.discard(locale.territory_code)
|
|
|
|
|
|
2024-04-23 13:50:59 +00:00
|
|
|
|
def __openTag(self, tag, **attrs):
|
|
|
|
|
if attrs:
|
2024-06-03 15:29:47 +00:00
|
|
|
|
text = ' '.join(f'{k}="{v}"' for k, v in attrs.items())
|
2024-04-23 13:50:59 +00:00
|
|
|
|
tag = f'{tag} {text}'
|
2021-07-06 14:22:07 +00:00
|
|
|
|
self.__write(f'<{tag}>')
|
2020-02-19 14:17:16 +00:00
|
|
|
|
def __closeTag(self, tag):
|
2021-07-06 14:22:07 +00:00
|
|
|
|
self.__write(f'</{tag}>')
|
2020-02-19 14:17:16 +00:00
|
|
|
|
|
|
|
|
|
def __write(self, line):
|
|
|
|
|
self.__rawOutput(self.__wrap(line))
|
|
|
|
|
|
|
|
|
|
class Locale (object):
|
|
|
|
|
"""Holder for the assorted data representing one locale.
|
|
|
|
|
|
|
|
|
|
Implemented as a namespace; its constructor and update() have the
|
|
|
|
|
same signatures as those of a dict, acting on the instance's
|
|
|
|
|
__dict__, so the results are accessed as attributes rather than
|
|
|
|
|
mapping keys."""
|
|
|
|
|
def __init__(self, data=None, **kw):
|
|
|
|
|
self.update(data, **kw)
|
|
|
|
|
|
|
|
|
|
def update(self, data=None, **kw):
|
|
|
|
|
if data: self.__dict__.update(data)
|
|
|
|
|
if kw: self.__dict__.update(kw)
|
|
|
|
|
|
|
|
|
|
def __len__(self): # Used when testing as a boolean
|
|
|
|
|
return len(self.__dict__)
|
|
|
|
|
|
2017-01-14 16:53:31 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def propsMonthDay(scale, lengths=('long', 'short', 'narrow')):
|
2017-05-30 13:50:47 +00:00
|
|
|
|
for L in lengths:
|
2017-01-14 16:53:31 +00:00
|
|
|
|
yield camelCase((L, scale))
|
|
|
|
|
yield camelCase(('standalone', L, scale))
|
2017-05-30 13:50:47 +00:00
|
|
|
|
|
|
|
|
|
# Expected to be numbers, read with int():
|
2020-01-13 14:46:13 +00:00
|
|
|
|
__asint = ("currencyDigits", "currencyRounding")
|
2017-05-30 13:50:47 +00:00
|
|
|
|
# Convert day-name to Qt day-of-week number:
|
|
|
|
|
__asdow = ("firstDayOfWeek", "weekendStart", "weekendEnd")
|
|
|
|
|
# Just use the raw text:
|
2021-05-04 11:20:32 +00:00
|
|
|
|
__astxt = ("language", "languageEndonym", "script", "territory", "territoryEndonym",
|
2020-01-13 14:46:13 +00:00
|
|
|
|
"decimal", "group", "zero",
|
|
|
|
|
"list", "percent", "minus", "plus", "exp",
|
|
|
|
|
"quotationStart", "quotationEnd",
|
|
|
|
|
"alternateQuotationStart", "alternateQuotationEnd",
|
2017-05-30 13:50:47 +00:00
|
|
|
|
"listPatternPartStart", "listPatternPartMiddle",
|
|
|
|
|
"listPatternPartEnd", "listPatternPartTwo", "am", "pm",
|
2024-04-26 13:47:31 +00:00
|
|
|
|
"longDateFormat", "shortDateFormat",
|
|
|
|
|
"longTimeFormat", "shortTimeFormat",
|
Add byte-based units to CLDR data
Scan CLDR for {,kilo,mega,giga,tera,peta,exa}byte forms and their IEC
equivalents, providing SI and IEC defaults when missing (which all of
IEC are) in addition to the usual numeric data. Extrapolate from any
present data (e.g. French's ko, Mo, Go, To imply Po, Eo and, for IEC,
Kio, Mio, etc.), since CLDR only goes up to tera. Propagate this data
to QLocale's database ready for use by QLocale::formattedDataSize().
Change-Id: Ie6ee978948c68be9f71ab784a128cbfae3d80ee1
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2017-05-30 12:55:33 +00:00
|
|
|
|
'byte_unit', 'byte_si_quantified', 'byte_iec_quantified',
|
2017-05-30 13:50:47 +00:00
|
|
|
|
"currencyIsoCode", "currencySymbol", "currencyDisplayName",
|
2024-04-23 13:50:59 +00:00
|
|
|
|
"currencyFormat", "currencyNegativeFormat",
|
|
|
|
|
)
|
2017-05-30 13:50:47 +00:00
|
|
|
|
|
|
|
|
|
# Day-of-Week numbering used by Qt:
|
|
|
|
|
__qDoW = {"mon": 1, "tue": 2, "wed": 3, "thu": 4, "fri": 5, "sat": 6, "sun": 7}
|
|
|
|
|
|
|
|
|
|
@classmethod
|
2017-01-14 16:53:31 +00:00
|
|
|
|
def fromXmlData(cls, lookup, calendars=('gregorian',)):
|
2017-05-30 13:50:47 +00:00
|
|
|
|
"""Constructor from the contents of XML elements.
|
|
|
|
|
|
2024-04-23 13:50:59 +00:00
|
|
|
|
First parameter, lookup, is called with the names of XML elements that
|
|
|
|
|
should contain the relevant data, within a QLocaleXML locale element
|
|
|
|
|
(within a localeList element); these names mostly match the attributes
|
|
|
|
|
of the object constructed. Its return must be the full text of the
|
|
|
|
|
first child DOM node element with the given name. Attribute values are
|
|
|
|
|
obtained by suitably digesting the returned element texts.
|
|
|
|
|
|
|
|
|
|
Optional second parameter, calendars, is a sequence of calendars for
|
|
|
|
|
which data is to be retrieved."""
|
2017-05-30 13:50:47 +00:00
|
|
|
|
data = {}
|
|
|
|
|
for k in cls.__asint:
|
2020-01-13 14:46:13 +00:00
|
|
|
|
data[k] = int(lookup(k))
|
2017-05-30 13:50:47 +00:00
|
|
|
|
|
|
|
|
|
for k in cls.__asdow:
|
|
|
|
|
data[k] = cls.__qDoW[lookup(k)]
|
|
|
|
|
|
2017-01-14 16:53:31 +00:00
|
|
|
|
for k in cls.__astxt + tuple(cls.propsMonthDay('days')):
|
2020-01-13 14:46:13 +00:00
|
|
|
|
data['listDelim' if k == 'list' else k] = lookup(k)
|
2017-05-30 13:50:47 +00:00
|
|
|
|
|
2017-01-14 16:53:31 +00:00
|
|
|
|
for k in cls.propsMonthDay('months'):
|
2024-03-22 13:48:53 +00:00
|
|
|
|
data[k] = {cal: lookup('_'.join((k, cal))) for cal in calendars}
|
2017-01-14 16:53:31 +00:00
|
|
|
|
|
2020-01-17 10:00:24 +00:00
|
|
|
|
grouping = lookup('groupSizes').split(';')
|
|
|
|
|
data.update(groupLeast = int(grouping[0]),
|
|
|
|
|
groupHigher = int(grouping[1]),
|
|
|
|
|
groupTop = int(grouping[2]))
|
|
|
|
|
|
2017-05-30 13:50:47 +00:00
|
|
|
|
return cls(data)
|
|
|
|
|
|
2020-02-19 14:17:16 +00:00
|
|
|
|
def toXml(self, write, calendars=('gregorian',)):
|
|
|
|
|
"""Writes its data as QLocale XML.
|
|
|
|
|
|
|
|
|
|
First argument, write, is a callable taking the name and
|
|
|
|
|
content of an XML element; it is expected to be the inTag
|
|
|
|
|
bound method of a QLocaleXmlWriter instance.
|
|
|
|
|
|
|
|
|
|
Optional second argument is a list of calendar names, in the
|
|
|
|
|
form used by CLDR; its default is ('gregorian',).
|
|
|
|
|
"""
|
2017-05-30 13:50:47 +00:00
|
|
|
|
get = lambda k: getattr(self, k)
|
2021-05-04 11:20:32 +00:00
|
|
|
|
for key in ('language', 'script', 'territory'):
|
2020-02-19 14:17:16 +00:00
|
|
|
|
write(key, get(key))
|
2021-07-06 14:22:07 +00:00
|
|
|
|
write(f'{key}code', get(f'{key}_code'))
|
2017-05-30 13:50:47 +00:00
|
|
|
|
|
2020-04-06 23:00:12 +00:00
|
|
|
|
for key in ('decimal', 'group', 'zero', 'list',
|
|
|
|
|
'percent', 'minus', 'plus', 'exp'):
|
|
|
|
|
write(key, get(key))
|
2017-05-30 13:50:47 +00:00
|
|
|
|
|
2021-05-04 11:20:32 +00:00
|
|
|
|
for key in ('languageEndonym', 'territoryEndonym',
|
2017-05-30 13:50:47 +00:00
|
|
|
|
'quotationStart', 'quotationEnd',
|
|
|
|
|
'alternateQuotationStart', 'alternateQuotationEnd',
|
|
|
|
|
'listPatternPartStart', 'listPatternPartMiddle',
|
|
|
|
|
'listPatternPartEnd', 'listPatternPartTwo',
|
Add byte-based units to CLDR data
Scan CLDR for {,kilo,mega,giga,tera,peta,exa}byte forms and their IEC
equivalents, providing SI and IEC defaults when missing (which all of
IEC are) in addition to the usual numeric data. Extrapolate from any
present data (e.g. French's ko, Mo, Go, To imply Po, Eo and, for IEC,
Kio, Mio, etc.), since CLDR only goes up to tera. Propagate this data
to QLocale's database ready for use by QLocale::formattedDataSize().
Change-Id: Ie6ee978948c68be9f71ab784a128cbfae3d80ee1
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2017-05-30 12:55:33 +00:00
|
|
|
|
'byte_unit', 'byte_si_quantified', 'byte_iec_quantified',
|
2017-05-30 13:50:47 +00:00
|
|
|
|
'am', 'pm', 'firstDayOfWeek',
|
|
|
|
|
'weekendStart', 'weekendEnd',
|
|
|
|
|
'longDateFormat', 'shortDateFormat',
|
|
|
|
|
'longTimeFormat', 'shortTimeFormat',
|
|
|
|
|
'currencyIsoCode', 'currencySymbol', 'currencyDisplayName',
|
2024-04-23 13:50:59 +00:00
|
|
|
|
'currencyFormat', 'currencyNegativeFormat',
|
2017-01-14 16:53:31 +00:00
|
|
|
|
) + tuple(self.propsMonthDay('days')) + tuple(
|
|
|
|
|
'_'.join((k, cal))
|
|
|
|
|
for k in self.propsMonthDay('months')
|
|
|
|
|
for cal in calendars):
|
2021-07-05 15:45:26 +00:00
|
|
|
|
write(key, escape(get(key)))
|
2017-05-30 13:50:47 +00:00
|
|
|
|
|
2020-01-17 10:00:24 +00:00
|
|
|
|
write('groupSizes', ';'.join(str(x) for x in get('groupSizes')))
|
2017-05-30 13:50:47 +00:00
|
|
|
|
for key in ('currencyDigits', 'currencyRounding'):
|
2020-02-19 14:17:16 +00:00
|
|
|
|
write(key, get(key))
|
2017-05-30 13:50:47 +00:00
|
|
|
|
|
|
|
|
|
@classmethod
|
2024-04-26 10:27:10 +00:00
|
|
|
|
def C(cls, en_US):
|
|
|
|
|
"""Returns an object representing the C locale.
|
|
|
|
|
|
|
|
|
|
Required argument, en_US, is the corresponding object for the
|
|
|
|
|
en_US locale (or the en_US_POSIX one if we ever support
|
|
|
|
|
variants). The C locale inherits from this, overriding what it
|
|
|
|
|
may need to."""
|
|
|
|
|
base = en_US.__dict__.copy()
|
|
|
|
|
# Soroush's original contribution shortened Jalali month names
|
|
|
|
|
# - contrary to CLDR, which doesn't abbreviate these in
|
|
|
|
|
# root.xml or en.xml, although some locales do, e.g. fr_CA.
|
|
|
|
|
# For compatibility with that,
|
|
|
|
|
for k in ('shortMonths_persian', 'standaloneShortMonths_persian'):
|
|
|
|
|
base[k] = ';'.join(x[:3] for x in base[k].split(';'))
|
|
|
|
|
|
|
|
|
|
return cls(base,
|
2024-04-26 14:42:29 +00:00
|
|
|
|
language='C', language_code='',
|
|
|
|
|
language_id=0, languageEndonym='',
|
|
|
|
|
script='AnyScript', script_code='', script_id=0,
|
|
|
|
|
territory='AnyTerritory', territory_code='',
|
|
|
|
|
territory_id=0, territoryEndonym='',
|
|
|
|
|
variant='', variant_code='', variant_id=0,
|
2024-04-26 10:27:10 +00:00
|
|
|
|
# CLDR has non-ASCII versions of these:
|
2017-05-30 13:50:47 +00:00
|
|
|
|
quotationStart='"', quotationEnd='"',
|
2024-04-26 10:27:10 +00:00
|
|
|
|
alternateQuotationStart="'", alternateQuotationEnd="'",
|
|
|
|
|
# CLDR gives 'dddd, MMMM d, yyyy', 'M/d/yy', 'h:mm:ss Ap tttt',
|
|
|
|
|
# 'h:mm Ap' with non-breaking space before Ap.
|
2024-04-26 13:47:31 +00:00
|
|
|
|
longDateFormat='dddd, d MMMM yyyy', shortDateFormat='d MMM yyyy',
|
|
|
|
|
longTimeFormat='HH:mm:ss t', shortTimeFormat='HH:mm:ss',
|
2024-04-26 10:27:10 +00:00
|
|
|
|
# CLDR has US-$ and US-style formats:
|
|
|
|
|
currencyIsoCode='', currencySymbol='', currencyDisplayName='',
|
2017-05-30 13:50:47 +00:00
|
|
|
|
currencyDigits=2, currencyRounding=1,
|
2024-04-26 10:27:10 +00:00
|
|
|
|
currencyFormat='%1%2', currencyNegativeFormat='',
|
|
|
|
|
# We may want to fall back to CLDR for some of these:
|
|
|
|
|
firstDayOfWeek='mon', # CLDR has 'sun'
|
|
|
|
|
exp='e', # CLDR has 'E'
|
|
|
|
|
listPatternPartEnd='%1, %2', # CLDR has '%1, and %2'
|
|
|
|
|
listPatternPartTwo='%1, %2', # CLDR has '%1 and %2'
|
|
|
|
|
narrowDays='7;1;2;3;4;5;6', # CLDR has letters
|
|
|
|
|
narrowMonths_gregorian='1;2;3;4;5;6;7;8;9;10;11;12', # CLDR has letters
|
|
|
|
|
standaloneNarrowMonths_persian='F;O;K;T;M;S;M;A;A;D;B;E', # CLDR has digits
|
|
|
|
|
# Keep these explicit, despite matching CLDR:
|
|
|
|
|
decimal='.', group=',', percent='%',
|
|
|
|
|
zero='0', minus='-', plus='+',
|
|
|
|
|
am='AM', pm='PM', weekendStart='sat', weekendEnd='sun')
|