Browse Source

Merge pull request #200 from patacrep/yaml_translation

Yaml translation of defaults and descriptions
pull/193/head
Louis 9 years ago
parent
commit
5c044249fd
  1. 15
      patacrep/build.py
  2. 21
      patacrep/data/templates/default.tex
  3. 62
      patacrep/data/templates/patacrep.tex
  4. 133
      patacrep/data/templates/songbook_model.yml
  5. 30
      patacrep/songbook/__main__.py
  6. 13
      patacrep/templates.py
  7. 2
      test/test_content/test_content.py
  8. 2
      test/test_song/test_parser.py
  9. 131
      test/test_songbook/lang_default.tex.control
  10. 2
      test/test_songbook/lang_default.yaml
  11. 131
      test/test_songbook/lang_en.tex.control
  12. 5
      test/test_songbook/lang_en.yaml
  13. 131
      test/test_songbook/lang_fr.tex.control
  14. 5
      test/test_songbook/lang_fr.yaml

15
patacrep/build.py

@ -372,13 +372,16 @@ class SongbookBuilder:
raise errors.CleaningError(self.basename + ext, exception)
def config_model(*args):
"""Get the model structure with schema and default options"""
def config_model(key):
"""Get the model structure
key can be:
- schema
- default
- description
"""
model_path = pkg_datapath('templates', 'songbook_model.yml')
with encoding.open_read(model_path) as model_file:
data = yaml.load(model_file)
while data and args:
name, *args = args
data = data.get(name)
return data
return data.get(key, {})

21
patacrep/data/templates/default.tex

@ -31,12 +31,21 @@ 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"
fr:
title: "Recueil de chansons pour guitare"
author: "L'équipe Patacrep"
description:
en:
title: "Title"
author: "Author"
classoptions: "LaTeX class options"
fr:
title: "Titre"
author: "Auteur"
classoptions: "Options de la classe LaTeX"
(* endvariables -*)
(*- extends "songs.tex" -*)

62
patacrep/data/templates/patacrep.tex

@ -43,20 +43,54 @@ 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
fr:
footer: "Créé avec le programme Songbook (\\url{http://www.patacrep.com})"
description:
en:
subtitle: "Subtitle"
version: "Version"
url: "Website"
email: "Email"
picture: "Cover picture"
picturecopyright: "Copyright for the cover picture"
footer: "Footer"
color:
songlink: "Songlink color"
hyperlink: "Hyperlink color"
bgcolor:
songnumber: "Number Shade"
note: "Note Shade"
index: "Index Shade"
fr:
subtitle: "Sous-titre"
version: "Version"
url: "Site web"
email: "Adresse électronique"
picture: "Image de couverture"
picturecopyright: "Copyright pour l'image de couverture"
footer: "Pied de page"
color:
songlink: "Couleur des liens vers les chants"
hyperlink: "Couleurs des liens hypertextes"
bgcolor:
songnumber: "Couleur des numéros"
note: "Couleur des notes"
index: "Couleur d'index"
(* endvariables -*)
(*- extends "default.tex" -*)

133
patacrep/data/templates/songbook_model.yml

