Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Python set language #183

Closed
wants to merge 2 commits into from

1 participant

@amet

added xbmc.setLanguage() to xbmcmodule.cpp. it allows the xbmc language to be set from python addon.

on JMs advice, I have created CGUISettings::ChangeLanguage so that the code wouldn't be duplicated

any objections to this? If not I will commit this in a few days

@ghost

why?

@amet

cos I had it done, it might be useful to make a first run wizard in a future

@ghost

then i suggest we leave it around until it is of use.

@amet

all the same to me

@amet amet closed this
@opdenkamp opdenkamp referenced this pull request from a commit
@opdenkamp opdenkamp pvr: don't wait for ApplicationMessenger::MediaStop() to finish in CD…
…VDPlayer::HandleMessages() or it'll cause a deadlock. closes #183
43b3689
@tru tru referenced this pull request from a commit in plexinc/plex-home-theater-public
@tru tru Support for background music
Fixes #183

userdata/BackgroundMusic/
23c4243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
20 xbmc/interfaces/python/xbmcmodule/xbmcmodule.cpp
@@ -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[] = {
@@ -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}
};
View
21 xbmc/settings/GUISettings.cpp
@@ -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"
@@ -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;
View
1  xbmc/settings/GUISettings.h
@@ -483,6 +483,7 @@ class CGUISettings
ReplayGainSettings m_replayGain;
void Clear();
+ void ChangeLanguage(const CStdString &strLanguage);
private:
typedef std::map<CStdString, CSetting*>::iterator mapIter;
View
25 xbmc/settings/GUIWindowSettingsCategory.cpp
@@ -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"))
Something went wrong with that request. Please try again.