Browse Source

La langue du carnet est maintenant celle choisie par l'utilisateur, pas la locale (#18)

pull/22/head
Louis 11 years ago
parent
commit
f650ec711c
  1. 1
      songbook_core/build.py
  2. 30
      songbook_core/data/templates/default.tex
  3. 34
      songbook_core/data/templates/layout.tex
  4. 6
      songbook_core/data/templates/patacrep.tex
  5. 12
      songbook_core/templates.py

1
songbook_core/build.py

@ -108,6 +108,7 @@ class Songbook(object):
renderer = TexRenderer( renderer = TexRenderer(
self.config['template'], self.config['template'],
self.config['datadir'], self.config['datadir'],
self.config['lang'],
) )
context = renderer.get_variables() context = renderer.get_variables()

30
songbook_core/data/templates/default.tex

@ -1,40 +1,40 @@
(% variables %) (% variables %)
{ {
"title": {"description": {"en": "Title", "fr": "Titre"}, "title": {"description": {"english": "Title", "french": "Titre"},
"default": {"en": "Guitar songbook", "fr": "Recueil de chansons pour guitare"}, "default": {"english": "Guitar songbook", "french": "Recueil de chansons pour guitare"},
"mandatory":true "mandatory":true
}, },
"author": {"description": {"en": "Author", "fr": "Auteur"}, "author": {"description": {"english": "Author", "french": "Auteur"},
"default": {"en": "The Songbook Team", "fr": "L'équipe Songbook"}, "default": {"english": "The Songbook Team", "french": "L'équipe Songbook"},
"mandatory":true "mandatory":true
}, },
"subtitle": {"description": {"en": "Subtitle", "fr": "Sous-titre"}, "subtitle": {"description": {"english": "Subtitle", "french": "Sous-titre"},
"default": {"default": ""} "default": {"default": ""}
}, },
"version":{ "description": {"en": "Version", "fr": "Version"}, "version":{ "description": {"english": "Version", "french": "Version"},
"default": {"default": "undefined"} "default": {"default": "undefined"}
}, },
"web": {"description": {"en": "Website", "fr": "Site web"}, "web": {"description": {"english": "Website", "french": "Site web"},
"default": {"default": "http://www.patacrep.com"} "default": {"default": "http://www.patacrep.com"}
}, },
"mail": {"description": {"en": "Email", "fr": "Adresse électronique"}, "mail": {"description": {"english": "Email", "french": "Adresse électronique"},
"default": {"default": "crep@team-on-fire.com"} "default": {"default": "crep@team-on-fire.com"}
}, },
"picture": {"description": {"en": "Cover picture", "fr": "Image de couverture"}, "picture": {"description": {"english": "Cover picture", "french": "Image de couverture"},
"type": "file", "type": "file",
"default": {"default": "treble_a"} "default": {"default": "treble_a"}
}, },
"picturecopyright": {"description": {"en": "Copyright for the cover picture", "fr": "Copyright pour l'image de couverture"}, "picturecopyright": {"description": {"english": "Copyright for the cover picture", "french": "Copyright pour l'image de couverture"},
"default": {"default": "Dbolton \\url{http://commons.wikimedia.org/wiki/User:Dbolton}"} "default": {"default": "Dbolton \\url{http://commons.wikimedia.org/wiki/User:Dbolton}"}
}, },
"footer": {"description": {"en": "Footer", "fr": "Pied de page"}, "footer": {"description": {"english": "Footer", "french": "Pied de page"},
"default": {"default": "\\begin{flushright}Generated using Songbook (\\url{http://www.patacrep.com})\\end{flushright}"} "default": {"default": "\\begin{flushright}Generated using Songbook (\\url{http://www.patacrep.com})\\end{flushright}"}
}, },
"titleprefixwords": {"description": {"en": "Ignore some words in the beginning of song titles", "titleprefixwords": {"description": {"english": "Ignore some words in the beginning of song titles",
"fr": "Ignore des mots dans le classement des chansons"} "french": "Ignore des mots dans le classement des chansons"}
}, },
"authwords": {"descriptipn": {"en": "Set of options to process author string (LaTeX commands authsepword, authignoreword, authbyword)", "authwords": {"descriptipn": {"english": "Set of options to process author string (LaTeX commands authsepword, authignoreword, authbyword)",
"fr": "Options pour traiter les noms d'auteurs (commandes LaTeX authsepword, authignoreword, authbyword)"} "french": "Options pour traiter les noms d'auteurs (commandes LaTeX authsepword, authignoreword, authbyword)"}
} }
} }
(% endvariables %) (% endvariables %)

34
songbook_core/data/templates/layout.tex

