Fix "is not a valid language" on upload
This commit is contained in:
parent
e29247774c
commit
4cf71dd336
|
@ -135,13 +135,7 @@ def get_comic_info(tmp_file_path, original_file_name, original_file_extension, r
|
||||||
loadedMetadata = archive.readMetadata(style)
|
loadedMetadata = archive.readMetadata(style)
|
||||||
|
|
||||||
lang = loadedMetadata.language
|
lang = loadedMetadata.language
|
||||||
if lang:
|
loadedMetadata.language = isoLanguages.get_lang3(lang)
|
||||||
if len(lang) == 2:
|
|
||||||
loadedMetadata.language = isoLanguages.get(part1=lang).name
|
|
||||||
elif len(lang) == 3:
|
|
||||||
loadedMetadata.language = isoLanguages.get(part3=lang).name
|
|
||||||
else:
|
|
||||||
loadedMetadata.language = ""
|
|
||||||
|
|
||||||
return BookMeta(
|
return BookMeta(
|
||||||
file_path=tmp_file_path,
|
file_path=tmp_file_path,
|
||||||
|
|
|
@ -393,7 +393,10 @@ def edit_book_comments(comments, book):
|
||||||
def edit_book_languages(languages, book, upload=False):
|
def edit_book_languages(languages, book, upload=False):
|
||||||
input_languages = languages.split(',')
|
input_languages = languages.split(',')
|
||||||
unknown_languages = []
|
unknown_languages = []
|
||||||
input_l = isoLanguages.get_language_codes(get_locale(), input_languages, unknown_languages)
|
if not upload:
|
||||||
|
input_l = isoLanguages.get_language_codes(get_locale(), input_languages, unknown_languages)
|
||||||
|
else:
|
||||||
|
input_l = isoLanguages.get_valid_language_codes(get_locale(), input_languages, unknown_languages)
|
||||||
for l in unknown_languages:
|
for l in unknown_languages:
|
||||||
log.error('%s is not a valid language', l)
|
log.error('%s is not a valid language', l)
|
||||||
flash(_(u"%(langname)s is not a valid language", langname=l), category="warning")
|
flash(_(u"%(langname)s is not a valid language", langname=l), category="warning")
|
||||||
|
|
13
cps/epub.py
13
cps/epub.py
|
@ -26,6 +26,7 @@ from .helper import split_authors
|
||||||
from .constants import BookMeta
|
from .constants import BookMeta
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def extractCover(zipFile, coverFile, coverpath, tmp_file_name):
|
def extractCover(zipFile, coverFile, coverpath, tmp_file_name):
|
||||||
if coverFile is None:
|
if coverFile is None:
|
||||||
return None
|
return None
|
||||||
|
@ -83,16 +84,8 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
|
||||||
else:
|
else:
|
||||||
epub_metadata['description'] = ""
|
epub_metadata['description'] = ""
|
||||||
|
|
||||||
if epub_metadata['language'] == u'Unknown':
|
lang = epub_metadata['language'].split('-', 1)[0].lower()
|
||||||
epub_metadata['language'] = ""
|
epub_metadata['language'] = isoLanguages.get_lang3(lang)
|
||||||
else:
|
|
||||||
lang = epub_metadata['language'].split('-', 1)[0].lower()
|
|
||||||
if len(lang) == 2:
|
|
||||||
epub_metadata['language'] = isoLanguages.get(part1=lang).name
|
|
||||||
elif len(lang) == 3:
|
|
||||||
epub_metadata['language'] = isoLanguages.get(part3=lang).name
|
|
||||||
else:
|
|
||||||
epub_metadata['language'] = ""
|
|
||||||
|
|
||||||
series = tree.xpath("/pkg:package/pkg:metadata/pkg:meta[@name='calibre:series']/@content", namespaces=ns)
|
series = tree.xpath("/pkg:package/pkg:metadata/pkg:meta[@name='calibre:series']/@content", namespaces=ns)
|
||||||
if len(series) > 0:
|
if len(series) > 0:
|
||||||
|
|
|
@ -43,7 +43,7 @@ log = logger.create()
|
||||||
try:
|
try:
|
||||||
from googleapiclient.errors import HttpError
|
from googleapiclient.errors import HttpError
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
log.debug(("Cannot import googleapiclient, using gdrive will not work: %s", err))
|
log.debug("Cannot import googleapiclient, using GDrive will not work: %s", err)
|
||||||
|
|
||||||
current_milli_time = lambda: int(round(time() * 1000))
|
current_milli_time = lambda: int(round(time() * 1000))
|
||||||
|
|
||||||
|
|
|
@ -66,3 +66,25 @@ def get_language_codes(locale, language_names, remainder=None):
|
||||||
if remainder is not None:
|
if remainder is not None:
|
||||||
remainder.extend(language_names)
|
remainder.extend(language_names)
|
||||||
return languages
|
return languages
|
||||||
|
|
||||||
|
def get_valid_language_codes(locale, language_names, remainder=None):
|
||||||
|
languages = list()
|
||||||
|
for k, v in get_language_names(locale).items():
|
||||||
|
if k in language_names:
|
||||||
|
languages.append(k)
|
||||||
|
language_names.remove(k)
|
||||||
|
if remainder is not None and len(language_names):
|
||||||
|
remainder.extend(language_names)
|
||||||
|
return languages
|
||||||
|
|
||||||
|
def get_lang3(lang):
|
||||||
|
try:
|
||||||
|
if len(lang) == 2:
|
||||||
|
ret_value = get(part1=lang).part3
|
||||||
|
elif len(lang) == 3:
|
||||||
|
ret_value = lang
|
||||||
|
else:
|
||||||
|
ret_value = ""
|
||||||
|
except KeyError:
|
||||||
|
ret_value = lang
|
||||||
|
return ret_value
|
||||||
|
|
Loading…
Reference in New Issue
Block a user