Skip to content

Commit

Permalink
Add "Audio Language" selection
Browse files Browse the repository at this point in the history
Add a selection for the preferred audio language.
The existing "Language" setting is used for the menu language
but was until this fix also used as preferred audio language.
When there is no "Audio Language" preference specified
then the "Language" setting is used so users do not need
to configure anything to keep the current behavior.
Note that TVs sold in Europe generally have separate
settings for "Menu Language" and "Audio Language".
  • Loading branch information
kmdewaal committed Feb 10, 2024
1 parent e2a33a2 commit 84b1140
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 8 deletions.
35 changes: 35 additions & 0 deletions mythtv/libs/libmythbase/mythcorecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class MythCoreContextPrivate : public QObject

MythLocale *m_locale { nullptr };
QString m_language;
QString m_audioLanguage;

MythScheduler *m_scheduler { nullptr };

Expand Down Expand Up @@ -1792,6 +1793,40 @@ void MythCoreContext::ResetLanguage(void)
d->m_language.clear();
}

/**
* \brief Returns two character ISO-639 language descriptor for audio language.
* \sa iso639_get_language_list()
*/
QString MythCoreContext::GetAudioLanguage(void)
{
return GetAudioLanguageAndVariant().left(2);
}

/**
* \brief Returns the user-set audio language and variant.
*
* The string has the form ll or ll_vv, where ll is the two character
* ISO-639 language code, and vv (which may not exist) is the variant.
* Examples include en_AU, en_CA, en_GB, en_US, fr_CH, fr_DE, pt_BR, pt_PT.
*/
QString MythCoreContext::GetAudioLanguageAndVariant(void)
{
if (d->m_audioLanguage.isEmpty())
{
auto menuLanguage = GetLanguageAndVariant();
d->m_audioLanguage = GetSetting("AudioLanguage", menuLanguage).toLower();

LOG(VB_AUDIO, LOG_DEBUG, LOC + QString("audio language:%1 menu language:%2")
.arg(d->m_audioLanguage).arg(menuLanguage));
}
return d->m_audioLanguage;
}

void MythCoreContext::ResetAudioLanguage(void)
{
d->m_audioLanguage.clear();
}

void MythCoreContext::ResetSockets(void)
{
QMutexLocker locker(&d->m_sockLock);
Expand Down
3 changes: 3 additions & 0 deletions mythtv/libs/libmythbase/mythcorecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ class MBASE_PUBLIC MythCoreContext : public QObject, public MythObservable, publ
QString GetLanguage(void);
QString GetLanguageAndVariant(void);
void ResetLanguage(void);
QString GetAudioLanguage(void);
QString GetAudioLanguageAndVariant(void);
void ResetAudioLanguage(void);
void ResetSockets(void);

using PlaybackStartCb = void (QObject::*)(void);
Expand Down
14 changes: 7 additions & 7 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4394,8 +4394,8 @@ int AvFormatDecoder::AutoSelectAudioTrack(void)
ftype.push_back(i);
}

// try to get the language track matching the frontend language.
QString language_key_convert = iso639_str2_to_str3(gCoreContext->GetLanguage());
// Try to get the language track for the preferred language for audio
QString language_key_convert = iso639_str2_to_str3(gCoreContext->GetAudioLanguage());
uint language_key = iso639_str3_to_key(language_key_convert);
uint canonical_key = iso639_key_to_canonical_key(language_key);

Expand All @@ -4422,8 +4422,8 @@ int AvFormatDecoder::AutoSelectAudioTrack(void)
if (selTrack < 0)
selTrack = filter_max_ch(m_ic, atracks, flang);

// try to get best track for most preferred language
// Set by the "Guide Data" language prefs in Appearance.
// Try to get best track for most preferred language for audio.
// Set by the "Guide Data" "Audio Language" preference in Appearance.
if (selTrack < 0)
{
auto it = m_languagePreference.begin();
Expand Down Expand Up @@ -4457,8 +4457,8 @@ int AvFormatDecoder::AutoSelectAudioTrack(void)
}
}

// could not select track based on user preferences (language)
// try to select the default track
// Could not select track based on user preferences (audio language)
// Try to select the default track
if (selTrack < 0)
{
LOG(VB_AUDIO, LOG_INFO, LOC + "Trying to select default track");
Expand All @@ -4472,7 +4472,7 @@ int AvFormatDecoder::AutoSelectAudioTrack(void)
}
}

// try to get best track for any language
// Try to get best track for any language
if (selTrack < 0)
{
LOG(VB_AUDIO, LOG_INFO, LOC +
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ bool MythMainWindow::event(QEvent *Event)
void MythMainWindow::LoadQtConfig()
{
gCoreContext->ResetLanguage();
gCoreContext->ResetAudioLanguage();
GetMythUI()->ClearThemeCacheDir();
QApplication::setStyle("Windows");
}
Expand Down
33 changes: 32 additions & 1 deletion mythtv/programs/mythfrontend/globalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3214,7 +3214,7 @@ static GlobalComboBoxSetting *MythLanguage()
{
auto *gc = new GlobalComboBoxSetting("Language");

gc->setLabel(AppearanceSettings::tr("Language"));
gc->setLabel(AppearanceSettings::tr("Menu Language"));

QMap<QString, QString> langMap = MythTranslation::getLanguages();
QStringList langs = langMap.values();
Expand All @@ -3237,6 +3237,36 @@ static GlobalComboBoxSetting *MythLanguage()
return gc;
}

static GlobalComboBoxSetting *AudioLanguage()
{
auto *gc = new GlobalComboBoxSetting("AudioLanguage");

gc->setLabel(AppearanceSettings::tr("Audio Language"));

QMap<QString, QString> langMap = MythTranslation::getLanguages();
QStringList langs = langMap.values();
langs.sort();
QString langCode = gCoreContext->GetSetting("AudioLanguage").toLower();

if (langCode.isEmpty())
{
auto menuLangCode = gCoreContext->GetSetting("Language").toLower();
langCode = menuLangCode.isEmpty() ? "en_US" : menuLangCode;
}

gc->clearSelections();

for (const auto & label : qAsConst(langs))
{
QString value = langMap.key(label);
gc->addSelection(label, value, (value.toLower() == langCode));
}

gc->setHelpText(AppearanceSettings::tr("Preferred language for the "
"audio track."));
return gc;
}

static void ISO639_fill_selections(MythUIComboBoxSetting *widget, uint i)
{
widget->clearSelections();
Expand Down Expand Up @@ -4784,6 +4814,7 @@ AppearanceSettings::AppearanceSettings()
dates->setLabel(tr("Localization"));

dates->addChild(MythLanguage());
dates->addChild(AudioLanguage());
dates->addChild(ISO639PreferredLanguage(0));
dates->addChild(ISO639PreferredLanguage(1));
dates->addChild(MythDateFormatCB());
Expand Down

0 comments on commit 84b1140

Please sign in to comment.