Browse Source

Differentiate language code (lang) and babel language (language)

pull/124/head
Oliverpool 9 years ago
parent
commit
60a22d2235
  1. 2
      examples/example-all.sb
  2. 2
      examples/songs/greensleeves.sgc
  3. 2
      examples/songs/tests/chords.sgc
  4. 2
      examples/songs/tests/errors.sgc
  5. 2
      patacrep/build.py
  6. 10
      patacrep/data/templates/songs.tex
  7. 30
      patacrep/songs/__init__.py
  8. 5
      patacrep/songs/chordpro/__init__.py
  9. 2
      patacrep/songs/chordpro/ast.py
  10. 4
      patacrep/songs/chordpro/data/chordpro/song_header
  11. 3
      patacrep/templates.py
  12. 2
      test/test_chordpro/00.sgc
  13. 2
      test/test_chordpro/01.sgc
  14. 2
      test/test_chordpro/02.sgc
  15. 2
      test/test_chordpro/03.sgc
  16. 2
      test/test_chordpro/04.sgc
  17. 2
      test/test_chordpro/05.sgc
  18. 2
      test/test_chordpro/06.sgc
  19. 2
      test/test_chordpro/07.sgc
  20. 2
      test/test_chordpro/08.sgc
  21. 2
      test/test_chordpro/09.sgc
  22. 2
      test/test_chordpro/10.sgc
  23. 2
      test/test_chordpro/11.sgc
  24. 2
      test/test_chordpro/12.sgc
  25. 2
      test/test_chordpro/13.sgc
  26. 2
      test/test_chordpro/21.sgc
  27. 2
      test/test_chordpro/22.sgc
  28. 2
      test/test_chordpro/23.sgc
  29. 2
      test/test_chordpro/24.sgc
  30. 2
      test/test_chordpro/25.sgc
  31. 2
      test/test_chordpro/26.sgc
  32. 2
      test/test_chordpro/27.sgc
  33. 2
      test/test_chordpro/28.sgc
  34. 2
      test/test_chordpro/29.sgc
  35. 2
      test/test_chordpro/author_names.sgc
  36. 2
      test/test_chordpro/chords.sgc
  37. 2
      test/test_chordpro/customchords.sgc
  38. 2
      test/test_chordpro/greensleeves.sgc
  39. 2
      test/test_chordpro/greensleeves.source
  40. 2
      test/test_chordpro/invalid_chord.sgc
  41. 2
      test/test_chordpro/invalid_customchord.sgc
  42. 2
      test/test_chordpro/metadata.sgc
  43. 4
      test/test_chordpro/metadata.source
  44. 2
      test/test_chordpro/newline.sgc
  45. 2
      test/test_chordpro/nolyrics.sgc
  46. 2
      test/test_chordpro/ukulelechords.sgc

2
examples/example-all.sb

