Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python set language #183

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions xbmc/interfaces/python/xbmcmodule/xbmcmodule.cpp
Expand Up @@ -978,6 +978,24 @@ namespace PYXBMC

return Py_BuildValue((char*)"ss",strSize.c_str(), strHash.c_str());
}

// setLanguage function
PyDoc_STRVAR(setLanguage__doc__,
"setLanguage(language)\n"
"\n"
"language : string or unicode - Language string\n"
"\n"
"example:\n"
" xbmc.setLanguage('English')");

PyObject* XBMC_SetLanguage(PyObject *self, PyObject *args)
{
char *cLine = NULL;
if (!PyArg_ParseTuple(args, (char*)"s", &cLine)) return NULL;
g_guiSettings.ChangeLanguage(cLine);
Py_INCREF(Py_None);
return Py_None;
}

// define c functions to be used in python here
PyMethodDef xbmcMethods[] = {
Expand Down Expand Up @@ -1026,6 +1044,8 @@ namespace PYXBMC

{(char*)"skinHasImage", (PyCFunction)XBMC_SkinHasImage, METH_VARARGS|METH_KEYWORDS, skinHasImage__doc__},
{(char*)"subHashAndFileSize", (PyCFunction)XBMC_subHashAndFileSize, METH_VARARGS, subHashAndFileSize__doc__},

{(char*)"setLanguage", (PyCFunction)XBMC_SetLanguage, METH_VARARGS, setLanguage__doc__},

{NULL, NULL, 0, NULL}
};
Expand Down
21 changes: 21 additions & 0 deletions xbmc/settings/GUISettings.cpp
Expand Up @@ -40,6 +40,8 @@
#include "powermanagement/PowerManager.h"
#include "cores/dvdplayer/DVDCodecs/Video/CrystalHD.h"
#include "utils/PCMRemap.h"
#include "utils/Weather.h"
#include "LangInfo.h"
#include "guilib/GUIFont.h" // for FONT_STYLE_* definitions
#if defined(__APPLE__)
#include "osx/DarwinUtils.h"
Expand Down Expand Up @@ -1259,6 +1261,25 @@ void CGUISettings::Clear()
settingsGroups.clear();
}

void CGUISettings::ChangeLanguage(const CStdString &strLanguage)
{
CStdString strLangInfoPath;
strLangInfoPath.Format("special://xbmc/language/%s/langinfo.xml", strLanguage.c_str());
g_langInfo.Load(strLangInfoPath);

SetString("locale.language", strLanguage);

g_charsetConverter.reset();

CStdString strLanguagePath;
strLanguagePath.Format("special://xbmc/language/%s/strings.xml", strLanguage.c_str());
g_localizeStrings.Load(strLanguagePath);

// also tell our weather and skin to reload as these are localized
g_weatherManager.Refresh();
g_application.getApplicationMessenger().ExecBuiltIn("ReloadSkin");
}

float square_error(float x, float y)
{
float yonx = (x > 0) ? y / x : 0;
Expand Down
1 change: 1 addition & 0 deletions xbmc/settings/GUISettings.h
Expand Up @@ -483,6 +483,7 @@ class CGUISettings
ReplayGainSettings m_replayGain;

void Clear();
void ChangeLanguage(const CStdString &strLanguage);

private:
typedef std::map<CStdString, CSetting*>::iterator mapIter;
Expand Down
25 changes: 1 addition & 24 deletions xbmc/settings/GUIWindowSettingsCategory.cpp
Expand Up @@ -1508,30 +1508,7 @@ void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingC
CStdString strLanguage = pControl->GetCurrentLabel();
if (strLanguage != ".svn" && strLanguage != pSettingString->GetData())
{
CStdString strLangInfoPath;
strLangInfoPath.Format("special://xbmc/language/%s/langinfo.xml", strLanguage.c_str());
g_langInfo.Load(strLangInfoPath);

if (g_langInfo.ForceUnicodeFont() && !g_fontManager.IsFontSetUnicode())
{
CLog::Log(LOGINFO, "Language needs a ttf font, loading first ttf font available");
CStdString strFontSet;
if (g_fontManager.GetFirstFontSetUnicode(strFontSet))
strLanguage = strFontSet;
else
CLog::Log(LOGERROR, "No ttf font found but needed: %s", strFontSet.c_str());
}
g_guiSettings.SetString("locale.language", strLanguage);

g_charsetConverter.reset();

CStdString strLanguagePath;
strLanguagePath.Format("special://xbmc/language/%s/strings.xml", strLanguage.c_str());
g_localizeStrings.Load(strLanguagePath);

// also tell our weather and skin to reload as these are localized
g_weatherManager.Refresh();
g_application.ReloadSkin();
g_guiSettings.ChangeLanguage(strLanguage);
}
}
else if (strSetting.Equals("lookandfeel.skintheme"))
Expand Down