本文整理汇总了Python中arelle.Locale.getLanguageCode方法的典型用法代码示例。如果您正苦于以下问题:Python Locale.getLanguageCode方法的具体用法?Python Locale.getLanguageCode怎么用?Python Locale.getLanguageCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arelle.Locale
的用法示例。
在下文中一共展示了Locale.getLanguageCode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parsePackage
# 需要导入模块: from arelle import Locale [as 别名]
# 或者: from arelle.Locale import getLanguageCode [as 别名]
def parsePackage(mainWin, metadataFile):
unNamedCounter = 1
NS = "{http://www.corefiling.com/xbrl/taxonomypackage/v1}"
pkg = {}
currentLang = Locale.getLanguageCode()
tree = etree.parse(metadataFile)
root = tree.getroot()
for eltName in ("name", "description", "version"):
pkg[eltName] = ""
for m in root.iterchildren(tag=NS + eltName):
pkg[eltName] = m.text.strip()
break # take first entry if several
remappings = dict((m.get("prefix"), m.get("replaceWith")) for m in tree.iter(tag=NS + "remapping"))
pkg["remappings"] = remappings
nameToUrls = {}
pkg["nameToUrls"] = nameToUrls
for entryPointSpec in tree.iter(tag=NS + "entryPoint"):
name = None
# find closest match name node given xml:lang match to current language or no xml:lang
for nameNode in entryPointSpec.iter(tag=NS + "name"):
xmlLang = nameNode.get("{http://www.w3.org/XML/1998/namespace}lang")
if name is None or not xmlLang or currentLang == xmlLang:
name = nameNode.text
if currentLang == xmlLang: # most prefer one with the current locale's language
break
if not name:
name = _("<unnamed {0}>").format(unNamedCounter)
unNamedCounter += 1
epDocCount = 0
for epDoc in entryPointSpec.iterchildren(NS + "entryPointDocument"):
if epDocCount:
mainWin.addToLog(_("WARNING: skipping multiple-document entry point (not supported)"))
continue
epDocCount += 1
epUrl = epDoc.get("href")
base = epDoc.get("{http://www.w3.org/XML/1998/namespace}base") # cope with xml:base
if base:
resolvedUrl = urljoin(base, epUrl)
else:
resolvedUrl = epUrl
# perform prefix remappings
remappedUrl = resolvedUrl
for prefix, replace in remappings.items():
remappedUrl = remappedUrl.replace(prefix, replace, 1)
nameToUrls[name] = (remappedUrl, resolvedUrl)
return pkg
示例2: __init__
# 需要导入模块: from arelle import Locale [as 别名]
# 或者: from arelle.Locale import getLanguageCode [as 别名]
def __init__(self, cntlr):
self.cntlr = cntlr
self.validateDisclosureSystem = False
self.disclosureSystem = DisclosureSystem.DisclosureSystem(self)
self.validateCalcLB = False
self.validateInferDecimals = False
self.validateUtr = False
self.loadedModelXbrls = []
from arelle import Locale
self.locale = Locale.getUserLocale()
self.defaultLang = Locale.getLanguageCode()
示例3: __init__
# 需要导入模块: from arelle import Locale [as 别名]
# 或者: from arelle.Locale import getLanguageCode [as 别名]
def __init__(self, cntlr):
self.cntlr = cntlr
self.validateDisclosureSystem = False
self.disclosureSystem = DisclosureSystem.DisclosureSystem(self)
self.validateCalcLB = False
self.validateInferDecimals = False
self.validateInfoset = False
self.validateUtr = False
self.abortOnMajorError = False
self.collectProfileStats = False
self.loadedModelXbrls = []
from arelle import Locale
self.locale = Locale.getUserLocale(cntlr.config.get("userInterfaceLocaleOverride",""))
self.defaultLang = Locale.getLanguageCode()
示例4: parseTxmyPkg
# 需要导入模块: from arelle import Locale [as 别名]
# 或者: from arelle.Locale import getLanguageCode [as 别名]
def parseTxmyPkg(mainWin, metadataFile):
unNamedCounter = 1
currentLang = Locale.getLanguageCode()
tree = etree.parse(metadataFile)
remappings = dict(
(m.get("prefix"), m.get("replaceWith"))
for m in tree.iter(tag="{http://www.corefiling.com/xbrl/taxonomypackage/v1}remapping")
)
result = {}
for entryPointSpec in tree.iter(tag="{http://www.corefiling.com/xbrl/taxonomypackage/v1}entryPoint"):
name = None
# find closest match name node given xml:lang match to current language or no xml:lang
for nameNode in entryPointSpec.iter(tag="{http://www.corefiling.com/xbrl/taxonomypackage/v1}name"):
xmlLang = nameNode.get("{http://www.w3.org/XML/1998/namespace}lang")
if name is None or not xmlLang or currentLang == xmlLang:
name = nameNode.text
if currentLang == xmlLang: # most prefer one with the current locale's language
break
if not name:
name = _("<unnamed {0}>").format(unNamedCounter)
unNamedCounter += 1
epDocCount = 0
for epDoc in entryPointSpec.iterchildren(
"{http://www.corefiling.com/xbrl/taxonomypackage/v1}entryPointDocument"
):
if epDocCount:
mainWin.addToLog(_("WARNING: skipping multiple-document entry point (not supported)"))
continue
epDocCount += 1
epUrl = epDoc.get("href")
base = epDoc.get("{http://www.w3.org/XML/1998/namespace}base") # cope with xml:base
if base:
resolvedUrl = urljoin(base, epUrl)
else:
resolvedUrl = epUrl
# perform prefix remappings
remappedUrl = resolvedUrl
for prefix, replace in remappings.items():
remappedUrl = resolvedUrl.replace(prefix, replace, 1)
result[name] = (remappedUrl, resolvedUrl)
return result
示例5: parsePackage
# 需要导入模块: from arelle import Locale [as 别名]
# 或者: from arelle.Locale import getLanguageCode [as 别名]
def parsePackage(cntlr, filesource, metadataFile, fileBase, errors=[]):
global ArchiveFileIOError
if ArchiveFileIOError is None:
from arelle.FileSource import ArchiveFileIOError
unNamedCounter = 1
txmyPkgNSes = ("http://www.corefiling.com/xbrl/taxonomypackage/v1",
"http://xbrl.org/PWD/2014-01-15/taxonomy-package",
"http://xbrl.org/PWD/2015-01-14/taxonomy-package",
"http://xbrl.org/WGWD/YYYY-MM-DD/taxonomy-package")
catalogNSes = ("urn:oasis:names:tc:entity:xmlns:xml:catalog",)
pkg = {}
currentLang = Locale.getLanguageCode()
_file = filesource.file(metadataFile)[0] # URL in zip, plain file in file system or web
try:
tree = etree.parse(_file)
except etree.XMLSyntaxError as err:
cntlr.addToLog(_("Package catalog syntax error %(error)s"),
messageArgs={"error": str(err)},
messageCode="tpe:invalidMetaDataFile",
file=os.path.basename(metadataFile),
level=logging.ERROR)
errors.append("tpe:invalidMetaDataFile")
raise # reraise error
root = tree.getroot()
ns = root.tag.partition("}")[0][1:]
nsPrefix = "{{{}}}".format(ns)
if ns in txmyPkgNSes: # package file
for eltName in ("identifier", "version", "license", "publisher", "publisherURL", "publisherCountry", "publicationDate"):
pkg[eltName] = ''
for m in root.iterchildren(tag=nsPrefix + eltName):
if eltName == "license":
pkg[eltName] = m.get("name")
else:
pkg[eltName] = (m.text or "").strip()
break # take first entry if several
for eltName in ("name", "description"):
closest = ''
closestLen = 0
for m in root.iterchildren(tag=nsPrefix + eltName):
s = (m.text or "").strip()
l = langCloseness(xmlLang(m), currentLang)
if l > closestLen:
closestLen = l
closest = s
pkg[eltName] = closest
for eltName in ("supersededTaxonomyPackages", "versioningReports"):
pkg[eltName] = []
for m in root.iterchildren(tag=nsPrefix + "supersededTaxonomyPackages"):
pkg['supersededTaxonomyPackages'] = [
r.text.strip()
for r in m.iterchildren(tag=nsPrefix + "taxonomyPackageRef")]
for m in root.iterchildren(tag=nsPrefix + "versioningReports"):
pkg['versioningReports'] = [
r.get("href")
for r in m.iterchildren(tag=nsPrefix + "versioningReport")]
# check for duplicate multi-lingual elements (among children of nodes)
langElts = defaultdict(list)
for n in root.iter(tag=nsPrefix + "*"):
for eltName in ("name", "description"):
langElts.clear()
for m in n.iterchildren(tag=nsPrefix + eltName):
langElts[xmlLang(m)].append(m)
for lang, elts in langElts.items():
if not lang:
cntlr.addToLog(_("Multi-lingual element %(element)s has no in-scope xml:lang attribute"),
messageArgs={"element": eltName},
messageCode="tpe:missingLanguageAttribute",
refs=[{"href":os.path.basename(metadataFile), "sourceLine":m.sourceline} for m in elts],
level=logging.ERROR)
errors.append("tpe:missingLanguageAttribute")
elif len(elts) > 1:
cntlr.addToLog(_("Multi-lingual element %(element)s has multiple (%(count)s) in-scope xml:lang %(lang)s elements"),
messageArgs={"element": eltName, "lang": lang, "count": len(elts)},
messageCode="tpe:duplicateLanguagesForElement",
refs=[{"href":os.path.basename(metadataFile), "sourceLine":m.sourceline} for m in elts],
level=logging.ERROR)
errors.append("tpe:duplicateLanguagesForElement")
del langElts # dereference
else: # oasis catalog, use dirname as the package name
# metadataFile may be a File object (with name) or string filename
fileName = getattr(metadataFile, 'fileName', # for FileSource named objects
getattr(metadataFile, 'name', # for io.file named objects
metadataFile)) # for string
pkg["name"] = os.path.basename(os.path.dirname(fileName))
pkg["description"] = "oasis catalog"
pkg["version"] = "(none)"
remappings = {}
rewriteTree = tree
catalogFile = metadataFile
if ns in ("http://xbrl.org/PWD/2015-01-14/taxonomy-package",
"http://xbrl.org/WGWD/YYYY-MM-DD/taxonomy-package"):
catalogFile = metadataFile.replace('taxonomyPackage.xml','catalog.xml')
try:
#.........这里部分代码省略.........
示例6: parsePackage
# 需要导入模块: from arelle import Locale [as 别名]
# 或者: from arelle.Locale import getLanguageCode [as 别名]
def parsePackage(cntlr, filesource, metadataFile, fileBase):
global ArchiveFileIOError
if ArchiveFileIOError is None:
from arelle.FileSource import ArchiveFileIOError
unNamedCounter = 1
txmyPkgNSes = ("http://www.corefiling.com/xbrl/taxonomypackage/v1",
"http://xbrl.org/PWD/2014-01-15/taxonomy-package",
"http://xbrl.org/PWD/2015-01-14/taxonomy-package")
catalogNSes = ("urn:oasis:names:tc:entity:xmlns:xml:catalog",)
pkg = {}
currentLang = Locale.getLanguageCode()
_file = filesource.file(metadataFile)[0] # URL in zip, plain file in file system or web
tree = etree.parse(_file)
root = tree.getroot()
ns = root.tag.partition("}")[0][1:]
nsPrefix = "{{{}}}".format(ns)
if ns in txmyPkgNSes: # package file
for eltName in ("name", "description", "version"):
pkg[eltName] = ''
for m in root.iterchildren(tag=nsPrefix + eltName):
pkg[eltName] = m.text.strip()
break # take first entry if several
else: # oasis catalog, use dirname as the package name
# metadataFile may be a File object (with name) or string filename
fileName = getattr(metadataFile, 'fileName', # for FileSource named objects
getattr(metadataFile, 'name', # for io.file named objects
metadataFile)) # for string
pkg["name"] = os.path.basename(os.path.dirname(fileName))
pkg["description"] = "oasis catalog"
pkg["version"] = "(none)"
remappings = {}
rewriteTree = tree
catalogFile = metadataFile
if ns in ("http://xbrl.org/PWD/2015-01-14/taxonomy-package",):
catalogFile = metadataFile.replace('taxonomyPackage.xml','catalog.xml')
try:
rewriteTree = etree.parse(filesource.file(catalogFile)[0])
except ArchiveFileIOError:
pass
for tag, prefixAttr, replaceAttr in (
(nsPrefix + "remapping", "prefix", "replaceWith"), # taxonomy package
("{urn:oasis:names:tc:entity:xmlns:xml:catalog}rewriteSystem", "systemIdStartString", "rewritePrefix"),
("{urn:oasis:names:tc:entity:xmlns:xml:catalog}rewriteURI", "uriStartString", "rewritePrefix")): # oasis catalog
for m in rewriteTree.iter(tag=tag):
prefixValue = m.get(prefixAttr)
replaceValue = m.get(replaceAttr)
if prefixValue and replaceValue is not None:
if prefixValue not in remappings:
base = baseForElement(m)
if base:
replaceValue = os.path.join(base, replaceValue)
if replaceValue: # neither None nor ''
if not isAbsolute(replaceValue):
if not os.path.isabs(replaceValue):
replaceValue = fileBase + replaceValue
replaceValue = replaceValue.replace("/", os.sep)
_normedValue = os.path.normpath(replaceValue)
if replaceValue.endswith(os.sep) and not _normedValue.endswith(os.sep):
_normedValue += os.sep
remappings[prefixValue] = _normedValue
else:
cntlr.addToLog(_("Package catalog duplicate rewrite start string %(rewriteStartString)s"),
messageArgs={"rewriteStartString": prefixValue},
messageCode="arelle.catalogDuplicateRewrite",
file=os.path.basename(catalogFile),
level=logging.ERROR)
pkg["remappings"] = remappings
nameToUrls = {}
pkg["nameToUrls"] = nameToUrls
for entryPointSpec in tree.iter(tag=nsPrefix + "entryPoint"):
name = None
# find closest match name node given xml:lang match to current language or no xml:lang
for nameNode in entryPointSpec.iter(tag=nsPrefix + "name"):
xmlLang = nameNode.get('{http://www.w3.org/XML/1998/namespace}lang')
if name is None or not xmlLang or currentLang == xmlLang:
name = nameNode.text
if currentLang == xmlLang: # most prefer one with the current locale's language
break
if not name:
name = _("<unnamed {0}>").format(unNamedCounter)
unNamedCounter += 1
epDocCount = 0
for epDoc in entryPointSpec.iterchildren(nsPrefix + "entryPointDocument"):
epUrl = epDoc.get('href')
base = epDoc.get('{http://www.w3.org/XML/1998/namespace}base') # cope with xml:base
if base:
resolvedUrl = urljoin(base, epUrl)
#.........这里部分代码省略.........
示例7: parsePackage
# 需要导入模块: from arelle import Locale [as 别名]
# 或者: from arelle.Locale import getLanguageCode [as 别名]
def parsePackage(mainWin, metadataFile):
unNamedCounter = 1
txmyPkgNSes = ("http://www.corefiling.com/xbrl/taxonomypackage/v1",
"http://xbrl.org/PWD/2014-01-15/taxonomy-package")
catalogNSes = ("urn:oasis:names:tc:entity:xmlns:xml:catalog",)
pkg = {}
currentLang = Locale.getLanguageCode()
tree = etree.parse(metadataFile)
root = tree.getroot()
ns = root.tag.partition("}")[0][1:]
nsPrefix = "{{{}}}".format(ns)
if ns in txmyPkgNSes: # package file
for eltName in ("name", "description", "version"):
pkg[eltName] = ''
for m in root.iterchildren(tag=nsPrefix + eltName):
pkg[eltName] = m.text.strip()
break # take first entry if several
else: # oasis catalog, use dirname as the package name
# metadataFile may be a File object (with name) or string filename
fileName = getattr(metadataFile, 'fileName', # for FileSource named objects
getattr(metadataFile, 'name', # for io.file named objects
metadataFile)) # for string
pkg["name"] = os.path.basename(os.path.dirname(fileName))
pkg["description"] = "oasis catalog"
pkg["version"] = "(none)"
remappings = {}
for tag, prefixAttr, replaceAttr in (
(nsPrefix + "remapping", "prefix", "replaceWith"), # taxonomy package
(nsPrefix + "rewriteSystem", "systemIdStartString", "rewritePrefix")): # oasis catalog
for m in tree.iter(tag=tag):
prefixValue = m.get(prefixAttr)
replaceValue = m.get(replaceAttr)
if prefixValue and replaceValue is not None:
remappings[prefixValue] = replaceValue
pkg["remappings"] = remappings
nameToUrls = {}
pkg["nameToUrls"] = nameToUrls
for entryPointSpec in tree.iter(tag=nsPrefix + "entryPoint"):
name = None
# find closest match name node given xml:lang match to current language or no xml:lang
for nameNode in entryPointSpec.iter(tag=nsPrefix + "name"):
xmlLang = nameNode.get('{http://www.w3.org/XML/1998/namespace}lang')
if name is None or not xmlLang or currentLang == xmlLang:
name = nameNode.text
if currentLang == xmlLang: # most prefer one with the current locale's language
break
if not name:
name = _("<unnamed {0}>").format(unNamedCounter)
unNamedCounter += 1
epDocCount = 0
for epDoc in entryPointSpec.iterchildren(nsPrefix + "entryPointDocument"):
if epDocCount:
mainWin.addToLog(_("WARNING: skipping multiple-document entry point (not supported)"))
continue
epDocCount += 1
epUrl = epDoc.get('href')
base = epDoc.get('{http://www.w3.org/XML/1998/namespace}base') # cope with xml:base
if base:
resolvedUrl = urljoin(base, epUrl)
else:
resolvedUrl = epUrl
#perform prefix remappings
remappedUrl = resolvedUrl
for prefix, replace in remappings.items():
remappedUrl = remappedUrl.replace(prefix, replace, 1)
nameToUrls[name] = (remappedUrl, resolvedUrl)
return pkg