Browse Source

Only one language per song (the latest defined)

pull/118/head
Oliverpool 9 years ago
parent
commit
133a13e0f6
  1. 2
      patacrep/content/song.py
  2. 6
      patacrep/latex/ast.py
  3. 6
      patacrep/songs/__init__.py
  4. 4
      patacrep/songs/chordpro/__init__.py
  5. 1
      patacrep/songs/chordpro/ast.py
  6. 4
      patacrep/songs/latex/__init__.py
  7. 2
      test/test_chordpro/metadata.source

2
patacrep/content/song.py

@ -92,7 +92,7 @@ def parse(keyword, argument, contentlist, config):
config, config,
)) ))
songlist.append(renderer) songlist.append(renderer)
config["_languages"].update(renderer.song.languages) config["_languages"].update(renderer.song.language)
if len(songlist) > before: if len(songlist) > before:
break break
if len(songlist) == before: if len(songlist) == before:

6
patacrep/latex/ast.py

@ -2,6 +2,8 @@
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
DEFAULT_LANGUAGE = "english"
class AST: class AST:
"""Base class for the tree.""" """Base class for the tree."""
# pylint: disable=no-init # pylint: disable=no-init
@ -16,7 +18,7 @@ class AST:
parsing. parsing.
""" """
cls.metadata = { cls.metadata = {
'@languages': set(), '@language': DEFAULT_LANGUAGE,
} }
class Expression(AST): class Expression(AST):
@ -44,7 +46,7 @@ class Command(AST):
self.optional = optional self.optional = optional
if name == r'\selectlanguage': if name == r'\selectlanguage':
self.metadata['@languages'] |= set(self.mandatory) self.metadata['@language'] = self.mandatory
def __str__(self): def __str__(self):
if self.name in [r'\emph']: if self.name in [r'\emph']:

6
patacrep/songs/__init__.py

@ -89,7 +89,7 @@ class Song:
"cached", "cached",
"data", "data",
"subpath", "subpath",
"languages", "language",
"authors", "authors",
"_filehash", "_filehash",
"_version", "_version",
@ -184,8 +184,8 @@ class Song:
- titles: the list of (raw) titles. This list will be processed to - titles: the list of (raw) titles. This list will be processed to
remove prefixes. remove prefixes.
- languages: the list of languages used in the song, as languages - language: the main language of the song, as language recognized by
recognized by the LaTeX babel package. the LaTeX babel package.
- authors: the list of (raw) authors. This list will be processed to - authors: the list of (raw) authors. This list will be processed to
'clean' it (see function :func:`patacrep.authors.processauthors`). 'clean' it (see function :func:`patacrep.authors.processauthors`).
- data: song metadata. Used (among others) to sort the songs. - data: song metadata. Used (among others) to sort the songs.

4
patacrep/songs/chordpro/__init__.py

@ -38,7 +38,7 @@ 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.languages = song.get_data_argument('language', [self.config['lang']]) self.language = song.get_data_argument('language', self.config['lang'])
self.data = song.meta self.data = song.meta
self.cached = { self.cached = {
'song': song, 'song': song,
@ -49,7 +49,7 @@ class ChordproSong(Song):
templatedirs = [] templatedirs = []
context = { context = {
'language': self.languages[0], 'language': self.language,
"titles": self.titles, "titles": self.titles,
"authors": self.authors, "authors": self.authors,
"metadata": self.data, "metadata": self.data,

1
patacrep/songs/chordpro/ast.py

@ -193,7 +193,6 @@ class Song(AST):
"artist": "add_author", "artist": "add_author",
"key": "add_key", "key": "add_key",
"define": "add_cumulative", "define": "add_cumulative",
"language": "add_cumulative",
} }
def __init__(self, filename): def __init__(self, filename):

4
patacrep/songs/latex/__init__.py

@ -20,8 +20,8 @@ class LatexSong(Song):
self.data = parse_song(song.read(), self.fullpath) self.data = parse_song(song.read(), self.fullpath)
self.titles = self.data['@titles'] self.titles = self.data['@titles']
del self.data['@titles'] del self.data['@titles']
self.languages = self.data['@languages'] self.language = self.data['@language']
del self.data['@languages'] del self.data['@language']
if "by" in self.data: if "by" in self.data:
self.authors = [self.data['by']] self.authors = [self.data['by']]
del self.data['by'] del self.data['by']

2
test/test_chordpro/metadata.source

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

Loading…
Cancel
Save