Add a fallback if the lang we want is not available
Previously, trying to get a text node with a lang which is different from the one we specified would return nothing, which means e.g. a message would be ignored because its body is of lang 'fr' when we setup slixmpp to prefer 'en'. We want to return something when there is an available, valid content in a different language.
This commit is contained in:
parent
46a90749f8
commit
96d1c26f90
@ -907,11 +907,17 @@ class ElementBase(object):
|
|||||||
stanzas = self.xml.findall(name)
|
stanzas = self.xml.findall(name)
|
||||||
if not stanzas:
|
if not stanzas:
|
||||||
return default
|
return default
|
||||||
|
result = None
|
||||||
for stanza in stanzas:
|
for stanza in stanzas:
|
||||||
if stanza.attrib.get('{%s}lang' % XML_NS, default_lang) == lang:
|
if stanza.attrib.get('{%s}lang' % XML_NS, default_lang) == lang:
|
||||||
if stanza.text is None:
|
if stanza.text is None:
|
||||||
return default
|
return default
|
||||||
return stanza.text
|
result = stanza.text
|
||||||
|
break
|
||||||
|
if stanza.text:
|
||||||
|
result = stanza.text
|
||||||
|
if result is not None:
|
||||||
|
return result
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def _get_all_sub_text(self, name, default='', lang=None):
|
def _get_all_sub_text(self, name, default='', lang=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user