From 6d062f35009db472e58e58fb9a05f463fbbe49d7 Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Thu, 12 Sep 2024 20:33:22 -0400 Subject: [PATCH] Modified some language names to match those in Sonarr and Radarr. #2650 --- bazarr/languages/custom_lang.py | 27 +++++++++++++++++---------- bazarr/languages/get_languages.py | 9 ++++++++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/bazarr/languages/custom_lang.py b/bazarr/languages/custom_lang.py index bc50a4758..e6f3aa2f3 100644 --- a/bazarr/languages/custom_lang.py +++ b/bazarr/languages/custom_lang.py @@ -5,7 +5,8 @@ import os 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__) @@ -18,7 +19,7 @@ class CustomLanguage: language = "pt-BR" official_alpha2 = "pt" official_alpha3 = "por" - name = "Brazilian Portuguese" + name = "Portuguese (Brazil)" iso = "BR" _scripts = [] _possible_matches = ("pt-br", "pob", "pb", "brazilian", "brasil", "brazil") @@ -50,13 +51,19 @@ class CustomLanguage: """Register the custom language subclasses in the database.""" for sub in cls.__subclasses__(): - database.execute( - insert(table) - .values(code3=sub.alpha3, - code2=sub.alpha2, - name=sub.name, - enabled=0) - .on_conflict_do_nothing()) + try: + database.execute( + insert(table) + .values(code3=sub.alpha3, + code2=sub.alpha2, + name=sub.name, + enabled=0)) + except IntegrityError: + database.execute( + update(table) + .values(code2=sub.alpha2, + name=sub.name) + .where(table.code3 == sub.alpha3)) @classmethod def found_external(cls, subtitle, subtitle_path): @@ -212,7 +219,7 @@ class LatinAmericanSpanish(CustomLanguage): language = "es-MX" official_alpha2 = "es" official_alpha3 = "spa" - name = "Latin American Spanish" + name = "Spanish (Latino)" iso = "MX" # Not fair, but ok _scripts = ("419",) _possible_matches = ( diff --git a/bazarr/languages/get_languages.py b/bazarr/languages/get_languages.py index 89e2316d8..494343f6f 100644 --- a/bazarr/languages/get_languages.py +++ b/bazarr/languages/get_languages.py @@ -44,6 +44,12 @@ def create_languages_dict(): .values(name='Chinese Simplified') .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 = [{ 'code3': x.code3, 'code2': x.code2, @@ -54,10 +60,10 @@ def create_languages_dict(): TableSettingsLanguages.code3b)) .all()] + def audio_language_from_name(lang): lang_map = { 'Chinese': 'zh', - 'Portuguese (Brazil)': 'pb' } alpha2_code = lang_map.get(lang, None) @@ -67,6 +73,7 @@ def audio_language_from_name(lang): return language_from_alpha2(alpha2_code) + def language_from_alpha2(lang): return next((item['name'] for item in languages_dict if item['code2'] == lang[:2]), None)