diff --git a/__init__.py b/__init__.py index f706c20..772ec06 100644 --- a/__init__.py +++ b/__init__.py @@ -21,7 +21,7 @@ class AccessAidePlugin(EditBookToolPlugin): name = 'Access Aide' - version = (0, 1, 12) + version = (0, 1, 14) author = 'Luca Baffa' supported_platforms = ['windows', 'osx', 'linux'] description = 'Enhance accessibility features in EPUB files.' diff --git a/main.py b/main.py index 11b1bfd..49e7f8f 100644 --- a/main.py +++ b/main.py @@ -101,8 +101,9 @@ def main(self): self.add_aria(container.parsed(name)) elif media_type in OPF_MIME: + self.add_lang_opf(container.parsed(name), + self.get_lang(container)) self.add_metadata(container) - self.add_a11y(container) else: @@ -154,6 +155,25 @@ def add_lang(self, root, lang): self.write_attrib(html, '{http://www.w3.org/XML/1998/namespace}lang', lang, self.lang_stat) + def add_lang_opf(self, root, lang): + '''Add language attributes to tag in the `content.opf` file. + + This method finds the tag of the given 'root' element + and adds a 'xml:lang' language declarations. Changes are tracked and + successes increase a stat counter. + + Note: the 'xml:lang' attribute of the note is set to the + book language value defined in the OPF file (). + This would not be appropriate in the case where the book is written + in a language different from the one used in the `content.opf` file. + ''' + + pkg = root.xpath('//*[local-name()="package"]')[0] + + # set lang for 'xml:lang' attribute + self.write_attrib(pkg, '{http://www.w3.org/XML/1998/namespace}lang', + lang, self.lang_stat) + def add_aria(self, root): '''Add aria roles.