@ -8,7 +8,7 @@
"booktype" : "chorded", "booktype" : "chorded",
"datadir": ["datadir2"], "datadir": ["datadir2"],
"template" : "patacrep.tex", "template" : "patacrep.tex",
"lang" : "french", "lang" : "fr",
"encoding": "utf8", "encoding": "utf8",
"authwords" : { "authwords" : {
"sep" : ["and", "et"] "sep" : ["and", "et"]

2
examples/songs/greensleeves.sgc

@ -1,4 +1,4 @@
{language : english} {lang : en}
{columns : 2} {columns : 2}
{ title : Greensleeves} { title : Greensleeves}
{subtitle: Test of the chordpro format} {subtitle: Test of the chordpro format}

2
examples/songs/tests/chords.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{columns: 1} {columns: 1}
{title: Chords testing} {title: Chords testing}
{subtitle: Test of the chords specification and LaTeX translation} {subtitle: Test of the chords specification and LaTeX translation}

2
examples/songs/tests/errors.sgc

@ -1,4 +1,4 @@
{language : english} {lang : en}
{columns : 2} {columns : 2}
{ title : Error} { title : Error}
{subtitle: A chordpro file with many errors} {subtitle: A chordpro file with many errors}

2
patacrep/build.py

@ -29,7 +29,7 @@ GENERATED_EXTENSIONS = [
] ]
DEFAULT_CONFIG = { DEFAULT_CONFIG = {
'template': "default.tex", 'template': "default.tex",
'lang': 'english', 'lang': 'en',
'content': [], 'content': [],
'titleprefixwords': [], 'titleprefixwords': [],
'encoding': None, 'encoding': None,

10
patacrep/data/templates/songs.tex

@ -52,7 +52,7 @@
"mandatory": true "mandatory": true
}, },
"lang": {"description": {"english": "Language", "french": "Langue"}, "lang": {"description": {"english": "Language", "french": "Langue"},
"default": {"english": "english", "french": "french"} "default": {"en": "english", "fr": "french"}
}, },
"titleprefixwords": {"description": {"english": "Ignore some words in the beginning of song titles", "titleprefixwords": {"description": {"english": "Ignore some words in the beginning of song titles",
"french": "Ignore des mots dans le classement des chansons"}, "french": "Ignore des mots dans le classement des chansons"},
@ -80,11 +80,11 @@
(* block songbookpreambule *) (* block songbookpreambule *)
(( super() )) (( super() ))
(* for lang in _languages -*) (* for language in _languages -*)
\PassOptionsToPackage{((lang))}{babel} \PassOptionsToPackage{((language))}{babel}
(* endfor *) (* endfor *)
\usepackage[((lang))]{babel} \usepackage[(( lang2language(lang) ))]{babel}
\lang{((lang))} \lang{(( lang2language(lang) ))}
\usepackage{graphicx} \usepackage{graphicx}
\graphicspath{ % \graphicspath{ %

30
patacrep/songs/__init__.py

@ -7,12 +7,27 @@ import logging
import os import os
import pickle import pickle
import re import re
from collections import OrderedDict
from patacrep.authors import process_listauthors from patacrep.authors import process_listauthors
from patacrep import files, encoding from patacrep import files, encoding
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
BABEL_LANGUAGES = OrderedDict((
('fr', 'french'),
('en', 'english'),
('de', 'german'),
))
def lang2language(lang):
try:
return BABEL_LANGUAGES[lang]
except KeyError:
# TODO: raise a nice error
print('Unknown lang:' + lang)
return 'english'
def cached_name(datadir, filename): def cached_name(datadir, filename):
"""Return the filename of the cache version of the file.""" """Return the filename of the cache version of the file."""
fullpath = os.path.abspath(os.path.join(datadir, '.cache', filename)) fullpath = os.path.abspath(os.path.join(datadir, '.cache', filename))
@ -246,6 +261,21 @@ class Song:
filepath = self.search_file(filename, ['', '.ly']) filepath = self.search_file(filename, ['', '.ly'])
return filepath if none_if_not_found or filepath else filename return filepath if none_if_not_found or filepath else filename
@property
def language(self):
"""Return the string corresponding to the babel (LaTeX) language"""
return lang2language(self.lang)
@language.setter
def language(self, language):
"""Set the language code"""
for lang, babel_language in BABEL_LANGUAGES.items():
if language == babel_language:
self.lang = lang
return
# TODO: raise a nice error
print('Unsupported language:' + language)
def unprefixed_title(title, prefixes): def unprefixed_title(title, prefixes):
"""Remove the first prefix of the list in the beginning of title (if any). """Remove the first prefix of the list in the beginning of title (if any).
""" """

5
patacrep/songs/chordpro/__init__.py

@ -35,7 +35,9 @@ class ChordproSong(Song):
song = parse_song(song.read(), self.fullpath) song = parse_song(song.read(), self.fullpath)
self.authors = song.authors self.authors = song.authors
self.titles = song.titles self.titles = song.titles
self.language = song.get_data_argument('language', self.config['lang']) #language and lang are synomyms in the directives
language = song.get_data_argument('language', self.config['lang'])
self.lang = song.get_data_argument('lang', language)
self.data = song.meta self.data = song.meta
self.cached = { self.cached = {
'song': song, 'song': song,
@ -47,6 +49,7 @@ class ChordproSong(Song):
context = { context = {
'language': self.language, 'language': self.language,
'lang': self.lang,
"titles": self.titles, "titles": self.titles,
"authors": self.authors, "authors": self.authors,
"metadata": self.data, "metadata": self.data,

2
patacrep/songs/chordpro/ast.py

@ -181,7 +181,7 @@ class Song(AST):
- content: the song content, as a list of objects `foo` such that - content: the song content, as a list of objects `foo` such that
`foo.inline` is True. `foo.inline` is True.
- titles: The list of titles - titles: The list of titles
- language: The language (if set), None otherwise - lang: The language code (if set), None otherwise
- authors: The list of authors - authors: The list of authors
- meta: Every other metadata. - meta: Every other metadata.
""" """

4
patacrep/songs/chordpro/data/chordpro/song_header

@ -1,5 +1,5 @@
(* if language is defined -*) (* if lang is defined -*)
{language: (( language ))} {lang: (( lang ))}
(* endif *) (* endif *)
(* if metadata.columns is defined -*) (* if metadata.columns is defined -*)
{columns: (( metadata.columns ))} {columns: (( metadata.columns ))}

3
patacrep/templates.py

@ -8,7 +8,7 @@ import os
import re import re
import json import json
from patacrep import errors, files from patacrep import errors, files, songs
import patacrep.encoding import patacrep.encoding
_LATEX_SUBS = ( _LATEX_SUBS = (
@ -84,6 +84,7 @@ class Renderer:
self.jinjaenv.trim_blocks = True self.jinjaenv.trim_blocks = True
self.jinjaenv.lstrip_blocks = True self.jinjaenv.lstrip_blocks = True
self.jinjaenv.globals["path2posix"] = files.path2posix self.jinjaenv.globals["path2posix"] = files.path2posix
self.jinjaenv.globals["lang2language"] = songs.lang2language
self.template = self.jinjaenv.get_template(template) self.template = self.jinjaenv.get_template(template)

2
test/test_chordpro/00.sgc

@ -1 +1 @@
{language: english} {lang: en}

2
test/test_chordpro/01.sgc

@ -1,3 +1,3 @@
{language: english} {lang: en}
A verse line A verse line

2
test/test_chordpro/02.sgc

@ -1,3 +1,3 @@
{language: english} {lang: en}
{title: A directive} {title: A directive}

2
test/test_chordpro/03.sgc

@ -1,2 +1,2 @@
{language: english} {lang: en}

2
test/test_chordpro/04.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{start_of_chorus} {start_of_chorus}
A one line chorus A one line chorus

2
test/test_chordpro/05.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{start_of_bridge} {start_of_bridge}
A one line bridge A one line bridge

2
test/test_chordpro/06.sgc

@ -1,2 +1,2 @@
{language: english} {lang: en}

2
test/test_chordpro/07.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{start_of_tab} {start_of_tab}
A tab A tab

2
test/test_chordpro/08.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
A lot of new lines A lot of new lines

2
test/test_chordpro/09.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{title: and a directive} {title: and a directive}

2
test/test_chordpro/10.sgc

@ -1,3 +1,3 @@
{language: english} {lang: en}
A line[A] with a chord A line[A] with a chord

2
test/test_chordpro/11.sgc

@ -1,3 +1,3 @@
{language: english} {lang: en}
A line ending with a chord[A] A line ending with a chord[A]

2
test/test_chordpro/12.sgc

@ -1,3 +1,3 @@
{language: english} {lang: en}
[A]A line starting with a chord [A]A line starting with a chord

2
test/test_chordpro/13.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{start_of_tab} {start_of_tab}
A table A table

2
test/test_chordpro/21.sgc

@ -1,3 +1,3 @@
{language: english} {lang: en}
A verse line A verse line

2
test/test_chordpro/22.sgc

@ -1,3 +1,3 @@
{language: english} {lang: en}
{title: A directive} {title: A directive}

2
test/test_chordpro/23.sgc

@ -1 +1 @@
{language: english} {lang: en}

2
test/test_chordpro/24.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{start_of_chorus} {start_of_chorus}
A one line chorus A one line chorus

2
test/test_chordpro/25.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{start_of_bridge} {start_of_bridge}
A one line bridge A one line bridge

2
test/test_chordpro/26.sgc

@ -1,2 +1,2 @@
{language: english} {lang: en}

2
test/test_chordpro/27.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{start_of_tab} {start_of_tab}
A tab A tab

2
test/test_chordpro/28.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
A lot of new lines A lot of new lines

2
test/test_chordpro/29.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{title: and a directive} {title: and a directive}

2
test/test_chordpro/author_names.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{title: Title} {title: Title}
{artist: The Beatles} {artist: The Beatles}
{artist: Oasis} {artist: Oasis}

2
test/test_chordpro/chords.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
[A]Simple [A]Simple
[Bb]Bémol [Bb]Bémol

2
test/test_chordpro/customchords.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{define: E4 base-fret 7 frets 0 1 3 3 x x} {define: E4 base-fret 7 frets 0 1 3 3 x x}
{define: E5 base-fret 7 frets 0 1 3 3 x x fingers - 1 2 3 - -} {define: E5 base-fret 7 frets 0 1 3 3 x x fingers - 1 2 3 - -}
{define: E5/A* base-fret 7 frets 0 1 3 3 x x fingers - 1 2 3 - -} {define: E5/A* base-fret 7 frets 0 1 3 3 x x fingers - 1 2 3 - -}

2
test/test_chordpro/greensleeves.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{columns: 2} {columns: 2}
{title: Greensleeves} {title: Greensleeves}
{title: Un autre sous-titre} {title: Un autre sous-titre}

2
test/test_chordpro/greensleeves.source

@ -1,4 +1,4 @@
{language : english} {lang : en}
{columns : 2} {columns : 2}
{subtitle : Un sous titre} {subtitle : Un sous titre}
{ title : Greensleeves} { title : Greensleeves}

2
test/test_chordpro/invalid_chord.sgc

@ -1,3 +1,3 @@
{language: english} {lang: en}
This is invalid. This is invalid.

2
test/test_chordpro/invalid_customchord.sgc

@ -1,2 +1,2 @@
{language: english} {lang: en}

2
test/test_chordpro/metadata.sgc

@ -1,4 +1,4 @@
{language: french} {lang: fr}
{capo: Capo} {capo: Capo}
{title: Title} {title: Title}
{title: Subtitle1} {title: Subtitle1}

4
test/test_chordpro/metadata.source

@ -4,8 +4,8 @@
{subtitle: Subtitle4} {subtitle: Subtitle4}
{t: Subtitle2} {t: Subtitle2}
{st: Subtitle5} {st: Subtitle5}
{language: english} {lang: en}
{language: french} {lang: fr}
{by: Author1} {by: Author1}
{artist: Author2} {artist: Author2}
{album: Album} {album: Album}

2
test/test_chordpro/newline.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
This is a verse This is a verse
With a new line With a new line

2
test/test_chordpro/nolyrics.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
A chorus [A]with lyrics A chorus [A]with lyrics
[Emaj3]maj et nombre [Emaj3]maj et nombre

2
test/test_chordpro/ukulelechords.sgc

@ -1,4 +1,4 @@
{language: english} {lang: en}
{define: G frets 0 2 3 2} {define: G frets 0 2 3 2}
{define: D7 frets 2 2 2 3 fingers 1 1 1 2} {define: D7 frets 2 2 2 3 fingers 1 1 1 2}
{define: G frets 3 2 0 0 0 3} {define: G frets 3 2 0 0 0 3}

Loading…
Cancel
Save