Skip to content

Commit

Permalink
Merge pull request xbmc#980 from alanwww1/reuse-IDs
Browse files Browse the repository at this point in the history
[gettext] define use of the English string file, as the source language file
  • Loading branch information
alanwww1 committed May 18, 2012
2 parents a4ac911 + 02c2e53 commit 52f85ab
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 57 deletions.
16 changes: 6 additions & 10 deletions xbmc/Application.cpp
Expand Up @@ -741,11 +741,10 @@ bool CApplication::Create()
CLog::Log(LOGINFO, "load language info file: %s", strLangInfoPath.c_str()); CLog::Log(LOGINFO, "load language info file: %s", strLangInfoPath.c_str());
g_langInfo.Load(strLangInfoPath); g_langInfo.Load(strLangInfoPath);


CStdString strLanguagePath; CStdString strLanguagePath = "special://xbmc/language/";
strLanguagePath.Format("special://xbmc/language/%s", strLanguage.c_str());


CLog::Log(LOGINFO, "load language file from path: %s", strLanguagePath.c_str()); CLog::Log(LOGINFO, "load %s language file, from path: %s", strLanguage.c_str(), strLanguagePath.c_str());
if (!g_localizeStrings.Load(strLanguagePath)) if (!g_localizeStrings.Load(strLanguagePath, strLanguage))
FatalErrorHandler(false, false, true); FatalErrorHandler(false, false, true);


// start the AudioEngine // start the AudioEngine
Expand Down Expand Up @@ -1756,14 +1755,11 @@ void CApplication::LoadSkin(const SkinPtr& skin)
g_fontManager.LoadFonts(g_guiSettings.GetString("lookandfeel.font")); g_fontManager.LoadFonts(g_guiSettings.GetString("lookandfeel.font"));


// load in the skin strings // load in the skin strings
CStdString langPath, skinEnglishPath; CStdString langPath;
URIUtils::AddFileToFolder(skin->Path(), "language", langPath); URIUtils::AddFileToFolder(skin->Path(), "language", langPath);
URIUtils::AddFileToFolder(langPath, g_guiSettings.GetString("locale.language"), langPath); URIUtils::AddSlashAtEnd(langPath);


URIUtils::AddFileToFolder(skin->Path(), "language", skinEnglishPath); g_localizeStrings.LoadSkinStrings(langPath, g_guiSettings.GetString("locale.language"));
URIUtils::AddFileToFolder(skinEnglishPath, "English", skinEnglishPath);

g_localizeStrings.LoadSkinStrings(langPath, skinEnglishPath);


g_SkinInfo->LoadIncludes(); g_SkinInfo->LoadIncludes();


Expand Down
7 changes: 2 additions & 5 deletions xbmc/addons/Addon.cpp
Expand Up @@ -344,12 +344,9 @@ void CAddon::BuildLibName(const cp_extension_t *extension)
bool CAddon::LoadStrings() bool CAddon::LoadStrings()
{ {
// Path where the language strings reside // Path where the language strings reside
CStdString chosenPath; CStdString chosenPath = URIUtils::AddFileToFolder(m_props.path, "resources/language/");
chosenPath.Format("resources/language/%s", g_guiSettings.GetString("locale.language").c_str());
CStdString chosen = URIUtils::AddFileToFolder(m_props.path, chosenPath);
CStdString fallback = URIUtils::AddFileToFolder(m_props.path, "resources/language/English");


m_hasStrings = m_strings.Load(chosen, fallback); m_hasStrings = m_strings.Load(chosenPath, g_guiSettings.GetString("locale.language"));
return m_checkedStrings = true; return m_checkedStrings = true;
} }


Expand Down
44 changes: 21 additions & 23 deletions xbmc/guilib/LocalizeStrings.cpp
Expand Up @@ -55,28 +55,28 @@ void CLocalizeStrings::ClearSkinStrings()
Clear(31000, 31999); Clear(31000, 31999);
} }


