1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "ags/shared/ac/common.h"
24 #include "ags/engine/ac/display.h"
25 #include "ags/engine/ac/game_state.h"
26 #include "ags/engine/ac/global_translation.h"
27 #include "ags/engine/ac/string.h"
28 #include "ags/engine/ac/translation.h"
29 #include "ags/engine/platform/base/ags_platform_driver.h"
30 #include "ags/plugins/ags_plugin.h"
31 #include "ags/plugins/plugin_engine.h"
32 #include "ags/shared/util/memory.h"
33 #include "ags/engine/ac/string.h"
34 #include "ags/globals.h"
35
36 namespace AGS3 {
37
38 using namespace AGS::Shared::Memory;
39
get_translation(const char * text)40 const char *get_translation(const char *text) {
41 if (text == nullptr)
42 quit("!Null string supplied to CheckForTranslations");
43
44 _G(source_text_length) = GetTextDisplayLength(text);
45
46 #if AGS_PLATFORM_64BIT
47 // check if a plugin wants to translate it - if so, return that
48 // TODO: plugin API is currently strictly 32-bit, so this may break on 64-bit systems
49 char *plResult = Int32ToPtr<char>(pl_run_plugin_hooks(AGSE_TRANSLATETEXT, PtrToInt32(text)));
50 if (plResult) {
51 return plResult;
52 }
53 #endif
54
55 const auto &transtree = get_translation_tree();
56 const auto it = transtree.find(text);
57 if (it != transtree.end())
58 return it->_value.GetCStr();
59
60 // return the original text
61 return text;
62 }
63
IsTranslationAvailable()64 int IsTranslationAvailable() {
65 if (get_translation_tree().size() > 0)
66 return 1;
67 return 0;
68 }
69
GetTranslationName(char * buffer)70 int GetTranslationName(char *buffer) {
71 VALIDATE_STRING(buffer);
72 strcpy(buffer, get_translation_name().GetCStr());
73 return IsTranslationAvailable();
74 }
75
76 } // namespace AGS3
77