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 type: //arr
contents: //str contents: //str
default: default:
title: "Guitar songbook" en:
author: "The Patacrep Team" title: "Guitar songbook"
description.en: author: "The Patacrep Team"
title: "Title" description:
author: "Author" en:
classoptions: "LaTeX class options" title: "Title"
author: "Author"
classoptions: "LaTeX class options"
(* endvariables -*) (* endvariables -*)
(*- extends "songs.tex" -*) (*- extends "songs.tex" -*)

29
patacrep/data/templates/patacrep.tex

@ -43,20 +43,21 @@ schema:
index: //str index: //str
default: default:
subtitle: "" en:
version: "" subtitle: ""
url: http://www.patacrep.com" version: ""
email: crep@team-on-fire.com url: http://www.patacrep.com"
picture: img/treble_a email: crep@team-on-fire.com
picturecopyright: "Dbolton \\url{http://commons.wikimedia.org/wiki/User:Dbolton}" picture: img/treble_a
footer: "Generated using Songbook (\\url{http://www.patacrep.com})" picturecopyright: "Dbolton \\url{http://commons.wikimedia.org/wiki/User:Dbolton}"
color: footer: "Generated using Songbook (\\url{http://www.patacrep.com})"
songlink: 4e9a06 color:
hyperlink: 204a87 songlink: 4e9a06
bgcolor: hyperlink: 204a87
songnumber: D1E4AE bgcolor:
note: D1E4AE songnumber: D1E4AE
index: D1E4AE note: D1E4AE
index: D1E4AE
(* endvariables -*) (* endvariables -*)
(*- extends "default.tex" -*) (*- extends "default.tex" -*)

13
patacrep/templates.py

@ -171,19 +171,26 @@ class TexBookRenderer(Renderer):
for templatename, param in data.items(): for templatename, param in data.items():
template_config = user_config.get(templatename, {}) template_config = user_config.get(templatename, {})
try: try:
variables[templatename] = self._get_variables(param, template_config) variables[templatename] = self._get_variables(param, template_config, self.lang)
except errors.SchemaError as exception: except errors.SchemaError as exception:
exception.message += "'template' > '{}' > ".format(templatename) exception.message += "'template' > '{}' > ".format(templatename)
raise exception raise exception
return variables return variables
@staticmethod @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. '''Get the default value for the parameter, according to the language.
Will raise `SchemaError` if the data does not respect the schema 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) data.update(user_config)
schema = parameter.get('schema', {}) schema = parameter.get('schema', {})

Loading…
Cancel
Save