Skip to content

Commit

Permalink
adjust language loading/handling logic
Browse files Browse the repository at this point in the history
adjust all paths to language files (special://xbmc/language/...)
unify loading/changing language
add update/fallback for locale.language setting including matching an old language name to an installable language addon
move <charsets>, <dvd> and <sorttokens> from langinfo.xml to addon.xml
rename CLangInfo's GetLocale() to GetSystemLocale()
  • Loading branch information
Montellese committed Mar 6, 2015
1 parent bd56546 commit 66953bf
Show file tree
Hide file tree
Showing 19 changed files with 425 additions and 193 deletions.
12 changes: 11 additions & 1 deletion language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -12904,7 +12904,17 @@ msgctxt "#24132"
msgid "Would you like to switch to this language?"
msgstr ""

#empty strings from id 24133 to 24998
#: xbmc/Application.cpp
msgctxt "#24133"
msgid "Failed to load language"
msgstr ""

#: xbmc/Application.cpp
msgctxt "#24134"
msgid "We were unable to load your configured language. Please check your language settings."
msgstr ""

#empty strings from id 24135 to 24998

msgctxt "#24999"
msgid "Hide incompatible"
Expand Down
4 changes: 2 additions & 2 deletions system/settings/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<group id="1">
<setting id="locale.language" type="addon" label="248" help="36114">
<level>0</level>
<default>English</default>
<default>resource.language.en_gb</default>
<constraints>
<addontype>kodi.resource.language</addontype>
</constraints>
Expand Down Expand Up @@ -848,7 +848,7 @@
<level>1</level>
<default>English</default>
<constraints>
<options>languages</options>
<options>languagenames</options>
<delimiter>,</delimiter>
<minimumItems>1</minimumItems>
<maximumItems>3</maximumItems>
Expand Down
61 changes: 24 additions & 37 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "guilib/GUIColorManager.h"
#include "guilib/StereoscopicsManager.h"
#include "guilib/GUITextLayout.h"
#include "addons/LanguageResource.h"
#include "addons/Skin.h"
#include "interfaces/generic/ScriptInvocationManager.h"
#ifdef HAS_PYTHON
Expand Down Expand Up @@ -664,26 +665,6 @@ bool CApplication::Create()

update_emu_environ();//apply the GUI settings

// Load the langinfo to have user charset <-> utf-8 conversion
std::string strLanguage = CSettings::Get().GetString("locale.language");
strLanguage[0] = toupper(strLanguage[0]);

std::string strLangInfoPath = StringUtils::Format("special://xbmc/language/%s/langinfo.xml", strLanguage.c_str());

CLog::Log(LOGINFO, "load language info file: %s", strLangInfoPath.c_str());
g_langInfo.Load(strLangInfoPath);
g_langInfo.SetAudioLanguage(CSettings::Get().GetString("locale.audiolanguage"));
g_langInfo.SetSubtitleLanguage(CSettings::Get().GetString("locale.subtitlelanguage"));

std::string strLanguagePath = "special://xbmc/language/";

CLog::Log(LOGINFO, "load %s language file, from path: %s", strLanguage.c_str(), strLanguagePath.c_str());
if (!g_localizeStrings.Load(strLanguagePath, strLanguage))
{
CLog::LogF(LOGFATAL, "Failed to load %s language file, from path: %s", strLanguage.c_str(), strLanguagePath.c_str());
return false;
}

#ifdef TARGET_WINDOWS
CWIN32Util::SetThreadLocalLocale(true); // enable independent locale for each thread, see https://connect.microsoft.com/VisualStudio/feedback/details/794122
#endif // TARGET_WINDOWS
Expand Down Expand Up @@ -952,11 +933,11 @@ bool CApplication::InitDirectoriesLinux()
appPath = appBinPath;
/* Check if binaries and arch independent data files are being kept in
* separate locations. */
if (!CDirectory::Exists(URIUtils::AddFileToFolder(appPath, "language")))
if (!CDirectory::Exists(URIUtils::AddFileToFolder(appPath, "system")))
{
/* Attempt to locate arch independent data files. */
CUtil::GetHomePath(appPath);
if (!CDirectory::Exists(URIUtils::AddFileToFolder(appPath, "language")))
if (!CDirectory::Exists(URIUtils::AddFileToFolder(appPath, "system")))
{
fprintf(stderr, "Unable to find path to %s data files!\n", appName.c_str());
exit(1);
Expand Down Expand Up @@ -1162,11 +1143,15 @@ bool CApplication::Initialize()
if (!m_bPlatformDirectories)
#endif
{
CDirectory::Create("special://xbmc/language");
CDirectory::Create("special://xbmc/addons");
CDirectory::Create("special://xbmc/sounds");
}

// load the language and its translated strings
bool fallbackLanguage = false;
if (!LoadLanguage(false, fallbackLanguage))
return false;

// Load curl so curl_global_init gets called before any service threads
// are started. Unloading will have no effect as curl is never fully unloaded.
// To quote man curl_global_init:
Expand Down Expand Up @@ -1267,6 +1252,9 @@ bool CApplication::Initialize()
CPeripheralImon::GetCountOfImonsConflictWithDInput() == 0 );
#endif

if (fallbackLanguage)
CGUIDialogOK::ShowAndGetInput(24133, 24134);

// show info dialog about moved configuration files if needed
ShowAppMigrationMessage();

Expand Down Expand Up @@ -4895,23 +4883,22 @@ CPerformanceStats &CApplication::GetPerformanceStats()

bool CApplication::SetLanguage(const std::string &strLanguage)
{
std::string strPreviousLanguage = CSettings::Get().GetString("locale.language");
if (strLanguage != strPreviousLanguage)
{
std::string strLangInfoPath = StringUtils::Format("special://xbmc/language/%s/langinfo.xml", strLanguage.c_str());
if (!g_langInfo.Load(strLangInfoPath))
return false;
// nothing to be done if the language hasn't changed
if (strLanguage == CSettings::Get().GetString("locale.language"))
return true;

CSettings::Get().SetString("locale.language", strLanguage);
return CSettings::Get().SetString("locale.language", strLanguage);
}

if (!g_localizeStrings.Load("special://xbmc/language/", strLanguage))
return false;
bool CApplication::LoadLanguage(bool reload, bool& fallback)
{
// load the configured langauge
if (!g_langInfo.SetLanguage(fallback, "", reload))
return false;

// also tell our weather and skin to reload as these are localized
g_weatherManager.Refresh();
g_PVRManager.LocalizationChanged();
ReloadSkin();
}
// set the proper audio and subtitle languages
g_langInfo.SetAudioLanguage(CSettings::Get().GetString("locale.audiolanguage"));
g_langInfo.SetSubtitleLanguage(CSettings::Get().GetString("locale.subtitlelanguage"));

return true;
}
Expand Down
1 change: 1 addition & 0 deletions xbmc/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
bool GetRenderGUI() const { return m_renderGUI; };

bool SetLanguage(const std::string &strLanguage);
bool LoadLanguage(bool reload, bool& fallback);

ReplayGainSettings& GetReplayGainSettings() { return m_replayGainSettings; }

Expand Down
2 changes: 1 addition & 1 deletion xbmc/GUIInfoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,7 @@ std::string CGUIInfoManager::GetLabel(int info, int contextWindow, std::string *
}
break;
case SYSTEM_LANGUAGE:
strLabel = CSettings::Get().GetString("locale.language");
strLabel = g_langInfo.GetEnglishLanguageName();
break;
case SYSTEM_TEMPERATURE_UNITS:
strLabel = g_langInfo.GetTempUnitString();
Expand Down
Loading

0 comments on commit 66953bf

Please sign in to comment.