From c43ea35cc67ab2a5a6ab62c8946da3af44a92d1b Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Wed, 10 Feb 2016 14:46:38 +0100 Subject: [PATCH] Support different lang in template defaults --- patacrep/data/templates/default.tex | 14 ++++++++------ patacrep/data/templates/patacrep.tex | 29 ++++++++++++++-------------- patacrep/templates.py | 13 ++++++++++--- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/patacrep/data/templates/default.tex b/patacrep/data/templates/default.tex index 5fbf5c10..531c457a 100644 --- a/patacrep/data/templates/default.tex +++ b/patacrep/data/templates/default.tex @@ -31,12 +31,14 @@ schema: type: //arr contents: //str default: - title: "Guitar songbook" - author: "The Patacrep Team" -description.en: - title: "Title" - author: "Author" - classoptions: "LaTeX class options" + en: + title: "Guitar songbook" + author: "The Patacrep Team" +description: + en: + title: "Title" + author: "Author" + classoptions: "LaTeX class options" (* endvariables -*) (*- extends "songs.tex" -*) diff --git a/patacrep/data/templates/patacrep.tex b/patacrep/data/templates/patacrep.tex index fce3a9e1..ae5a5f43 100644 --- a/patacrep/data/templates/patacrep.tex +++ b/patacrep/data/templates/patacrep.tex @@ -43,20 +43,21 @@ schema: index: //str default: - subtitle: "" - version: "" - url: http://www.patacrep.com" - email: crep@team-on-fire.com - picture: img/treble_a - picturecopyright: "Dbolton \\url{http://commons.wikimedia.org/wiki/User:Dbolton}" - footer: "Generated using Songbook (\\url{http://www.patacrep.com})" - color: - songlink: 4e9a06 - hyperlink: 204a87 - bgcolor: - songnumber: D1E4AE - note: D1E4AE - index: D1E4AE + en: + subtitle: "" + version: "" + url: http://www.patacrep.com" + email: crep@team-on-fire.com + picture: img/treble_a + picturecopyright: "Dbolton \\url{http://commons.wikimedia.org/wiki/User:Dbolton}" + footer: "Generated using Songbook (\\url{http://www.patacrep.com})" + color: + songlink: 4e9a06 + hyperlink: 204a87 + bgcolor: + songnumber: D1E4AE + note: D1E4AE + index: D1E4AE (* endvariables -*) (*- extends "default.tex" -*) diff --git a/patacrep/templates.py b/patacrep/templates.py index b47dd683..7c410c8a 100644 --- a/patacrep/templates.py +++ b/patacrep/templates.py @@ -171,19 +171,26 @@ class TexBookRenderer(Renderer): for templatename, param in data.items(): template_config = user_config.get(templatename, {}) try: - variables[templatename] = self._get_variables(param, template_config) + variables[templatename] = self._get_variables(param, template_config, self.lang) except errors.SchemaError as exception: exception.message += "'template' > '{}' > ".format(templatename) raise exception return variables @staticmethod - def _get_variables(parameter, user_config): + def _get_variables(parameter, user_config, lang): '''Get the default value for the parameter, according to the language. Will raise `SchemaError` if the data does not respect the schema ''' - data = utils.DictOfDict(parameter.get('default', {})) + locale_default = parameter.get('default', {}) + # Initialize with default in english + data = locale_default.get('en', {}) + data = utils.DictOfDict(data) + + # Update default with current lang + data.update(locale_default.get(lang, {})) + # Update default with user_config data.update(user_config) schema = parameter.get('schema', {})