forked from CasualCoderGuy/FO4-ModSwitchFramework-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSF_Localization.cpp
More file actions
130 lines (111 loc) · 4.38 KB
/
MSF_Localization.cpp
File metadata and controls
130 lines (111 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "MSF_Localization.h"
#include "MSF_Data.h"
#include "f4se\GameSettings.h"
#include "f4se\GameStreams.h"
#include <comdef.h>
namespace MSF_Localization
{
std::string Keys::modText = "$MOD_AT_WORKBENCH";
std::string Keys::noAPText = "$NO_ATTACHPOINT";
std::string Keys::noWeapText = "$NO_WEAPON";
std::string Keys::couldntAttachText = "$COULD_NOT_ATTACH";
std::string Keys::itemText = "$CANNOT_EQUIP";
std::string Keys::unsupportedAmmoText = "$CANNOT_EQUIP_NP_AMMO";
std::string Keys::noAmmoTypeText = "$CANNOT_EQUIP_AMMOTYPE";
std::string Keys::ammoEquipFailedText = "$CANNOT_EQUIP_AMMO_RN";
std::string Keys::ammoUnequipText = "$CANNOT_UNEQUIP_AMMO";
std::string Keys::ammoEquippedText = "$AMMO_EQUIPPED";
std::string Keys::missingLooseModText = "$MISSING_LOOSEMOD";
std::string Keys::pipboyMagsizeLoadedText = "$PIP_MAGSIZE_LOADED";
std::string Keys::menuAmmoTypeText = "$MENU_AMMOTYPE";
std::string Keys::menuMuzzleText = "$MENU_MUZZLE";
std::string Keys::menuNoneText = "$MENU_NONE";
void FillDefaults()
{
MSF_MainData::loc = "en_d";
MSF_MainData::translationMap[Keys::modText] = "This mod can only be attached at a workbench.";
MSF_MainData::translationMap[Keys::noAPText] = "The equipped weapon does not have a compatible attach point for this mod.";
MSF_MainData::translationMap[Keys::noWeapText] = "There is no compatible weapon equipped for this mod.";
MSF_MainData::translationMap[Keys::couldntAttachText] = "Could not attach this mod to the equipped weapon.";
MSF_MainData::translationMap[Keys::itemText] = "You cannot equip this item.";
MSF_MainData::translationMap[Keys::unsupportedAmmoText] = "You cannot equip non-playable ammo or fusion cores.";
MSF_MainData::translationMap[Keys::noAmmoTypeText] = "You cannot equip this ammo type.";
MSF_MainData::translationMap[Keys::ammoEquipFailedText] = "You cannot equip this ammo right now.";
MSF_MainData::translationMap[Keys::ammoUnequipText] = "You cannot unequip ammo.";
MSF_MainData::translationMap[Keys::ammoEquippedText] = "Ammo equipped.";
MSF_MainData::translationMap[Keys::missingLooseModText] = "Missing required loose mod.";
MSF_MainData::translationMap[Keys::pipboyMagsizeLoadedText] = "Mag Size/Loaded";
MSF_MainData::translationMap[Keys::menuAmmoTypeText] = "Ammo Type";
MSF_MainData::translationMap[Keys::menuMuzzleText] = "Muzzle";
MSF_MainData::translationMap[Keys::menuNoneText] = "None";
}
bool ParseTranslations()
{
Setting* setting = GetINISetting("sLanguage:General");
std::string path = "Data\\MSF\\Translations\\";
std::string loc = (setting && setting->GetType() == Setting::kType_String) ? setting->data.s : "en";
_DEBUG("translate: %s", loc.c_str());
if (MSF_MainData::loc == loc)
return true;
FillDefaults();
// Construct translation filename
path += "MSF_";
path += loc;
path += ".txt";
_DEBUG("translate path: %s", path.c_str());
if (GetFileAttributes(path.c_str()) == INVALID_FILE_ATTRIBUTES)
_DEBUG("translate missing");
BSResourceNiBinaryStream fileStream(path.c_str());
if (!fileStream.IsValid())
return false;
else
_MESSAGE("Reading translations from %s...", path.c_str());
// Check if file is empty, if not check if the BOM is UTF-16
UInt32 bom = 0;
UInt32 ret = fileStream.Read(&bom, sizeof(UInt32));
if (ret == 0) {
_MESSAGE("Empty translation file.");
return false;
}
if ((bom & 0xFFFFFF) != 0xBFBBEF) {
_MESSAGE("BOM Error, translation file must be encoded in UTF-8 BOM. 0x%06X", bom & 0xFFFFFF);
return false;
}
while (true)
{
char buf[512];
UInt32 len = fileStream.ReadLine(buf, sizeof(buf) / sizeof(buf[0]), '\n');
if (len == 0) // End of file
break;
// at least $ + char + \t + char
if (len < 4 || buf[0] != '$')
continue;
char last = buf[len - 1];
if (last == '\r')
len--;
// null terminate
buf[len] = 0;
UInt32 delimIdx = 0;
for (UInt32 i = 0; i < len; i++)
if (buf[i] == '\t')
delimIdx = i;
// at least $ + char
if (delimIdx < 2)
continue;
// replace \t by \0
buf[delimIdx] = 0;
std::string key(buf);
std::string translation(&buf[delimIdx + 1]);
MSF_MainData::translationMap[key] = translation;
}
MSF_MainData::loc = loc;
return true;
}
const char* GetTranslation(std::string key)
{
auto trIt = MSF_MainData::translationMap.find(key);
if (trIt == MSF_MainData::translationMap.end())
return "";
return trIt->second.c_str();
}
}