bool CLocalizeStrings::LoadSkinStrings(const CStdString& path, const CStdString& fallbackPath) bool CLocalizeStrings::LoadSkinStrings(const CStdString& path, const CStdString& language)
{ {
ClearSkinStrings(); ClearSkinStrings();
// load the skin strings in. // load the skin strings in.
CStdString encoding; CStdString encoding;
if (!LoadStr2Mem(path, encoding)) if (!LoadStr2Mem(path, language, encoding))
{ {
if (path.Equals(fallbackPath)) // no fallback, nothing to do if (language.Equals(SOURCE_LANGUAGE)) // no fallback, nothing to do
return false; return false;
} }


// load the fallback // load the fallback
if (!path.Equals(fallbackPath)) if (!language.Equals(SOURCE_LANGUAGE))
LoadStr2Mem(fallbackPath, encoding); LoadStr2Mem(path, SOURCE_LANGUAGE, encoding);


return true; return true;
} }


bool CLocalizeStrings::LoadStr2Mem(const CStdString &pathname_in, CStdString &encoding, bool CLocalizeStrings::LoadStr2Mem(const CStdString &pathname_in, const CStdString &language,
uint32_t offset /* = 0 */) CStdString &encoding, uint32_t offset /* = 0 */)
{ {
CStdString pathname = CSpecialProtocol::TranslatePathConvertCase(pathname_in); CStdString pathname = CSpecialProtocol::TranslatePathConvertCase(pathname_in + language);
if (!XFILE::CDirectory::Exists(pathname)) if (!XFILE::CDirectory::Exists(pathname))
{ {
CLog::Log(LOGDEBUG, CLog::Log(LOGDEBUG,
Expand All @@ -85,10 +85,8 @@ bool CLocalizeStrings::LoadStr2Mem(const CStdString &pathname_in, CStdString &en
return false; return false;
} }


URIUtils::RemoveSlashAtEnd(pathname); if (LoadPO(URIUtils::AddFileToFolder(pathname, "strings.po"), encoding, offset,
bool bIsSourceLanguage = URIUtils::GetFileName(pathname).Equals("english");; language.Equals(SOURCE_LANGUAGE)))

if (LoadPO(URIUtils::AddFileToFolder(pathname, "strings.po"), encoding, offset, bIsSourceLanguage))
return true; return true;


CLog::Log(LOGDEBUG, "LocalizeStrings: no strings.po file exist at %s, fallback to strings.xml", CLog::Log(LOGDEBUG, "LocalizeStrings: no strings.po file exist at %s, fallback to strings.xml",
Expand Down Expand Up @@ -173,7 +171,7 @@ bool CLocalizeStrings::LoadXML(const CStdString &filename, CStdString &encoding,
const TiXmlElement *pChild = pRootElement->FirstChildElement("string"); const TiXmlElement *pChild = pRootElement->FirstChildElement("string");
while (pChild) while (pChild)
{ {
// Load new style language file with id as attribute // Load old style language file with id as attribute
const char* attrId=pChild->Attribute("id"); const char* attrId=pChild->Attribute("id");
if (attrId && !pChild->NoChildren()) if (attrId && !pChild->NoChildren())
{ {
Expand All @@ -186,24 +184,24 @@ bool CLocalizeStrings::LoadXML(const CStdString &filename, CStdString &encoding,
return true; return true;
} }


bool CLocalizeStrings::Load(const CStdString& strFileName, const CStdString& strFallbackFileName) bool CLocalizeStrings::Load(const CStdString& strPathName, const CStdString& strLanguage)
{ {
bool bLoadFallback = !strFileName.Equals(strFallbackFileName); bool bLoadFallback = !strLanguage.Equals(SOURCE_LANGUAGE);


CStdString encoding; CStdString encoding;
Clear(); Clear();


if (!LoadStr2Mem(strFileName, encoding)) if (!LoadStr2Mem(strPathName, strLanguage, encoding))
{ {
// try loading the fallback // try loading the fallback
if (!bLoadFallback || !LoadStr2Mem(strFallbackFileName, encoding)) if (!bLoadFallback || !LoadStr2Mem(strPathName, SOURCE_LANGUAGE, encoding))
return false; return false;


bLoadFallback = false; bLoadFallback = false;
} }


if (bLoadFallback) if (bLoadFallback)
LoadStr2Mem(strFallbackFileName, encoding); LoadStr2Mem(strPathName, SOURCE_LANGUAGE, encoding);


CStdString encoding_thisfile = "ISO-8859-1"; CStdString encoding_thisfile = "ISO-8859-1";
// we have ANSI encoding for LocalizeStrings.cpp therefore we need to use this encoding // we have ANSI encoding for LocalizeStrings.cpp therefore we need to use this encoding
Expand Down Expand Up @@ -265,7 +263,7 @@ void CLocalizeStrings::Clear(uint32_t start, uint32_t end)
} }
} }


uint32_t CLocalizeStrings::LoadBlock(const CStdString &id, const CStdString &path, const CStdString &fallbackPath) uint32_t CLocalizeStrings::LoadBlock(const CStdString &id, const CStdString &path, const CStdString &language)
{ {
iBlocks it = m_blocks.find(id); iBlocks it = m_blocks.find(id);
if (it != m_blocks.end()) if (it != m_blocks.end())
Expand All @@ -277,16 +275,16 @@ uint32_t CLocalizeStrings::LoadBlock(const CStdString &id, const CStdString &pat


// load the strings // load the strings
CStdString encoding; CStdString encoding;
bool success = LoadStr2Mem(path, encoding, offset); bool success = LoadStr2Mem(path, language, encoding, offset);
if (!success) if (!success)
{ {
if (path.Equals(fallbackPath)) // no fallback, nothing to do if (language.Equals(SOURCE_LANGUAGE)) // no fallback, nothing to do
return 0; return 0;
} }


// load the fallback // load the fallback
if (!path.Equals(fallbackPath)) if (!language.Equals(SOURCE_LANGUAGE))
success |= LoadStr2Mem(fallbackPath, encoding, offset); success |= LoadStr2Mem(path, SOURCE_LANGUAGE, encoding, offset);


return success ? offset : 0; return success ? offset : 0;
} }
Expand Down
17 changes: 11 additions & 6 deletions xbmc/guilib/LocalizeStrings.h
Expand Up @@ -40,33 +40,38 @@


struct LocStr struct LocStr
{ {
CStdString strTranslated; CStdString strTranslated; // string to be used in xbmc GUI
CStdString strOriginal; CStdString strOriginal; // the original English string, the tranlsation is based on
}; };


// The default fallback language is fixed to be English
const CStdString SOURCE_LANGUAGE = "English";

class CLocalizeStrings class CLocalizeStrings
{ {
public: public:
CLocalizeStrings(void); CLocalizeStrings(void);
virtual ~CLocalizeStrings(void); virtual ~CLocalizeStrings(void);
bool Load(const CStdString& strFileName, const CStdString& strFallbackFileName="special://xbmc/language/english"); bool Load(const CStdString& strPathName, const CStdString& strLanguage);
bool LoadSkinStrings(const CStdString& path, const CStdString& fallbackPath); bool LoadSkinStrings(const CStdString& path, const CStdString& language);
void ClearSkinStrings(); void ClearSkinStrings();
const CStdString& Get(uint32_t code) const; const CStdString& Get(uint32_t code) const;
void Clear(); void Clear();
uint32_t LoadBlock(const CStdString &id, const CStdString &path, const CStdString &fallbackPath); uint32_t LoadBlock(const CStdString &id, const CStdString &path, const CStdString &language);
void ClearBlock(const CStdString &id); void ClearBlock(const CStdString &id);
protected: protected:
void Clear(uint32_t start, uint32_t end); void Clear(uint32_t start, uint32_t end);


/*! \brief Loads language ids and strings to memory map m_strings. /*! \brief Loads language ids and strings to memory map m_strings.
* It tries to load a strings.po file first. If doesn't exist, it loads a strings.xml file instead. * It tries to load a strings.po file first. If doesn't exist, it loads a strings.xml file instead.
\param pathname The directory name, where we look for the strings file. \param pathname The directory name, where we look for the strings file.
\param language We load the strings for this language. Fallback language is always English.
\param encoding Encoding of the strings. For PO files we only use utf-8. \param encoding Encoding of the strings. For PO files we only use utf-8.
\param offset An offset value to place strings from the id value. \param offset An offset value to place strings from the id value.
\return false if no strings.po or strings.xml file was loaded. \return false if no strings.po or strings.xml file was loaded.
*/ */
bool LoadStr2Mem(const CStdString &pathname, CStdString &encoding, uint32_t offset = 0); bool LoadStr2Mem(const CStdString &pathname, const CStdString &language,
CStdString &encoding, uint32_t offset = 0);


/*! \brief Tries to load ids and strings from a strings.po file to m_strings map. /*! \brief Tries to load ids and strings from a strings.po file to m_strings map.
* It should only be called from the LoadStr2Mem function to have a fallback. * It should only be called from the LoadStr2Mem function to have a fallback.
Expand Down
8 changes: 2 additions & 6 deletions xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp
Expand Up @@ -440,16 +440,12 @@ unsigned int CGUIPythonWindowXML::LoadScriptStrings()
{ {
// Path where the language strings reside // Path where the language strings reside
CStdString pathToLanguageFile = m_scriptPath; CStdString pathToLanguageFile = m_scriptPath;
CStdString pathToFallbackLanguageFile = m_scriptPath;
URIUtils::AddFileToFolder(pathToLanguageFile, "resources", pathToLanguageFile); URIUtils::AddFileToFolder(pathToLanguageFile, "resources", pathToLanguageFile);
URIUtils::AddFileToFolder(pathToFallbackLanguageFile, "resources", pathToFallbackLanguageFile);
URIUtils::AddFileToFolder(pathToLanguageFile, "language", pathToLanguageFile); URIUtils::AddFileToFolder(pathToLanguageFile, "language", pathToLanguageFile);
URIUtils::AddFileToFolder(pathToFallbackLanguageFile, "language", pathToFallbackLanguageFile); URIUtils::AddSlashAtEnd(pathToLanguageFile);
URIUtils::AddFileToFolder(pathToLanguageFile, g_guiSettings.GetString("locale.language"), pathToLanguageFile);
URIUtils::AddFileToFolder(pathToFallbackLanguageFile, "english", pathToFallbackLanguageFile);


// allocate a bunch of strings // allocate a bunch of strings
return g_localizeStrings.LoadBlock(m_scriptPath, pathToLanguageFile, pathToFallbackLanguageFile); return g_localizeStrings.LoadBlock(m_scriptPath, pathToLanguageFile, g_guiSettings.GetString("locale.language"));
} }


void CGUIPythonWindowXML::ClearScriptStrings() void CGUIPythonWindowXML::ClearScriptStrings()
Expand Down
4 changes: 1 addition & 3 deletions xbmc/settings/GUISettings.cpp
Expand Up @@ -1464,9 +1464,7 @@ bool CGUISettings::SetLanguage(const CStdString &strLanguage)


g_charsetConverter.reset(); g_charsetConverter.reset();


CStdString strLanguagePath; if (!g_localizeStrings.Load("special://xbmc/language/", strNewLanguage))
strLanguagePath.Format("special://xbmc/language/%s", strNewLanguage.c_str());
if (!g_localizeStrings.Load(strLanguagePath))
return false; return false;


// also tell our weather and skin to reload as these are localized // also tell our weather and skin to reload as these are localized
Expand Down
5 changes: 1 addition & 4 deletions xbmc/settings/Settings.cpp
Expand Up @@ -941,11 +941,8 @@ bool CSettings::LoadProfile(unsigned int index)
CLog::Log(LOGINFO, "load language info file:%s", strLangInfoPath.c_str()); CLog::Log(LOGINFO, "load language info file:%s", strLangInfoPath.c_str());
g_langInfo.Load(strLangInfoPath); g_langInfo.Load(strLangInfoPath);


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

CButtonTranslator::GetInstance().Load(true); CButtonTranslator::GetInstance().Load(true);
g_localizeStrings.Load(strLanguagePath); g_localizeStrings.Load("special://xbmc/language/", strLanguage);


g_Mouse.SetEnabled(g_guiSettings.GetBool("input.enablemouse")); g_Mouse.SetEnabled(g_guiSettings.GetBool("input.enablemouse"));


Expand Down

0 comments on commit 52f85ab

Please sign in to comment.