Merge pull request #4687 from ruuk/textboxgettext
[vuplus_xbmc] / xbmc / guilib / LocalizeStrings.h
1 /*!
2 \file LocalizeStrings.h
3 \brief
4 */
5
6 #ifndef GUILIB_LOCALIZESTRINGS_H
7 #define GUILIB_LOCALIZESTRINGS_H
8
9 #pragma once
10
11 /*
12  *      Copyright (C) 2005-2013 Team XBMC
13  *      http://xbmc.org
14  *
15  *  This Program is free software; you can redistribute it and/or modify
16  *  it under the terms of the GNU General Public License as published by
17  *  the Free Software Foundation; either version 2, or (at your option)
18  *  any later version.
19  *
20  *  This Program is distributed in the hope that it will be useful,
21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  *  GNU General Public License for more details.
24  *
25  *  You should have received a copy of the GNU General Public License
26  *  along with XBMC; see the file COPYING.  If not, see
27  *  <http://www.gnu.org/licenses/>.
28  *
29  */
30
31 #include "utils/StdString.h"
32 #include "threads/CriticalSection.h"
33
34 #include <map>
35
36 /*!
37  \ingroup strings
38  \brief
39  */
40
41 struct LocStr
42 {
43 CStdString strTranslated; // string to be used in xbmc GUI
44 CStdString strOriginal;   // the original English string, the tranlsation is based on
45 };
46
47 // The default fallback language is fixed to be English
48 const CStdString SOURCE_LANGUAGE = "English";
49
50 class CLocalizeStrings
51 {
52 public:
53   CLocalizeStrings(void);
54   virtual ~CLocalizeStrings(void);
55   bool Load(const CStdString& strPathName, const CStdString& strLanguage);
56   bool LoadSkinStrings(const CStdString& path, const CStdString& language);
57   void ClearSkinStrings();
58   const CStdString& Get(uint32_t code) const;
59   void Clear();
60 protected:
61   void Clear(uint32_t start, uint32_t end);
62
63   /*! \brief Loads language ids and strings to memory map m_strings.
64    * It tries to load a strings.po file first. If doesn't exist, it loads a strings.xml file instead.
65    \param pathname The directory name, where we look for the strings file.
66    \param language We load the strings for this language. Fallback language is always English.
67    \param encoding Encoding of the strings. For PO files we only use utf-8.
68    \param offset An offset value to place strings from the id value.
69    \return false if no strings.po or strings.xml file was loaded.
70    */
71   bool LoadStr2Mem(const CStdString &pathname, const CStdString &language,
72                    CStdString &encoding, uint32_t offset = 0);
73
74   /*! \brief Tries to load ids and strings from a strings.po file to m_strings map.
75    * It should only be called from the LoadStr2Mem function to have a fallback.
76    \param pathname The directory name, where we look for the strings file.
77    \param encoding Encoding of the strings. For PO files we only use utf-8.
78    \param offset An offset value to place strings from the id value.
79    \param bSourceLanguage If we are loading the source English strings.po.
80    \return false if no strings.po file was loaded.
81    */
82   bool LoadPO(const CStdString &filename, CStdString &encoding, uint32_t offset = 0,
83               bool bSourceLanguage = false);
84
85   /*! \brief Tries to load ids and strings from a strings.xml file to m_strings map.
86    * It should only be called from the LoadStr2Mem function to try a PO file first.
87    \param pathname The directory name, where we look for the strings file.
88    \param encoding Encoding of the strings.
89    \param offset An offset value to place strings from the id value.
90    \return false if no strings.xml file was loaded.
91    */
92   bool LoadXML(const CStdString &filename, CStdString &encoding, uint32_t offset = 0);
93
94   static CStdString ToUTF8(const CStdString &encoding, const CStdString &str);
95   std::map<uint32_t, LocStr> m_strings;
96   typedef std::map<uint32_t, LocStr>::const_iterator ciStrings;
97   typedef std::map<uint32_t, LocStr>::iterator       iStrings;
98
99   CCriticalSection m_critSection;
100 };
101
102 /*!
103  \ingroup strings
104  \brief
105  */
106 extern CLocalizeStrings g_localizeStrings;
107 extern CLocalizeStrings g_localizeStringsTemp;
108 #endif