~pgokul/calibre/srikosam

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/metadata/docx.py

  • Committer: Kovid Goyal
  • Date: 2013-05-04 05:36:59 UTC
  • Revision ID: kovid@kovidgoyal.net-20130504053659-5psggtezwfw5d2t4
Docx metadata: Read the language of the file, if present

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
from lxml import etree
11
11
 
12
12
from calibre.ebooks.metadata.book.base import Metadata
 
13
from calibre.utils.localization import canonicalize_lang
13
14
from calibre.utils.zipfile import ZipFile
14
15
from calibre.utils.magick.draw import identify_data
15
16
from calibre.ebooks.oeb.base import DC11_NS
52
53
        raw = etree.tostring(desc[0], method='text', encoding=unicode)
53
54
        mi.comments = raw
54
55
 
 
56
    langs = []
 
57
    for lang in XPath('//dc:language')(root):
 
58
        if lang.text and lang.text.strip():
 
59
            l = canonicalize_lang(lang.text)
 
60
            if l:
 
61
                langs.append(l)
 
62
    if langs:
 
63
        mi.languages = langs
 
64
 
55
65
def _read_app_props(raw, mi):
56
66
    root = etree.fromstring(raw, parser=RECOVER_PARSER)
57
67
    company = root.xpath('//*[local-name()="Company"]')