#include "LangInfo.h"
#include "Application.h"
+#include "ApplicationMessenger.h"
#include "FileItem.h"
#include "Util.h"
#include "filesystem/Directory.h"
#include "guilib/LocalizeStrings.h"
#include "pvr/PVRManager.h"
#include "settings/AdvancedSettings.h"
-#include "settings/Setting.h"
+#include "settings/lib/Setting.h"
#include "settings/Settings.h"
#include "utils/CharsetConverter.h"
#include "utils/log.h"
locale::global(current_locale);
#endif
+ g_charsetConverter.resetSystemCharset();
CLog::Log(LOGINFO, "global locale set to %s", strLocale.c_str());
}
}
}
-bool CLangInfo::Load(const CStdString& strFileName)
+bool CLangInfo::Load(const std::string& strFileName, bool onlyCheckLanguage /*= false*/)
{
SetDefaults();
CXBMCTinyXML xmlDoc;
if (!xmlDoc.LoadFile(strFileName))
{
- CLog::Log(LOGERROR, "unable to load %s: %s at line %d", strFileName.c_str(), xmlDoc.ErrorDesc(), xmlDoc.ErrorRow());
+ CLog::Log(onlyCheckLanguage ? LOGDEBUG : LOGERROR, "unable to load %s: %s at line %d", strFileName.c_str(), xmlDoc.ErrorDesc(), xmlDoc.ErrorRow());
return false;
}
TiXmlElement* pRootElement = xmlDoc.RootElement();
- CStdString strValue = pRootElement->Value();
- if (strValue != CStdString("language"))
+ if (pRootElement->ValueStr() != "language")
{
- CLog::Log(LOGERROR, "%s Doesn't contain <language>", strFileName.c_str());
+ CLog::Log(onlyCheckLanguage ? LOGDEBUG : LOGERROR, "%s Doesn't contain <language>", strFileName.c_str());
return false;
}
#else
if (m_defaultRegion.m_strLangLocaleName.length() != 3)
{
- if (!g_LangCodeExpander.ConvertToThreeCharCode(m_languageCodeGeneral, m_defaultRegion.m_strLangLocaleName))
+ if (!g_LangCodeExpander.ConvertToThreeCharCode(m_languageCodeGeneral, m_defaultRegion.m_strLangLocaleName, !onlyCheckLanguage))
m_languageCodeGeneral = "";
}
else
{
CRegion region(m_defaultRegion);
region.m_strName=pRegion->Attribute("name");
- if (region.m_strName.IsEmpty())
+ if (region.m_strName.empty())
region.m_strName="N/A";
if (pRegion->Attribute("locale"))
pRegion=pRegion->NextSiblingElement("region");
}
- const CStdString& strName=CSettings::Get().GetString("locale.country");
- SetCurrentRegion(strName);
+ if (!onlyCheckLanguage)
+ {
+ const CStdString& strName = CSettings::Get().GetString("locale.country");
+ SetCurrentRegion(strName);
+ }
}
+ g_charsetConverter.reinitCharsetsFromSettings();
- LoadTokens(pRootElement->FirstChild("sorttokens"),g_advancedSettings.m_vecTokens);
+ if (!onlyCheckLanguage)
+ LoadTokens(pRootElement->FirstChild("sorttokens"), g_advancedSettings.m_vecTokens);
return true;
}
+bool CLangInfo::CheckLanguage(const std::string& language)
+{
+ CLangInfo li;
+ return li.Load("special://xbmc/language/" + language + "/langinfo.xml", true);
+}
+
void CLangInfo::LoadTokens(const TiXmlNode* pTokens, vector<CStdString>& vecTokens)
{
if (pTokens && !pTokens->NoChildren())
strSep = pToken->Attribute("separators");
if (pToken->FirstChild() && pToken->FirstChild()->Value())
{
- if (strSep.IsEmpty())
+ if (strSep.empty())
vecTokens.push_back(pToken->FirstChild()->Value());
else
for (unsigned int i=0;i<strSep.size();++i)
bool CLangInfo::SetLanguage(const std::string &strLanguage)
{
string strLangInfoPath = StringUtils::Format("special://xbmc/language/%s/langinfo.xml", strLanguage.c_str());
- if (!g_langInfo.Load(strLangInfoPath))
+ if (!Load(strLangInfoPath))
return false;
if (ForceUnicodeFont() && !g_fontManager.IsFontSetUnicode())
CLog::Log(LOGERROR, "No ttf font found but needed: %s", strFontSet.c_str());
}
- g_charsetConverter.reset();
-
if (!g_localizeStrings.Load("special://xbmc/language/", strLanguage))
return false;
// also tell our weather and skin to reload as these are localized
g_weatherManager.Refresh();
g_PVRManager.LocalizationChanged();
- g_application.ReloadSkin();
+ CApplicationMessenger::Get().ExecBuiltIn("ReloadSkin", false);
return true;
}
+bool CLangInfo::CheckLoadLanguage(const std::string &language)
+{
+ return Load("special://xbmc/language/" + language + "/langinfo.xml", true);
+}
+
// three char language code (not win32 specific)
const CStdString& CLangInfo::GetAudioLanguage() const
{
return m_languageCodeGeneral;
}
-void CLangInfo::SetAudioLanguage(const CStdString &language)
+void CLangInfo::SetAudioLanguage(const std::string& language)
{
- if (language.empty() || !g_LangCodeExpander.ConvertToThreeCharCode(m_audioLanguage, language))
+ if (language.empty()
+ || StringUtils::EqualsNoCase(language, "default")
+ || StringUtils::EqualsNoCase(language, "original")
+ || !g_LangCodeExpander.ConvertToThreeCharCode(m_audioLanguage, language))
m_audioLanguage.clear();
}
return m_languageCodeGeneral;
}
-void CLangInfo::SetSubtitleLanguage(const CStdString &language)
+void CLangInfo::SetSubtitleLanguage(const std::string& language)
{
- if (language.empty() || !g_LangCodeExpander.ConvertToThreeCharCode(m_subtitleLanguage, language))
+ if (language.empty()
+ || StringUtils::EqualsNoCase(language, "default")
+ || StringUtils::EqualsNoCase(language, "original")
+ || !g_LangCodeExpander.ConvertToThreeCharCode(m_subtitleLanguage, language))
m_subtitleLanguage.clear();
}