1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsCorePrerequisites.h"
6#include "Utility/BsModule.h"
7#include "Localization/BsStringTable.h"
8
9namespace bs
10{
11 /** @addtogroup Localization
12 * @{
13 */
14
15 /**
16 * Manages string tables used for localizing text. Allows you to add and remove different tables and change the active
17 * language.
18 */
19 class BS_CORE_EXPORT BS_SCRIPT_EXPORT(n:StringTables,m:Localization) StringTableManager : public Module<StringTableManager>
20 {
21 public:
22 StringTableManager() = default;
23
24 /** Determines the currently active language. Any newly created strings will use this value. */
25 BS_SCRIPT_EXPORT(n:ActiveLanguage,pr:setter)
26 void setActiveLanguage(Language language);
27
28 /** @copydoc setActiveLanguage() */
29 BS_SCRIPT_EXPORT(n:ActiveLanguage,pr:getter)
30 Language getActiveLanguage() const { return mActiveLanguage; }
31
32 /**
33 * Returns the string table with the specified id. If the table doesn't exist new one is created.
34 *
35 * @param[in] id Identifier of the string table.
36 * @return String table with the specified identifier.
37 */
38 BS_SCRIPT_EXPORT()
39 HStringTable getTable(UINT32 id);
40
41 /**
42 * Removes the string table with the specified id.
43 *
44 * @param[in] id Identifier of the string table.
45 */
46 BS_SCRIPT_EXPORT()
47 void removeTable(UINT32 id);
48
49 /**
50 * Registers a new string table or replaces an old one at the specified id.
51 *
52 * @param[in] id Identifier of the string table.
53 * @param[in] table New string table to assign to the specified identifier.
54 */
55 BS_SCRIPT_EXPORT()
56 void setTable(UINT32 id, const HStringTable& table);
57
58 private:
59 Language mActiveLanguage = StringTable::DEFAULT_LANGUAGE;
60 UnorderedMap<UINT32, HStringTable> mTables;
61 };
62
63 /** Provides easier access to StringTableManager. */
64 BS_CORE_EXPORT StringTableManager& gStringTableManager();
65
66 /** @} */
67}