Merge pull request #2948 from ace20022/blu_lang_fix
[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://www.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   uint32_t LoadBlock(const CStdString &id, const CStdString &path, const CStdString &language);
61   void ClearBlock(const CStdString &id);
62 protected:
63   void Clear(uint32_t start, uint32_t end);
64
65   /*! \brief Loads language ids and strings to memory map m_strings.
66    * It tries to load a strings.po file first. If doesn't exist, it loads a strings.xml file instead.
67    \param pathname The directory name, where we look for the strings file.
68    \param language We load the strings for this language. Fallback language is always English.
69    \param encoding Encoding of the strings. For PO files we only use utf-8.
70    \param offset An offset value to place strings from the id value.
71    \return false if no strings.po or strings.xml file was loaded.
72    */
73   bool LoadStr2Mem(const CStdString &pathname, const CStdString &language,
74                    CStdString &encoding, uint32_t offset = 0);
75
76   /*! \brief Tries to load ids and strings from a strings.po file to m_strings map.
77    * It should only be called from the LoadStr2Mem function to have a fallback.
78    \param pathname The directory name, where we look for the strings file.
79    \param encoding Encoding of the strings. For PO files we only use utf-8.
80    \param offset An offset value to place strings from the id value.
81    \param bSourceLanguage If we are loading the source English strings.po.
82    \return false if no strings.po file was loaded.
83    */
84   bool LoadPO(const CStdString &filename, CStdString &encoding, uint32_t offset = 0,
85               bool bSourceLanguage = false);
86
87   /*! \brief Tries to load ids and strings from a strings.xml file to m_strings map.
88    * It should only be called from the LoadStr2Mem function to try a PO file first.
89    \param pathname The directory name, where we look for the strings file.
90    \param encoding Encoding of the strings.
91    \param offset An offset value to place strings from the id value.
92    \return false if no strings.xml file was loaded.
93    */
94   bool LoadXML(const CStdString &filename, CStdString &encoding, uint32_t offset = 0);
95
96   CStdString ToUTF8(const CStdString &encoding, const CStdString &str);
97   std::map<uint32_t, LocStr> m_strings;
98   typedef std::map<uint32_t, LocStr>::const_iterator ciStrings;
99   typedef std::map<uint32_t, LocStr>::iterator       iStrings;
100
101   static const uint32_t block_start = 0xf000000;
102   static const uint32_t block_size = 4096;
103   std::map<CStdString, uint32_t> m_blocks;
104   typedef std::map<CStdString, uint32_t>::iterator iBlocks;
105   CCriticalSection m_critSection;
106 };
107
108 /*!
109  \ingroup strings
110  \brief
111  */
112 extern CLocalizeStrings g_localizeStrings;
113 extern CLocalizeStrings g_localizeStringsTemp;
114 #endif