Lookup the correct DCNC code to use for languages rather than just
authorCarl Hetherington <cth@carlh.net>
Sun, 17 Apr 2022 20:25:50 +0000 (22:25 +0200)
committerCarl Hetherington <cth@carlh.net>
Wed, 20 Apr 2022 20:31:08 +0000 (22:31 +0200)
using the language's subtag (#2235).

src/lib/film.cc
test/isdcf_name_test.cc

index 7cf67546ea1d504386289d579bea8e11322eb5e8..ef64a91d339d1d479999496477e63d727967950f 100644 (file)
@@ -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 {
index 28df9b2b933a6a9fc49274469b8b69da92b382ab..d3227f636ee5ba57d75e71ef40841d73dc1ae49e 100644 (file)
@@ -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");
 }