Browse Source

Support different lang in template defaults

pull/200/head
Oliverpool 9 years ago
parent
commit
c43ea35cc6
  1. 14
      patacrep/data/templates/default.tex
  2. 29
      patacrep/data/templates/patacrep.tex
  3. 13
      patacrep/templates.py

14
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" -*)

29
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" -*)

13
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', {})

Loading…
Cancel
Save