@ -25,43 +25,43 @@
(% variables %) (% variables %)
{ {
"instruments": {"description": {"en": "Instruments", "fr": "Instruments"}, "instruments": {"description": {"english": "Instruments", "french": "Instruments"},
"type": "flag", "type": "flag",
"values": {"guitar": {"en": "Guitare", "fr": "Guitare"}, "values": {"guitar": {"english": "Guitare", "french": "Guitare"},
"ukulele": {"en": "Ukulele", "fr": "Ukulele"} "ukulele": {"english": "Ukulele", "french": "Ukulele"}
}, },
"join": ",", "join": ",",
"mandatory": true, "mandatory": true,
"default": {"default":["guitar"]} "default": {"default":["guitar"]}
}, },
"bookoptions": {"description": {"en": "Options", "fr": "Options"}, "bookoptions": {"description": {"english": "Options", "french": "Options"},
"type": "flag", "type": "flag",
"values": {"diagram": {"en": "Chords diagrams", "fr": "Diagrammes d'accords"}, "values": {"diagram": {"english": "Chords diagrams", "french": "Diagrammes d'accords"},
"importantdiagramonly": {"en": "Only importants diagrames", "fr": "Diagrammes importants uniquement"}, "importantdiagramonly": {"english": "Only importants diagrames", "french": "Diagrammes importants uniquement"},
"lilypond": {"en": "Lilypond music sheets", "fr": "Partitions lilypond"}, "lilypond": {"english": "Lilypond music sheets", "french": "Partitions lilypond"},
"pictures": {"en": "Cover pictures", "fr": "Couvertures d'albums"}, "pictures": {"english": "Cover pictures", "french": "Couvertures d'albums"},
"tabs": {"en": "Tablatures", "fr": "Tablatures"}, "tabs": {"english": "Tablatures", "french": "Tablatures"},
"repeatchords": {"en": "Repeat chords", "fr": "Répéter les accords"}, "repeatchords": {"english": "Repeat chords", "french": "Répéter les accords"},
"onesongperpage": {"en": "One song per page", "fr": "Une chanson par page"} "onesongperpage": {"english": "One song per page", "french": "Une chanson par page"}
}, },
"join": ",", "join": ",",
"mandatory": true, "mandatory": true,
"default": {"default":["diagram","pictures"]} "default": {"default":["diagram","pictures"]}
}, },
"booktype": {"description": {"en": "Type", "fr": "Type"}, "booktype": {"description": {"english": "Type", "french": "Type"},
"type": "enum", "type": "enum",
"values": {"chorded": {"en": "With guitar chords", "fr": "Avec accords de guitare" }, "values": {"chorded": {"english": "With guitar chords", "french": "Avec accords de guitare" },
"lyric": {"en": "Lyrics only", "fr": "Paroles uniquement"} "lyric": {"english": "Lyrics only", "french": "Paroles uniquement"}
}, },
"default": {"default":"chorded"}, "default": {"default":"chorded"},
"mandatory": true "mandatory": true
}, },
"mainfontsize": {"description": {"en": "Font Size", "fr": "Taille de police"}, "mainfontsize": {"description": {"english": "Font Size", "french": "Taille de police"},
"type":"font", "type":"font",
"default":{"default": "10"} "default":{"default": "10"}
}, },
"lang": {"description": {"en": "Language", "fr": "Langue"}, "lang": {"description": {"english": "Language", "french": "Langue"},
"default": {"en": "english", "fr": "french"} "default": {"english": "english", "french": "french"}
} }
} }
(% endvariables %) (% endvariables %)

6
songbook_core/data/templates/patacrep.tex

@ -1,14 +1,14 @@
(% variables %) (% variables %)
{ {
"songnumberbgcolor": {"description": {"en": "Number Shade", "fr": "Couleur des numéros"}, "songnumberbgcolor": {"description": {"english": "Number Shade", "french": "Couleur des numéros"},
"type": "color", "type": "color",
"default": {"default": "D1E4AE"} "default": {"default": "D1E4AE"}
}, },
"notebgcolor": {"description": {"en": "Note Shade", "fr": "Couleur des notes"}, "notebgcolor": {"description": {"english": "Note Shade", "french": "Couleur des notes"},
"type": "color", "type": "color",
"default": {"default": "D1E4AE"} "default": {"default": "D1E4AE"}
}, },
"indexbgcolor": {"description": {"en": "Index Shade", "fr": "Couleur d'index"}, "indexbgcolor": {"description": {"english": "Index Shade", "french": "Couleur d'index"},
"type": "color", "type": "color",
"default": {"default": "D1E4AE"} "default": {"default": "D1E4AE"}
} }

12
songbook_core/templates.py

@ -7,7 +7,6 @@ from jinja2.meta import find_referenced_templates as find_templates
import os import os
import re import re
import json import json
import locale
from songbook_core import errors from songbook_core import errors
@ -32,12 +31,16 @@ def _escape_tex(value):
class TexRenderer(object): class TexRenderer(object):
"""Render a template to a LaTeX file.""" """Render a template to a LaTeX file."""
def __init__(self, template, datadir=''): def __init__(self, template, datadir, lang):
'''Start a new jinja2 environment for .tex creation. '''Start a new jinja2 environment for .tex creation.
Arguments: Arguments:
- datadir: location of the user-defined templates - template: name of the template to use.
- datadir: location of the data directory (which max contain
file <datadir>/templates/<template>).
- lang: main language of songbook.
''' '''
self.lang = lang
self.texenv = Environment( self.texenv = Environment(
loader=ChoiceLoader([ loader=ChoiceLoader([
FileSystemLoader( FileSystemLoader(
@ -69,9 +72,6 @@ class TexRenderer(object):
), ),
) )
# Trick to get the language code
self.lang = locale.getdefaultlocale()[0].split('-')[0].split('_')[0]
def get_variables(self): def get_variables(self):
'''Get and return a dictionary with the default values '''Get and return a dictionary with the default values
for all the variables for all the variables

Loading…
Cancel
Save