@ -79,44 +79,101 @@ schema:
contents: //str
- type: //nil
default:
book:
lang: en
encoding: utf-8
pictures: yes
template: patacrep.tex
onesongperpage: no
en:
book:
lang: en
encoding: utf-8
pictures: yes
template: patacrep.tex
onesongperpage: no
chords:
show: yes
diagramreminder: important
diagrampage: yes
repeatchords: yes
lilypond: no
tablatures: no
instrument: guitar
notation: alphascale
chords: # Options relatives aux accords
show: yes
diagramreminder: important
diagrampage: yes
repeatchords: yes
lilypond: no
tablatures: no
instrument: guitar
notation: alphascale
authors:
separators:
- and
ignore:
- unknown
after:
- by
authors: # Comment sont analysés les auteurs
separators:
- and
ignore:
- unknown
after:
- by
titles:
prefix:
- The
- Le
- La
- "L'"
- A
- Au
- Ces
- De
- Des
- El
- Les
- Ma
- Mon
- Un
titles: # Comment sont analysés les titres
prefix:
- The
- Le
- La
- "L'"
- A
- Au
- Ces
- De
- Des
- El
- Les
- Ma
- Mon
- Un
fr:
chords:
notation: solfedge
description:
en:
book:
lang: "Main language of the songbook"
encoding: "Encoding of the files"
pictures: "Display the album pictures"
template: "Main template to use"
onesongperpage: "Start every song on a new page"
chords:
show: "Display chords"
diagramreminder: "Display some diagram reminders before the songs"
diagrampage: "Add a diagram page"
repeatchords: "Repeat the chords inside the songs"
lilypond: "Display lilypond scores"
tablatures: "Display tablatures"
instrument: "Instrument for the diagrams"
notation: "Chord notation"
authors:
separators: "Separator words between artists"
ignore: "Artist names to ignore"
after: "Word preceding artist names"
titles:
prefix: "Words to ignore at the beginning of song titles for the index"
fr:
book:
lang: "Langue principale"
encoding: "Encodage des fichiers"
pictures: "Afficher les illustrations d'albums"
template: "Template de base"
onesongperpage: "Commencer chaque chant sur une nouvelle page"
chords:
show: "Afficher les accords"
diagramreminder: "Afficher quelques diagrammes d'accords au début des chants"
diagrampage: "Inclure une page de rappel des accords"
repeatchords: "Répéter l'affichage des accords au sein des chants"
lilypond: "Inclure les partitions lilypond"
tablatures: "Inclure les tablatures"
instrument: "Instrument pour les diagrammes d'accords"
notation: "Notation des accords"
authors:
separators: "Mots de séparation entre les artistes"
ignore: "Noms d'artistes à ignorer"
after: "Mots précédents les noms d'artistes"
titles:
prefix: "Préfixes de chants à ignorer dans le classement"

30
patacrep/songbook/__main__.py

@ -148,10 +148,7 @@ def main():
LOGGER.error("Error while loading file '{}'.".format(songbook_path))
sys.exit(1)
# Merge the default and user configs
default_songbook = DictOfDict(config_model('default'))
default_songbook.update(user_songbook)
songbook = dict(default_songbook)
songbook = add_songbook_defaults(user_songbook)
songbook['_filepath'] = os.path.abspath(songbook_path)
sbdir = os.path.dirname(songbook['_filepath'])
@ -193,5 +190,30 @@ def main():
sys.exit(0)
def add_songbook_defaults(user_songbook):
""" Adds the defaults values to the songbook if missing from
the user songbook
Priority:
- User values
- Default values of the user lang (if set)
- Default english values
"""
# Merge the default and user configs
locale_default = config_model('default')
# Initialize with default in english
default_songbook = locale_default.get('en', {})
default_songbook = DictOfDict(default_songbook)
if 'lang' in user_songbook.get('book', []):
# Update default with current lang
lang = user_songbook['book']['lang']
default_songbook.update(locale_default.get(lang, {}))
# Update default with user_songbook
default_songbook.update(user_songbook)
return dict(default_songbook)
if __name__ == '__main__':
main()

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

2
test/test_content/test_content.py

@ -101,7 +101,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
"""Generate the config to process the content"""
# Load the default songbook config
config = config_model('default')
config = config_model('default')['en']
datadirpaths = [os.path.join(os.path.dirname(__file__), 'datadir')]

2
test/test_song/test_parser.py

@ -76,7 +76,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
"""Iterate over song files to test."""
# Setting datadir
# Load the default songbook config
cls.config = config_model('default')
cls.config = config_model('default')['en']
if '_datadir' not in cls.config:
cls.config['_datadir'] = []

131
test/test_songbook/lang_default.tex.control

