diff --git a/README.md b/README.md index 1c778a8..14e19cb 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,14 @@ This project is a port of the [Access-Aide](https://github.com/kevinhendricks/Ac The _Access Aide_ plugin for Calibre is at a very early developmental stage. # Features - - Add 'en-GB' language declaration to `` tags. + - Add language declaration to `` tags. # Coming features - - Retrieve book language from book metadata; - Add in appropriate epub:type semantic tags; - Map epub:type attributes to their appropriate aria role attribute; - Add accessibility declarations to book metadata. -# Licence +# License Source code by Luca Baffa, released under the GPL 3 licence. -The plugin icon (`./icon/icon.png`) comes from the `adwaita-icon-theme` pack ([gitlab page](https://gitlab.gnome.org/GNOME/adwaita-icon-theme) of the project), released as CC SA 3.0 by the GNOME Project. \ No newline at end of file +The plugin icon (`./icon/icon.png`) comes from the `adwaita-icon-theme` pack ([gitlab page](https://gitlab.gnome.org/GNOME/adwaita-icon-theme) of the project), released as LGPL v3 by the GNOME Project. \ No newline at end of file diff --git a/__init__.py b/__init__.py index fcc5733..cbeeee0 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ class DemoPlugin(EditBookToolPlugin): name = 'Access Aide' - version = (0, 0, 1) + version = (0, 1, 0) author = 'Luca Baffa' supported_platforms = ['windows', 'osx', 'linux'] description = 'Access Aide plugin for Calibre' diff --git a/main.py b/main.py index 57ef315..98d8095 100644 --- a/main.py +++ b/main.py @@ -34,8 +34,8 @@ def main(self): return error_dialog(self.gui, 'No book open', 'Need to have a book open first', show=True) - # TODO Parse book metadata and find book language - lang = 'en-GB' + # get the book main language + lang = self.get_lang(container) # iterate over book files for name, media_type in container.mime_map.items(): @@ -48,6 +48,22 @@ def main(self): container.dirty(name) + def get_lang(self, container): + ''' + This method parses the OPF file, gets a list of the declared + languages and returns the first one (which we trust to be the + main language of the book) + ''' + + languages = container.opf_xpath('//dc:language/text()') + + if not languages: + return error_dialog(self.gui, 'No language declaration for book', + 'The OPF file does not report language info.', + show=True) + + return languages[0] + def add_lang(self, root, lang): ''' This method finds the tag of the given 'root' element