-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocale_settings.lua
207 lines (184 loc) · 6.81 KB
/
locale_settings.lua
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
module(..., package.seeall)
debug.ReloadScripts.allowReload(..., true)
local thisModule = _M
-- NOTE: The native names here may appear buggy, because they are in UTF-8, but they are just fine.
-- This is the list of all known languages (note, not all of these are supported for all purposes, such as for audio purposes).
-- Languages per build or per platform are defined in: initLanguagesPerPlatformOrBuild()
all_languages =
{
{ id = "en", nativeName = "English", englishName = "English", audioName = "english_us_/" }
, { id = "de", nativeName = "Deutsch", englishName = "German", audioName = "german/" }
, { id = "fr", nativeName = "Français", englishName = "French", audioName = "french_france_/" }
, { id = "es", nativeName = "Español", englishName = "Spanish", audioName = "spanish_spain_/" }
, { id = "it", nativeName = "Italiano", englishName = "Italian", audioName = "italian/" }
, { id = "ru", nativeName = "Русский", englishName = "Russian", audioName = "russian/", useCompatibilityFont = false, useCompatibilityFont2 = false }
, { id = "ja", nativeName = "日本語", englishName = "Japanese", audioName = "japanese/", useCompatibilityFont = true, useCompatibilityFont2 = true }
, { id = "zh", nativeName = "简体中文", englishName = "Chinese (Simplified)", audioName = "chinese_s/", useCompatibilityFont = true, useCompatibilityFont2 = true }
}
-- list of supported gui langugages
all_guiLocaleLanguages =
{
"en"
, "de"
, "fr"
, "es"
, "it"
, "ru"
, "ja"
, "zh"
}
-- list of supported subtitling langugages
all_subtitleLocaleLanguages =
{
"en"
, "de"
, "fr"
, "es"
, "it"
, "ru"
, "ja"
, "zh"
}
-- list of supported audio langugages
all_audioLanguages =
{
"en"
}
languages = { };
guiLocaleLanguages = { };
subtitleLocaleLanguages = { };
audioLanguages = { };
declareReload(thisModule, [[all_languages]])
declareReload(thisModule, [[all_guiLocaleLanguages]])
declareReload(thisModule, [[all_subtitleLocaleLanguages]])
declareReload(thisModule, [[all_audioLanguages]])
declareReload(thisModule, [[languages]])
declareReload(thisModule, [[guiLocaleLanguages]])
declareReload(thisModule, [[subtitleLocaleLanguages]])
declareReload(thisModule, [[audioLanguages]])
function initLanguagesPerPlatformOrBuild()
local useAllAvailableLanguages = false;
-- Use "en" always as default if nothing else is defined
local tmplanguages = { "en"}
local tmpguiLocaleLanguages = { "en"}
local tmpsubtitleLocaleLanguages = { "en"}
local tmpaudioLanguages = { "en"}
-- Clear old ones
languages = { };
guiLocaleLanguages = { };
subtitleLocaleLanguages = { };
audioLanguages = { };
if FB_BUILD == "FB_FINAL_RELEASE" then
-- Steam and non-steam has all languages
tmplanguages = {"en", "de", "fr", "es", "it", "ru", "ja", "zh"}
tmpguiLocaleLanguages = {"en", "de", "fr", "es", "it", "ru", "ja", "zh"}
tmpsubtitleLocaleLanguages = {"en", "de", "fr", "es", "it", "ru", "ja", "zh"}
tmpaudioLanguages = {"en"}
else
-- If not final release, just use all available languages. E.g. in Editor we want to be able to configure all languages
useAllAvailableLanguages = true;
end
if useAllAvailableLanguages then
-- Use all languages which are defined into all_ tables
languages = all_languages;
guiLocaleLanguages = all_guiLocaleLanguages;
subtitleLocaleLanguages = all_subtitleLocaleLanguages;
audioLanguages = all_audioLanguages;
else
-- Add all desired languages
for i, lang in ipairs(all_languages) do
for i, tmplang in ipairs(tmplanguages) do
if lang.id == tmplang then
table.insert(languages, lang);
end
end
end
guiLocaleLanguages = tmpguiLocaleLanguages;
subtitleLocaleLanguages = tmpsubtitleLocaleLanguages;
audioLanguages = tmpaudioLanguages;
end
end
function tableHasEntry(t, v)
for i=#t,1,-1 do
if(t[i] == v) then
return true
end
end
return false
end
function addLocalePatches()
-- Init languages
initLanguagesPerPlatformOrBuild();
-- Language patches
for i = 0,localeModule:getLocalePatchAmount()-1 do
local localePatchInfoString = localeModule:getLocalePatchInfo(i)
if (localePatchInfoString ~= "") then
localeModule:applyLocalePatchInfo(localePatchInfoString)
if (_G.localePatchTemp) then
local loc = _G.localePatchTemp
if (type(loc) == "table") then
if (type(loc.id) == "string"
and type(loc.supportGui) == "boolean"
and type(loc.supportSubtitle) == "boolean"
and type(loc.supportAudio) == "boolean")
then
table.insert(languages, loc)
if (loc.supportGui and not tableHasEntry(guiLocaleLanguages, loc.id)) then
table.insert(guiLocaleLanguages, loc.id)
end
if (loc.supportSubtitle and not tableHasEntry(subtitleLocaleLanguages, loc.id)) then
table.insert(subtitleLocaleLanguages, loc.id)
end
if (loc.supportAudio and not tableHasEntry(audioLanguages, loc.id)) then
table.insert(audioLanguages, loc.id)
end
else
logger:error("Locale patch info does not contain proper id or information about supported locale banks.")
end
else
logger:error("Malformed locale patch info (non lua table data).")
end
else
logger:error("Malformed locale patch info (probably a parse error).")
end
else
logger:warning("Empty locale patch info encountered.")
end
end
_G.localePatchTemp = nil
end
function load()
-- Init languages
initLanguagesPerPlatformOrBuild();
-- Languages
for i = 1,#languages do
local useCompatibilityFont = false
local useCompatibilityFont2 = false
if (languages[i].useCompatibilityFont) then useCompatibilityFont = true end
if (languages[i].useCompatibilityFont2) then useCompatibilityFont2 = true end
-- (done like this for backward compatibility between different script<->executables)
if (useCompatibilityFont2) then
localeModule:addLanguageExtended(languages[i].id, languages[i].nativeName, languages[i].englishName, languages[i].audioName, 2)
else
localeModule:addLanguage(languages[i].id, languages[i].nativeName, languages[i].englishName, languages[i].audioName, useCompatibilityFont)
end
end
-- Setup GUI locales
--
localeModule:addLocaleBank("gui", "GuiLanguage")
for i = 1,#guiLocaleLanguages do
localeModule:addSupportedLanguageToBank("gui", guiLocaleLanguages[i])
end
-- Setup subtitle locales
--
localeModule:addLocaleBank("subtitles", "SubtitleLanguage")
for i = 1,#subtitleLocaleLanguages do
localeModule:addSupportedLanguageToBank("subtitles", guiLocaleLanguages[i])
end
-- Setup audio locales
--
localeModule:addLocaleBank("audio", "AudioLanguage")
for i = 1,#audioLanguages do
localeModule:addSupportedLanguageToBank("audio", guiLocaleLanguages[i])
end
end