1 /*
2  *  Copyright (C) 2005-2018 Team Kodi
3  *  This file is part of Kodi - https://kodi.tv
4  *
5  *  SPDX-License-Identifier: GPL-2.0-or-later
6  *  See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 /*!
12 \file LocalizeStrings.h
13 \brief
14 */
15 
16 #include "threads/SharedSection.h"
17 #include "utils/ILocalizer.h"
18 
19 #include <map>
20 #include <stdint.h>
21 #include <string>
22 
23 /*!
24  \ingroup strings
25  \brief
26  */
27 
28 struct LocStr
29 {
30   std::string strTranslated; // string to be used in xbmc GUI
31   std::string strOriginal;   // the original English string the translation is based on
32 };
33 
34 // The default fallback language is fixed to be English
35 const std::string LANGUAGE_DEFAULT = "resource.language.en_gb";
36 const std::string LANGUAGE_OLD_DEFAULT = "English";
37 
38 class CLocalizeStrings : public ILocalizer
39 {
40 public:
41   CLocalizeStrings(void);
42   ~CLocalizeStrings(void) override;
43   bool Load(const std::string& strPathName, const std::string& strLanguage);
44   bool LoadSkinStrings(const std::string& path, const std::string& language);
45   bool LoadAddonStrings(const std::string& path, const std::string& language, const std::string& addonId);
46   void ClearSkinStrings();
47   const std::string& Get(uint32_t code) const;
48   std::string GetAddonString(const std::string& addonId, uint32_t code);
49   void Clear();
50 
51   // implementation of ILocalizer
Localize(std::uint32_t code)52   std::string Localize(std::uint32_t code) const override { return Get(code); }
53 
54 protected:
55   void Clear(uint32_t start, uint32_t end);
56 
57   std::map<uint32_t, LocStr> m_strings;
58   std::map<std::string, std::map<uint32_t, LocStr>> m_addonStrings;
59   typedef std::map<uint32_t, LocStr>::const_iterator ciStrings;
60   typedef std::map<uint32_t, LocStr>::iterator       iStrings;
61 
62   mutable CSharedSection m_stringsMutex;
63   CSharedSection m_addonStringsMutex;
64 };
65 
66 /*!
67  \ingroup strings
68  \brief
69  */
70 extern CLocalizeStrings g_localizeStrings;
71 extern CLocalizeStrings g_localizeStringsTemp;
72 
73