@ -0,0 +1,131 @@
%% Automatically generated document.
%% You may edit this file but all changes will be overwritten.
%% If you want to change this document, have a look at
%% the templating system.
%%
%% Generated using Songbook <http://www.patacrep.com>
\makeatletter
\def\input@path{ %
{@TEST_FOLDER@/latex/} %
{@DATA_FOLDER@/latex/} %
}
\makeatother
\documentclass[
]{article}
\usepackage[
chorded,
pictures,
repeatchords,
importantdiagramonly,
guitar,
]{crepbook}
\usepackage[
a4paper % paper size
,includeheadfoot % include header and footer into text size
,hmarginratio=1:1 % ratio between inner and outer margin (default)
,outer=1.8cm % outer margin (right)
,vmarginratio=1:1 % ratio between top and bottom margin
,bmargin=1.3cm % bottom margin
]{geometry}
\usepackage{lmodern}
\usepackage[english]{babel}
\lang{english}
\usepackage{graphicx}
\graphicspath{ %
{@TEST_FOLDER@/} %
{@DATA_FOLDER@/} %
}
\makeatletter
\@ifpackageloaded{hyperref}{}{
\usepackage{url}
\newcommand{\phantomsection}{}
\newcommand{\hyperlink}[2]{#2}
\newcommand{\href}[2]{\expandafter\url\expandafter{#1}}
}
\makeatother
\usepackage{chords}
\title{Guitar songbook}
\author{The Patacrep Team}
\newindex{titleidx}{lang_default_title}
\newauthorindex{authidx}{lang_default_auth}
\authignoreword{unknown}
\authbyword{by}
\authsepword{and}
\notenamesout{A}{B}{C}{D}{E}{F}{G}
\pagestyle{empty}\definecolor{SongNumberBgColor}{HTML}{D1E4AE}
\definecolor{NoteBgColor}{HTML}{D1E4AE}
\definecolor{IndexBgColor}{HTML}{D1E4AE}
\renewcommand{\snumbgcolor}{SongNumberBgColor}
\renewcommand{\notebgcolor}{NoteBgColor}
\renewcommand{\idxbgcolor}{IndexBgColor}
\definecolor{tango-green-3}{HTML}{4e9a06}
\definecolor{tango-blue-3}{HTML}{204a87}
\usepackage[
bookmarks,
bookmarksopen,
hyperfigures=true,
colorlinks=true,
linkcolor=tango-green-3,
urlcolor=tango-blue-3
]{hyperref}
\subtitle{}
\mail{crep@team-on-fire.com}
\web{http://www.patacrep.com}
\picture{img/treble_a}
\picturecopyright{Dbolton \url{http://commons.wikimedia.org/wiki/User:Dbolton}}
\footer{Generated using Songbook (\url{http://www.patacrep.com})}
\begin{document}
\maketitle
\showindex{\songindexname}{titleidx}
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\fi
\phantomsection
\addcontentsline{toc}{section}{\songlistname}
\end{document}

2
test/test_songbook/lang_default.yaml

@ -0,0 +1,2 @@
content:
- sort:

131
test/test_songbook/lang_en.tex.control

@ -0,0 +1,131 @@
%% Automatically generated document.
%% You may edit this file but all changes will be overwritten.
%% If you want to change this document, have a look at
%% the templating system.
%%
%% Generated using Songbook <http://www.patacrep.com>
\makeatletter
\def\input@path{ %
{@TEST_FOLDER@/latex/} %
{@DATA_FOLDER@/latex/} %
}
\makeatother
\documentclass[
]{article}
\usepackage[
chorded,
pictures,
repeatchords,
importantdiagramonly,
guitar,
]{crepbook}
\usepackage[
a4paper % paper size
,includeheadfoot % include header and footer into text size
,hmarginratio=1:1 % ratio between inner and outer margin (default)
,outer=1.8cm % outer margin (right)
,vmarginratio=1:1 % ratio between top and bottom margin
,bmargin=1.3cm % bottom margin
]{geometry}
\usepackage{lmodern}
\usepackage[english]{babel}
\lang{english}
\usepackage{graphicx}
\graphicspath{ %
{@TEST_FOLDER@/} %
{@DATA_FOLDER@/} %
}
\makeatletter
\@ifpackageloaded{hyperref}{}{
\usepackage{url}
\newcommand{\phantomsection}{}
\newcommand{\hyperlink}[2]{#2}
\newcommand{\href}[2]{\expandafter\url\expandafter{#1}}
}
\makeatother
\usepackage{chords}
\title{Guitar songbook}
\author{The Patacrep Team}
\newindex{titleidx}{lang_en_title}
\newauthorindex{authidx}{lang_en_auth}
\authignoreword{unknown}
\authbyword{by}
\authsepword{and}
\notenamesout{A}{B}{C}{D}{E}{F}{G}
\pagestyle{empty}\definecolor{SongNumberBgColor}{HTML}{D1E4AE}
\definecolor{NoteBgColor}{HTML}{D1E4AE}
\definecolor{IndexBgColor}{HTML}{D1E4AE}
\renewcommand{\snumbgcolor}{SongNumberBgColor}
\renewcommand{\notebgcolor}{NoteBgColor}
\renewcommand{\idxbgcolor}{IndexBgColor}
\definecolor{tango-green-3}{HTML}{4e9a06}
\definecolor{tango-blue-3}{HTML}{204a87}
\usepackage[
bookmarks,
bookmarksopen,
hyperfigures=true,
colorlinks=true,
linkcolor=tango-green-3,
urlcolor=tango-blue-3
]{hyperref}
\subtitle{}
\mail{crep@team-on-fire.com}
\web{http://www.patacrep.com}
\picture{img/treble_a}
\picturecopyright{Dbolton \url{http://commons.wikimedia.org/wiki/User:Dbolton}}
\footer{Generated using Songbook (\url{http://www.patacrep.com})}
\begin{document}
\maketitle
\showindex{\songindexname}{titleidx}
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\fi
\phantomsection
\addcontentsline{toc}{section}{\songlistname}
\end{document}

5
test/test_songbook/lang_en.yaml

@ -0,0 +1,5 @@
book:
lang: en
content:
- sort:

131
test/test_songbook/lang_fr.tex.control

@ -0,0 +1,131 @@
%% Automatically generated document.
%% You may edit this file but all changes will be overwritten.
%% If you want to change this document, have a look at
%% the templating system.
%%
%% Generated using Songbook <http://www.patacrep.com>
\makeatletter
\def\input@path{ %
{@TEST_FOLDER@/latex/} %
{@DATA_FOLDER@/latex/} %
}
\makeatother
\documentclass[
]{article}
\usepackage[
chorded,
pictures,
repeatchords,
importantdiagramonly,
guitar,
]{crepbook}
\usepackage[
a4paper % paper size
,includeheadfoot % include header and footer into text size
,hmarginratio=1:1 % ratio between inner and outer margin (default)
,outer=1.8cm % outer margin (right)
,vmarginratio=1:1 % ratio between top and bottom margin
,bmargin=1.3cm % bottom margin
]{geometry}
\usepackage{lmodern}
\usepackage[french]{babel}
\lang{french}
\usepackage{graphicx}
\graphicspath{ %
{@TEST_FOLDER@/} %
{@DATA_FOLDER@/} %
}
\makeatletter
\@ifpackageloaded{hyperref}{}{
\usepackage{url}
\newcommand{\phantomsection}{}
\newcommand{\hyperlink}[2]{#2}
\newcommand{\href}[2]{\expandafter\url\expandafter{#1}}
}
\makeatother
\usepackage{chords}
\title{Recueil de chansons pour guitare}
\author{L'équipe Patacrep}
\newindex{titleidx}{lang_fr_title}
\newauthorindex{authidx}{lang_fr_auth}
\authignoreword{unknown}
\authbyword{by}
\authsepword{and}
\notenamesout{La}{Si}{Do}{R\'e}{Mi}{Fa}{Sol}
\pagestyle{empty}\definecolor{SongNumberBgColor}{HTML}{D1E4AE}
\definecolor{NoteBgColor}{HTML}{D1E4AE}
\definecolor{IndexBgColor}{HTML}{D1E4AE}
\renewcommand{\snumbgcolor}{SongNumberBgColor}
\renewcommand{\notebgcolor}{NoteBgColor}
\renewcommand{\idxbgcolor}{IndexBgColor}
\definecolor{tango-green-3}{HTML}{4e9a06}
\definecolor{tango-blue-3}{HTML}{204a87}
\usepackage[
bookmarks,
bookmarksopen,
hyperfigures=true,
colorlinks=true,
linkcolor=tango-green-3,
urlcolor=tango-blue-3
]{hyperref}
\subtitle{}
\mail{crep@team-on-fire.com}
\web{http://www.patacrep.com}
\picture{img/treble_a}
\picturecopyright{Dbolton \url{http://commons.wikimedia.org/wiki/User:Dbolton}}
\footer{Créé avec le programme Songbook (\url{http://www.patacrep.com})}
\begin{document}
\maketitle
\showindex{\songindexname}{titleidx}
\showindex{\authorindexname}{authidx}
% list of chords
\ifchorded
\ifdiagram
\phantomsection
\addcontentsline{toc}{section}{\chordlistname}
\chords
\fi
\fi
\phantomsection
\addcontentsline{toc}{section}{\songlistname}
\end{document}

5
test/test_songbook/lang_fr.yaml

@ -0,0 +1,5 @@
book:
lang: fr
content:
- sort:
Loading…
Cancel
Save