Browse Source

Allow {language: bable_language} and {lang: code_lang} in chordpro

pull/124/head
Oliverpool 9 years ago
parent
commit
410e7465a4
  1. 15
      patacrep/songs/chordpro/__init__.py
  2. 2
      patacrep/songs/chordpro/ast.py
  3. 1
      test/test_chordpro/lang.sgc
  4. 1
      test/test_chordpro/lang.source

15
patacrep/songs/chordpro/__init__.py

@ -35,9 +35,18 @@ class ChordproSong(Song):
song = parse_song(song.read(), self.fullpath)
self.authors = song.authors
self.titles = song.titles
#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)
# Lang inverted priority (last one is preferred):
# config['lang']
# song.language
# song.lang
self.lang = self.config['lang']
language = song.get_data_argument('language')
if language:
# self.lang is automatically updated
self.language = language
self.lang = song.get_data_argument('lang', self.lang)
self.data = song.meta
self.cached = {
'song': song,

2
patacrep/songs/chordpro/ast.py

@ -245,7 +245,7 @@ class Song(AST):
self.meta[data.keyword] = []
self.meta[data.keyword].append(data)
def get_data_argument(self, keyword, default):
def get_data_argument(self, keyword, default=None):
"""Return `self.meta[keyword].argument`.
Return `default` if `self.meta[keyword]` does not exist.

1
test/test_chordpro/lang.sgc

@ -0,0 +1 @@
{lang: fr}

1
test/test_chordpro/lang.source

@ -0,0 +1 @@
{language: french}
Loading…
Cancel
Save