From e6d7b6d8520c7454ecf67df7269056a16d0e2b70 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 17 Apr 2022 22:25:50 +0200 Subject: [PATCH] Lookup the correct DCNC code to use for languages rather than just using the language's subtag (#2235). --- src/lib/film.cc | 15 +++++++++++++-- test/isdcf_name_test.cc | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib/film.cc b/src/lib/film.cc index 7cf67546e..ef64a91d3 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -915,7 +915,18 @@ Film::isdcf_name (bool if_created_now) const } } - auto audio_language = (_audio_language && _audio_language->language()) ? _audio_language->language()->subtag() : "XX"; + auto entry_for_language = [](dcp::LanguageTag const& tag) { + /* Look up what we should be using for this tag in the DCNC name */ + for (auto const& dcnc: dcp::dcnc_tags()) { + if (tag.to_string() == dcnc.first) { + return dcnc.second; + } + } + /* Fallback to the language subtag, if there is one */ + return tag.language() ? tag.language()->subtag() : "XX"; + }; + + auto audio_language = _audio_language ? entry_for_language(*_audio_language) : "XX"; d += "_" + to_upper (audio_language); @@ -937,7 +948,7 @@ Film::isdcf_name (bool if_created_now) const auto sub_langs = subtitle_languages(); if (sub_langs.first && sub_langs.first->language()) { - auto lang = sub_langs.first->language()->subtag(); + auto lang = entry_for_language(*sub_langs.first); if (burnt_in) { transform (lang.begin(), lang.end(), lang.begin(), ::tolower); } else { diff --git a/test/isdcf_name_test.cc b/test/isdcf_name_test.cc index 28df9b2b9..d3227f636 100644 --- a/test/isdcf_name_test.cc +++ b/test/isdcf_name_test.cc @@ -230,5 +230,9 @@ BOOST_AUTO_TEST_CASE (isdcf_name_test) mapping.set (0, dcp::Channel::VI, 1.0); sound->audio->set_mapping (mapping); BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_DE-fr_US-R_71-HI-VI_4K_DI_20140704_PPF_SMPTE_OV"); + + /* Check that the proper codes are used, not just part of the language code; in this case, QBP instead of PT (#2235) */ + film->set_audio_language(dcp::LanguageTag("pt-BR")); + BOOST_CHECK_EQUAL (film->isdcf_name(false), "LikeShouting_XSN-2_F-133_QBP-fr_US-R_71-HI-VI_4K_DI_20140704_PPF_SMPTE_OV"); } -- 2.30.2