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(
self.config['template'],
self.config['datadir'],
self.config['lang'],
)
context = renderer.get_variables()

30
songbook_core/data/templates/default.tex

@ -1,40 +1,40 @@
(% variables %)
{
"title": {"description": {"en": "Title", "fr": "Titre"},
"default": {"en": "Guitar songbook", "fr": "Recueil de chansons pour guitare"},
"title": {"description": {"english": "Title", "french": "Titre"},
"default": {"english": "Guitar songbook", "french": "Recueil de chansons pour guitare"},
"mandatory":true
},
"author": {"description": {"en": "Author", "fr": "Auteur"},
"default": {"en": "The Songbook Team", "fr": "L'équipe Songbook"},
"author": {"description": {"english": "Author", "french": "Auteur"},
"default": {"english": "The Songbook Team", "french": "L'équipe Songbook"},
"mandatory":true
},
"subtitle": {"description": {"en": "Subtitle", "fr": "Sous-titre"},
"subtitle": {"description": {"english": "Subtitle", "french": "Sous-titre"},
"default": {"default": ""}
},
"version":{ "description": {"en": "Version", "fr": "Version"},
"version":{ "description": {"english": "Version", "french": "Version"},
"default": {"default": "undefined"}
},
"web": {"description": {"en": "Website", "fr": "Site web"},
"web": {"description": {"english": "Website", "french": "Site web"},
"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"}
},
"picture": {"description": {"en": "Cover picture", "fr": "Image de couverture"},
"picture": {"description": {"english": "Cover picture", "french": "Image de couverture"},
"type": "file",
"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}"}
},
"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}"}
},
"titleprefixwords": {"description": {"en": "Ignore some words in the beginning of song titles",
"fr": "Ignore des mots dans le classement des chansons"}
"titleprefixwords": {"description": {"english": "Ignore some words in the beginning of song titles",
"french": "Ignore des mots dans le classement des chansons"}
},
"authwords": {"descriptipn": {"en": "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)"}
"authwords": {"descriptipn": {"english": "Set of options to process author string (LaTeX commands authsepword, authignoreword, authbyword)",
"french": "Options pour traiter les noms d'auteurs (commandes LaTeX authsepword, authignoreword, authbyword)"}
}
}
(% endvariables %)

34
songbook_core/data/templates/layout.tex

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

6
songbook_core/data/templates/patacrep.tex

@ -1,14 +1,14 @@
(% variables %)
{
"songnumberbgcolor": {"description": {"en": "Number Shade", "fr": "Couleur des numéros"},
"songnumberbgcolor": {"description": {"english": "Number Shade", "french": "Couleur des numéros"},
"type": "color",
"default": {"default": "D1E4AE"}
},
"notebgcolor": {"description": {"en": "Note Shade", "fr": "Couleur des notes"},
"notebgcolor": {"description": {"english": "Note Shade", "french": "Couleur des notes"},
"type": "color",
"default": {"default": "D1E4AE"}
},
"indexbgcolor": {"description": {"en": "Index Shade", "fr": "Couleur d'index"},
"indexbgcolor": {"description": {"english": "Index Shade", "french": "Couleur d'index"},
"type": "color",
"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 re
import json
import locale
from songbook_core import errors
@ -32,12 +31,16 @@ def _escape_tex(value):
class TexRenderer(object):
"""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.
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(
loader=ChoiceLoader([
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):
'''Get and return a dictionary with the default values
for all the variables

Loading…
Cancel
Save