Modified some language names to match those in Sonarr and Radarr. #2650

pull/2658/head v1.4.4-beta.45
morpheus65535 2 months ago
parent 10d475e81e
commit 6d062f3500

@ -5,7 +5,8 @@ import os
from subzero.language import Language from subzero.language import Language
from app.database import database, insert from app.database import database, insert, update
from sqlalchemy.exc import IntegrityError
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -18,7 +19,7 @@ class CustomLanguage:
language = "pt-BR" language = "pt-BR"
official_alpha2 = "pt" official_alpha2 = "pt"
official_alpha3 = "por" official_alpha3 = "por"
name = "Brazilian Portuguese" name = "Portuguese (Brazil)"
iso = "BR" iso = "BR"
_scripts = [] _scripts = []
_possible_matches = ("pt-br", "pob", "pb", "brazilian", "brasil", "brazil") _possible_matches = ("pt-br", "pob", "pb", "brazilian", "brasil", "brazil")
@ -50,13 +51,19 @@ class CustomLanguage:
"""Register the custom language subclasses in the database.""" """Register the custom language subclasses in the database."""
for sub in cls.__subclasses__(): for sub in cls.__subclasses__():
try:
database.execute( database.execute(
insert(table) insert(table)
.values(code3=sub.alpha3, .values(code3=sub.alpha3,
code2=sub.alpha2, code2=sub.alpha2,
name=sub.name, name=sub.name,
enabled=0) enabled=0))
.on_conflict_do_nothing()) except IntegrityError:
database.execute(
update(table)
.values(code2=sub.alpha2,
name=sub.name)
.where(table.code3 == sub.alpha3))
@classmethod @classmethod
def found_external(cls, subtitle, subtitle_path): def found_external(cls, subtitle, subtitle_path):
@ -212,7 +219,7 @@ class LatinAmericanSpanish(CustomLanguage):
language = "es-MX" language = "es-MX"
official_alpha2 = "es" official_alpha2 = "es"
official_alpha3 = "spa" official_alpha3 = "spa"
name = "Latin American Spanish" name = "Spanish (Latino)"
iso = "MX" # Not fair, but ok iso = "MX" # Not fair, but ok
_scripts = ("419",) _scripts = ("419",)
_possible_matches = ( _possible_matches = (

@ -44,6 +44,12 @@ def create_languages_dict():
.values(name='Chinese Simplified') .values(name='Chinese Simplified')
.where(TableSettingsLanguages.code3 == 'zho')) .where(TableSettingsLanguages.code3 == 'zho'))
# replace Modern Greek by Greek to match Sonarr and Radarr languages
database.execute(
update(TableSettingsLanguages)
.values(name='Greek')
.where(TableSettingsLanguages.code3 == 'ell'))
languages_dict = [{ languages_dict = [{
'code3': x.code3, 'code3': x.code3,
'code2': x.code2, 'code2': x.code2,
@ -54,10 +60,10 @@ def create_languages_dict():
TableSettingsLanguages.code3b)) TableSettingsLanguages.code3b))
.all()] .all()]
def audio_language_from_name(lang): def audio_language_from_name(lang):
lang_map = { lang_map = {
'Chinese': 'zh', 'Chinese': 'zh',
'Portuguese (Brazil)': 'pb'
} }
alpha2_code = lang_map.get(lang, None) alpha2_code = lang_map.get(lang, None)
@ -67,6 +73,7 @@ def audio_language_from_name(lang):
return language_from_alpha2(alpha2_code) return language_from_alpha2(alpha2_code)
def language_from_alpha2(lang): def language_from_alpha2(lang):
return next((item['name'] for item in languages_dict if item['code2'] == lang[:2]), None) return next((item['name'] for item in languages_dict if item['code2'] == lang[:2]), None)

Loading…
Cancel
Save