QLocaleXML: use attributes for likely subtag tag parts
This makes the likely subtag part of the file more compact. Introduces a QLocaleXmlWriter.asTag() for attribute-only elements; this requires the Spacer to recognize self-closing elements as not increasing the indent needed. Change-Id: I1b73b755f9841617a5c002cf624785321e808d0c Reviewed-by: Mate Barany <mate.barany@qt.io>
This commit is contained in:
parent
b66ecb295e
commit
6705728aba
@ -224,8 +224,8 @@ class QLocaleXmlReader (object):
|
|||||||
|
|
||||||
# Likely subtag management:
|
# Likely subtag management:
|
||||||
def __likelySubtagsMap(self):
|
def __likelySubtagsMap(self):
|
||||||
def triplet(element, keys=('language', 'script', 'territory'), kid = self.__firstChildText):
|
def triplet(element, keys=('language', 'script', 'territory')):
|
||||||
return tuple(int(kid(element, key)) for key in keys)
|
return tuple(int(element.attributes[key].nodeValue) for key in keys)
|
||||||
|
|
||||||
kid = self.__firstChildElt
|
kid = self.__firstChildElt
|
||||||
for elt in self.__eachEltInGroup(self.root, 'likelySubtags', 'likelySubtag'):
|
for elt in self.__eachEltInGroup(self.root, 'likelySubtags', 'likelySubtag'):
|
||||||
@ -341,6 +341,7 @@ class Spacer (object):
|
|||||||
indent = self.current = indent[:-len(self.__each)]
|
indent = self.current = indent[:-len(self.__each)]
|
||||||
elif line.startswith('<') and line[1:2] not in '!?':
|
elif line.startswith('<') and line[1:2] not in '!?':
|
||||||
cut = line.find('>')
|
cut = line.find('>')
|
||||||
|
if cut < 1 or line[cut - 1] != '/':
|
||||||
tag = (line[1:] if cut < 0 else line[1 : cut]).strip().split()[0]
|
tag = (line[1:] if cut < 0 else line[1 : cut]).strip().split()[0]
|
||||||
if f'</{tag}>' not in line:
|
if f'</{tag}>' not in line:
|
||||||
self.current += self.__each
|
self.current += self.__each
|
||||||
@ -475,6 +476,12 @@ class QLocaleXmlWriter (object):
|
|||||||
head = tag
|
head = tag
|
||||||
self.__write(f'<{head}>{text}</{tag}>')
|
self.__write(f'<{head}>{text}</{tag}>')
|
||||||
|
|
||||||
|
def asTag(self, tag, **attrs):
|
||||||
|
"""Similar to inTag(), but with no content for the element."""
|
||||||
|
assert attrs, tag # No point to this otherwise
|
||||||
|
tail = ' '.join(f'{k}="{v}"' for k, v in attrs.items())
|
||||||
|
self.__write(f'<{tag} {tail} />')
|
||||||
|
|
||||||
def close(self, grumble):
|
def close(self, grumble):
|
||||||
"""Finish writing and grumble about any issues discovered."""
|
"""Finish writing and grumble about any issues discovered."""
|
||||||
if self.__rawOutput != self.__complain:
|
if self.__rawOutput != self.__complain:
|
||||||
@ -521,12 +528,8 @@ class QLocaleXmlWriter (object):
|
|||||||
self.__closeTag(f'{tag}List')
|
self.__closeTag(f'{tag}List')
|
||||||
|
|
||||||
def __likelySubTag(self, tag, likely):
|
def __likelySubTag(self, tag, likely):
|
||||||
self.__openTag(tag)
|
self.asTag(tag, language = likely[0], script = likely[1],
|
||||||
self.inTag('language', likely[0])
|
territory = likely[2]) # variant = likely[3]
|
||||||
self.inTag('script', likely[1])
|
|
||||||
self.inTag('territory', likely[2])
|
|
||||||
# self.inTag('variant', likely[3])
|
|
||||||
self.__closeTag(tag)
|
|
||||||
|
|
||||||
def __writeLocale(self, locale, calendars):
|
def __writeLocale(self, locale, calendars):
|
||||||
locale.toXml(self.inTag, calendars)
|
locale.toXml(self.inTag, calendars)
|
||||||
|
@ -34,9 +34,9 @@ LikelySubtag = element likelySubtag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LocaleTriplet = (
|
LocaleTriplet = (
|
||||||
element language { xsd:nonNegativeInteger },
|
attribute language { xsd:nonNegativeInteger },
|
||||||
element script { xsd:nonNegativeInteger },
|
attribute script { xsd:nonNegativeInteger },
|
||||||
element territory { xsd:nonNegativeInteger }
|
attribute territory { xsd:nonNegativeInteger }
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: xsd patterns for IANA IDs and space-joined lists of them
|
# TODO: xsd patterns for IANA IDs and space-joined lists of them
|
||||||
|
Loading…
x
Reference in New Issue
Block a user