Skip to content
This repository
Browse code

Merge pull request #3375 from ace20022/langinfo

[Langinfo] Use preferred audio/subtitle language for dvds and blurays.
  • Loading branch information...
commit c3ff40f693d0bc07de0785581b52710bc83e7c4e 2 parents b4c32ba + b994301
Andreas Zelend authored October 09, 2013
35  xbmc/LangInfo.cpp
@@ -53,6 +53,7 @@ CLangInfo::CRegion::CRegion(const CRegion& region)
53 53
   m_strDVDAudioLanguage=region.m_strDVDAudioLanguage;
54 54
   m_strDVDSubtitleLanguage=region.m_strDVDSubtitleLanguage;
55 55
   m_strLangLocaleName = region.m_strLangLocaleName;
  56
+  m_strLangLocaleCodeTwoChar = region.m_strLangLocaleCodeTwoChar;
56 57
   m_strRegionLocaleName = region.m_strRegionLocaleName;
57 58
 
58 59
   m_strDateFormatShort=region.m_strDateFormatShort;
@@ -86,6 +87,7 @@ void CLangInfo::CRegion::SetDefaults()
86 87
   m_strDVDAudioLanguage="en";
87 88
   m_strDVDSubtitleLanguage="en";
88 89
   m_strLangLocaleName = "English";
  90
+  m_strLangLocaleCodeTwoChar = "en";
89 91
 
90 92
   m_strDateFormatShort="DD/MM/YYYY";
91 93
   m_strDateFormatLong="DDDD, D MMMM YYYY";
@@ -270,6 +272,10 @@ bool CLangInfo::Load(const CStdString& strFileName)
270 272
     m_languageCodeGeneral = m_defaultRegion.m_strLangLocaleName;
271 273
 #endif
272 274
 
  275
+  CStdString tmp;
  276
+  if (g_LangCodeExpander.ConvertToTwoCharCode(tmp, m_defaultRegion.m_strLangLocaleName))
  277
+    m_defaultRegion.m_strLangLocaleCodeTwoChar = tmp;
  278
+
273 279
   const TiXmlNode *pCharSets = pRootElement->FirstChild("charsets");
274 280
   if (pCharSets && !pCharSets->NoChildren())
275 281
   {
@@ -483,25 +489,40 @@ void CLangInfo::SetSubtitleLanguage(const CStdString &language)
483 489
 }
484 490
 
485 491
 // two character codes as defined in ISO639
486  
-const CStdString& CLangInfo::GetDVDMenuLanguage() const
  492
+const std::string CLangInfo::GetDVDMenuLanguage() const
487 493
 {
488  
-  return m_currentRegion->m_strDVDMenuLanguage;
  494
+  CStdString code;
  495
+  if (!g_LangCodeExpander.ConvertToTwoCharCode(code, m_currentRegion->m_strLangLocaleName))
  496
+    code = m_currentRegion->m_strDVDMenuLanguage;
  497
+  
  498
+  return code;
489 499
 }
490 500
 
491 501
 // two character codes as defined in ISO639
492  
-const CStdString& CLangInfo::GetDVDAudioLanguage() const
  502
+const std::string CLangInfo::GetDVDAudioLanguage() const
493 503
 {
494  
-  return m_currentRegion->m_strDVDAudioLanguage;
  504
+  CStdString code;
  505
+  if (!g_LangCodeExpander.ConvertToTwoCharCode(code, m_audioLanguage))
  506
+    code = m_currentRegion->m_strDVDAudioLanguage;
  507
+  
  508
+  return code;
495 509
 }
496 510
 
497 511
 // two character codes as defined in ISO639
498  
-const CStdString& CLangInfo::GetDVDSubtitleLanguage() const
  512
+const std::string CLangInfo::GetDVDSubtitleLanguage() const
499 513
 {
500  
-  return m_currentRegion->m_strDVDSubtitleLanguage;
  514
+  CStdString code;
  515
+  if (!g_LangCodeExpander.ConvertToTwoCharCode(code, m_subtitleLanguage))
  516
+    code = m_currentRegion->m_strDVDSubtitleLanguage;
  517
+  
  518
+  return code;
501 519
 }
502 520
 
503  
-const CStdString& CLangInfo::GetLanguageLocale() const
  521
+const std::string CLangInfo::GetLanguageLocale(bool twochar /* = false */) const
504 522
 {
  523
+  if (twochar)
  524
+    return m_currentRegion->m_strLangLocaleCodeTwoChar;
  525
+
505 526
   return m_currentRegion->m_strLangLocaleName;
506 527
 }
507 528
 
9  xbmc/LangInfo.h
@@ -57,13 +57,13 @@ class CLangInfo : public ISettingCallback
57 57
   // or a language name in english (as used by XBMC)
58 58
   void SetSubtitleLanguage(const CStdString &language);
59 59
 
60  
-  const CStdString& GetDVDMenuLanguage() const;
61  
-  const CStdString& GetDVDAudioLanguage() const;
62  
-  const CStdString& GetDVDSubtitleLanguage() const;
  60
+  const std::string GetDVDMenuLanguage() const;
  61
+  const std::string GetDVDAudioLanguage() const;
  62
+  const std::string GetDVDSubtitleLanguage() const;
63 63
   const CStdString& GetTimeZone() const;
64 64
 
65 65
   const CStdString& GetRegionLocale() const;
66  
-  const CStdString& GetLanguageLocale() const;
  66
+  const std::string GetLanguageLocale(bool twochar = false) const;
67 67
 
68 68
   bool ForceUnicodeFont() const { return m_currentRegion->m_forceUnicodeFont; }
69 69
 
@@ -144,6 +144,7 @@ class CLangInfo : public ISettingCallback
144 144
     CStdString m_strDVDAudioLanguage;
145 145
     CStdString m_strDVDSubtitleLanguage;
146 146
     CStdString m_strLangLocaleName;
  147
+    std::string m_strLangLocaleCodeTwoChar;
147 148
     CStdString m_strRegionLocaleName;
148 149
     bool m_forceUnicodeFont;
149 150
     CStdString m_strName;
2  xbmc/addons/AddonManager.cpp
@@ -587,7 +587,7 @@ const char *CAddonMgr::GetTranslatedString(const cp_cfg_element_t *root, const c
587 587
     if (strcmp(tag, child.name) == 0)
588 588
     { // see if we have a "lang" attribute
589 589
       const char *lang = m_cpluff->lookup_cfg_value((cp_cfg_element_t*)&child, "@lang");
590  
-      if (lang && 0 == strcmp(lang,g_langInfo.GetDVDAudioLanguage().c_str()))
  590
+      if (lang && 0 == strcmp(lang,g_langInfo.GetLanguageLocale(true).c_str()))
591 591
         return child.value;
592 592
       if (!lang || 0 == strcmp(lang, "en"))
593 593
         eng = &child;

0 notes on commit c3ff40f

Please sign in to comment.
Something went wrong with that request. Please try again.