2022-12-29 05:23:20 +01:00
|
|
|
#define LOCALIZATIONSTORAGE_CPP
|
|
|
|
#include "Localization.h"
|
|
|
|
#include "LocalizationStorage.h"
|
|
|
|
|
2022-12-31 04:37:45 +01:00
|
|
|
#include "Alloc.h"
|
2022-12-29 05:23:20 +01:00
|
|
|
#include "Constants.h"
|
|
|
|
#include "CustomLevels.h"
|
|
|
|
#include "FileSystemUtils.h"
|
2023-01-06 19:17:50 +01:00
|
|
|
#include "Font.h"
|
2022-12-29 05:23:20 +01:00
|
|
|
#include "Graphics.h"
|
|
|
|
#include "Unused.h"
|
|
|
|
#include "UtilityClass.h"
|
|
|
|
#include "VFormat.h"
|
|
|
|
#include "Vlogging.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace loc
|
|
|
|
{
|
|
|
|
|
|
|
|
bool inited = false;
|
|
|
|
bool inited_custom = false;
|
|
|
|
|
|
|
|
char* custom_level_path = NULL;
|
|
|
|
|
|
|
|
std::vector<TextOverflow> text_overflows;
|
|
|
|
|
|
|
|
bool load_lang_doc(
|
|
|
|
const std::string& cat,
|
|
|
|
tinyxml2::XMLDocument& doc,
|
|
|
|
const std::string& langcode /*= lang*/,
|
|
|
|
const std::string& asset_cat /*= ""*/
|
|
|
|
)
|
|
|
|
{
|
|
|
|
/* Load a language-related XML file.
|
|
|
|
* cat is the "category", so "strings", "numbers", etc.
|
|
|
|
*
|
|
|
|
* asset_cat is only used when loading
|
|
|
|
* from custom level assets is possible. */
|
|
|
|
|
|
|
|
bool asset_loaded = false;
|
|
|
|
if (!asset_cat.empty())
|
|
|
|
{
|
|
|
|
asset_loaded = FILESYSTEM_loadAssetTiXml2Document(("lang/" + langcode + "/" + asset_cat + ".xml").c_str(), doc);
|
|
|
|
}
|
|
|
|
if (!asset_loaded && !FILESYSTEM_loadTiXml2Document(("lang/" + langcode + "/" + cat + ".xml").c_str(), doc))
|
|
|
|
{
|
|
|
|
vlog_debug("Could not load language file %s/%s.", langcode.c_str(), cat.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (doc.Error())
|
|
|
|
{
|
|
|
|
vlog_error("Error parsing language file %s/%s: %s", langcode.c_str(), cat.c_str(), doc.ErrorStr());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loadmeta(LangMeta& meta, const std::string& langcode = lang)
|
|
|
|
{
|
|
|
|
meta.active = true;
|
|
|
|
meta.code = langcode;
|
2023-12-08 02:05:24 +01:00
|
|
|
meta.nativename = langcode;
|
|
|
|
meta.credit = "";
|
|
|
|
meta.action_hint = "Press Space, Z, or V to select";
|
|
|
|
meta.gamepad_hint = "Press {button} to select";
|
2022-12-29 05:23:20 +01:00
|
|
|
meta.autowordwrap = true;
|
|
|
|
meta.toupper = true;
|
|
|
|
meta.toupper_i_dot = false;
|
|
|
|
meta.toupper_lower_escape_char = false;
|
|
|
|
meta.menu_select = "[ {label} ]";
|
|
|
|
meta.menu_select_tight = "[{label}]";
|
2023-01-15 01:31:02 +01:00
|
|
|
meta.font_idx = font::get_font_idx_8x8();
|
2022-12-29 05:23:20 +01:00
|
|
|
|
|
|
|
tinyxml2::XMLDocument doc;
|
|
|
|
tinyxml2::XMLHandle hDoc(&doc);
|
|
|
|
tinyxml2::XMLElement* pElem;
|
|
|
|
|
|
|
|
if (!load_lang_doc("meta", doc, langcode))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FOR_EACH_XML_ELEMENT(hDoc, pElem)
|
|
|
|
{
|
|
|
|
const char* pKey = pElem->Value();
|
|
|
|
const char* pText = pElem->GetText();
|
|
|
|
if (pText == NULL)
|
|
|
|
{
|
|
|
|
pText = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SDL_strcmp(pKey, "active") == 0)
|
|
|
|
meta.active = help.Int(pText);
|
|
|
|
else if (SDL_strcmp(pKey, "nativename") == 0)
|
|
|
|
meta.nativename = std::string(pText);
|
|
|
|
else if (SDL_strcmp(pKey, "credit") == 0)
|
|
|
|
meta.credit = std::string(pText);
|
|
|
|
else if (SDL_strcmp(pKey, "action_hint") == 0)
|
|
|
|
meta.action_hint = std::string(pText);
|
2023-03-26 20:15:45 +02:00
|
|
|
else if (SDL_strcmp(pKey, "gamepad_hint") == 0)
|
|
|
|
meta.gamepad_hint = std::string(pText);
|
2022-12-29 05:23:20 +01:00
|
|
|
else if (SDL_strcmp(pKey, "autowordwrap") == 0)
|
|
|
|
meta.autowordwrap = help.Int(pText);
|
|
|
|
else if (SDL_strcmp(pKey, "toupper") == 0)
|
|
|
|
meta.toupper = help.Int(pText);
|
|
|
|
else if (SDL_strcmp(pKey, "toupper_i_dot") == 0)
|
|
|
|
meta.toupper_i_dot = help.Int(pText);
|
|
|
|
else if (SDL_strcmp(pKey, "toupper_lower_escape_char") == 0)
|
|
|
|
meta.toupper_lower_escape_char = help.Int(pText);
|
|
|
|
else if (SDL_strcmp(pKey, "menu_select") == 0)
|
|
|
|
meta.menu_select = std::string(pText);
|
|
|
|
else if (SDL_strcmp(pKey, "menu_select_tight") == 0)
|
|
|
|
meta.menu_select_tight = std::string(pText);
|
2023-01-15 01:31:02 +01:00
|
|
|
else if (SDL_strcmp(pKey, "font") == 0)
|
|
|
|
font::find_main_font_by_name(pText, &meta.font_idx);
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void map_store_translation(Textbook* textbook, hashmap* map, const char* eng, const char* tra)
|
|
|
|
{
|
|
|
|
/* Add the texts to the given textbook and set the translation in the given hashmap. */
|
|
|
|
if (eng == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tra == NULL)
|
|
|
|
{
|
|
|
|
tra = "";
|
|
|
|
}
|
|
|
|
const char* tb_eng = textbook_store(textbook, eng);
|
|
|
|
const char* tb_tra = textbook_store(textbook, tra);
|
|
|
|
|
|
|
|
if (tb_eng == NULL || tb_tra == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-05 21:42:21 +01:00
|
|
|
hashmap_set(map, tb_eng, SDL_strlen(tb_eng), (uintptr_t) tb_tra);
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char form_for_count(int n)
|
|
|
|
{
|
|
|
|
int n_ix;
|
|
|
|
if (n > -100 && n < 100)
|
|
|
|
{
|
|
|
|
/* Plural forms for negative numbers are debatable in any language I'd imagine...
|
|
|
|
* But they shouldn't appear anyway unless there's a bug or you're asking for it.
|
|
|
|
* Or do YOU ever get -10 deaths while collecting -1 trinket? */
|
|
|
|
n_ix = SDL_abs(n);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Plural forms for 100 and above always just keep repeating. Thank goodness. */
|
|
|
|
n_ix = SDL_abs(n % 100) + 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
return number_plural_form[n_ix];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void callback_free_map_value(void* key, size_t ksize, uintptr_t value, void* usr)
|
|
|
|
{
|
|
|
|
UNUSED(key);
|
|
|
|
UNUSED(ksize);
|
|
|
|
UNUSED(usr);
|
|
|
|
|
|
|
|
hashmap_free((hashmap*) value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void resettext_custom(bool final_shutdown)
|
|
|
|
{
|
|
|
|
/* Reset/initialize custom level strings only.
|
|
|
|
* If final_shutdown, this just does a last cleanup of any allocations,
|
|
|
|
* otherwise it makes storage ready for first use (or reuse by a new language). */
|
|
|
|
|
|
|
|
if (inited_custom)
|
|
|
|
{
|
|
|
|
hashmap_iterate(map_translation_cutscene_custom, callback_free_map_value, NULL);
|
|
|
|
hashmap_free(map_translation_cutscene_custom);
|
|
|
|
|
|
|
|
textbook_clear(&textbook_custom);
|
|
|
|
}
|
|
|
|
else if (!final_shutdown)
|
|
|
|
{
|
|
|
|
inited_custom = true;
|
|
|
|
|
|
|
|
textbook_init(&textbook_custom);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!final_shutdown)
|
|
|
|
{
|
|
|
|
map_translation_cutscene_custom = hashmap_create();
|
|
|
|
|
|
|
|
SDL_zeroa(translation_roomnames_custom);
|
|
|
|
SDL_zeroa(explanation_roomnames_custom);
|
|
|
|
|
|
|
|
n_untranslated_roomnames_custom = 0;
|
|
|
|
n_unexplained_roomnames_custom = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void unloadtext_custom(void)
|
|
|
|
{
|
|
|
|
resettext_custom(false);
|
|
|
|
|
|
|
|
loc::lang_custom = "";
|
|
|
|
|
2022-12-31 04:37:45 +01:00
|
|
|
VVV_free(custom_level_path);
|
2022-12-29 05:23:20 +01:00
|
|
|
custom_level_path = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void resettext(bool final_shutdown)
|
|
|
|
{
|
|
|
|
/* Reset/initialize strings.
|
|
|
|
* If final_shutdown, this just does a last cleanup of any allocations,
|
|
|
|
* otherwise it makes storage ready for first use (or reuse by a new language). */
|
|
|
|
|
|
|
|
if (inited)
|
|
|
|
{
|
|
|
|
hashmap_free(map_translation);
|
|
|
|
hashmap_iterate(map_translation_cutscene, callback_free_map_value, NULL);
|
|
|
|
hashmap_free(map_translation_cutscene);
|
|
|
|
hashmap_free(map_translation_plural);
|
|
|
|
hashmap_free(map_translation_roomnames_special);
|
|
|
|
|
|
|
|
textbook_clear(&textbook_main);
|
|
|
|
}
|
|
|
|
else if (!final_shutdown)
|
|
|
|
{
|
|
|
|
inited = true;
|
|
|
|
|
|
|
|
textbook_init(&textbook_main);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!final_shutdown)
|
|
|
|
{
|
|
|
|
map_translation = hashmap_create();
|
|
|
|
map_translation_cutscene = hashmap_create();
|
|
|
|
map_translation_plural = hashmap_create();
|
|
|
|
|
|
|
|
for (size_t i = 0; i <= 100; i++)
|
|
|
|
{
|
|
|
|
number[i] = "";
|
Add a system for selecting between wordy/wordy2
Some languages have different spellings of wordy numbers based on the
gender of the things they're counting (uno crewmate versus una trinket)
or what a number's role is in the sentence (e.g. twenta out of twentu).
We've always had the idea we couldn't support such complex differences
though, because the game can't be adapted to know what gender each
object will have and what word classes might exist in other languages,
so translators would in those cases just have to forgo the wordy
numbers and just let the game use "20 out of 20".
A solution we came up semi-recently though (after all translations were
finished except for Arabic), was to allow the translator to define
however many classes of wordy numbers they need, and fill them all out.
This would not need the game to be *adapted* for every language's
specific grammar and word genders/classes. Instead, the translator
would just choose their correct self-defined class at the time they use
`wordy` in the VFormat placeholder. Something like
{n|wordy|class=feminine}, or {n|wordy_feminine}.
So this would benefit several languages, but we came up with the
solution a little late for all languages to benefit from it. The Arabic
translators asked for two separate classes of wordy numbers though, so
my plan is to first just have a second list of wordy numbers
(translation2 in numbers.xml), which can be accessed by passing the
`wordy2` flag to VFormat, instead of `wordy`.
Once 2.4 is released, we can take our time to do it properly. This
would involve the ability for translators to define however many
classes they need, to name them what they want, and this name would
then be useable in VFormat placeholders. We can convert all existing
translations to have one class defined by default, such as "wordy", or
"translation" depending on implementation, but there's not so much
concern for maintaining backwards compatibility here, so we can do a
mass-switchover for all language files. That said, it wouldn't be too
hard to add a special case for "translation" being "wordy" either.
We can then ask translators if they would like to change anything with
the new system in place.
For now, we can use this system for Arabic, maybe Spanish since there
were complaints about uno/una, and *maybe* Dutch (it has a thing where
the number "one" is often capitalized differently, but it's not
mandatory per se)
2024-01-06 04:15:06 +01:00
|
|
|
number2[i] = "";
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
SDL_zeroa(number_plural_form);
|
2023-12-08 02:05:24 +01:00
|
|
|
number_plural_form[1] = 1;
|
2022-12-29 05:23:20 +01:00
|
|
|
|
|
|
|
SDL_zeroa(translation_roomnames);
|
|
|
|
SDL_zeroa(explanation_roomnames);
|
|
|
|
|
|
|
|
n_untranslated_roomnames = 0;
|
|
|
|
n_unexplained_roomnames = 0;
|
2022-11-27 20:06:08 +01:00
|
|
|
SDL_zeroa(n_untranslated_roomnames_area);
|
2022-12-29 05:23:20 +01:00
|
|
|
|
|
|
|
SDL_zeroa(n_untranslated);
|
|
|
|
|
|
|
|
map_translation_roomnames_special = hashmap_create();
|
|
|
|
}
|
|
|
|
|
|
|
|
resettext_custom(final_shutdown);
|
|
|
|
}
|
|
|
|
|
2023-01-23 03:15:17 +01:00
|
|
|
bool parse_max(const char* max, unsigned short* max_w, unsigned short* max_h)
|
2022-12-29 05:23:20 +01:00
|
|
|
{
|
|
|
|
/* Parse a max string, like "33" or "33*3", into two shorts.
|
|
|
|
* Returns true if successful and max_w/max_h have gotten valid values, false otherwise. */
|
|
|
|
if (max == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* max_mut = SDL_strdup(max);
|
|
|
|
if (max_mut == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* asterisk = SDL_strchr(max_mut, '*');
|
|
|
|
if (asterisk != NULL)
|
|
|
|
{
|
|
|
|
asterisk[0] = '\0';
|
|
|
|
*max_h = (unsigned short) help.Int(&asterisk[1], 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*max_h = 1;
|
|
|
|
}
|
|
|
|
*max_w = (unsigned short) help.Int(max_mut, 0);
|
|
|
|
|
2022-12-31 04:37:45 +01:00
|
|
|
VVV_free(max_mut);
|
2022-12-29 05:23:20 +01:00
|
|
|
|
|
|
|
return *max_w != 0 && *max_h != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool max_check_string(const char* str, const char* max)
|
|
|
|
{
|
|
|
|
/* Stores a detected overflow in the overflows vector, returns true if this happened */
|
|
|
|
unsigned short max_w, max_h;
|
|
|
|
if (str == NULL || !parse_max(max, &max_w, &max_h))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Special case that must ALWAYS be 2 lines even when the font is bigger */
|
|
|
|
if (SDL_strcmp(str, "You have rescued a crew member!") == 0 && max_h == 1)
|
|
|
|
{
|
|
|
|
max_h = 2;
|
|
|
|
}
|
|
|
|
|
2023-01-16 21:29:50 +01:00
|
|
|
uint8_t font_idx = get_langmeta()->font_idx;
|
|
|
|
uint32_t print_flags = PR_FONT_IDX(font_idx) | PR_CJK_LOW;
|
2023-01-15 01:31:02 +01:00
|
|
|
uint8_t font_w = 8;
|
|
|
|
uint8_t font_h = 8;
|
2023-01-17 22:18:39 +01:00
|
|
|
font::glyph_dimensions(print_flags, &font_w, &font_h);
|
2023-01-15 01:31:02 +01:00
|
|
|
|
2023-01-16 21:29:50 +01:00
|
|
|
unsigned short max_w_px = max_w * 8;
|
|
|
|
unsigned short max_h_px = max_h * 10;
|
2022-12-29 05:23:20 +01:00
|
|
|
|
|
|
|
bool does_overflow = false;
|
|
|
|
|
|
|
|
if (max_h == 1)
|
|
|
|
{
|
2023-01-16 21:29:50 +01:00
|
|
|
max_h_px = font_h;
|
|
|
|
does_overflow = font::len(print_flags, str) > (int) max_w_px;
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
short lines;
|
2023-01-21 02:31:44 +01:00
|
|
|
font::string_wordwrap(print_flags, str, max_w_px, &lines);
|
2023-01-16 21:29:50 +01:00
|
|
|
does_overflow = lines*SDL_max(10, font_h) > (short) max_h_px;
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
|
2023-01-16 21:29:50 +01:00
|
|
|
// Convert max_w and max_h from 8x8 into local
|
|
|
|
max_w = max_w_px / font_w;
|
|
|
|
max_h = max_h_px / SDL_max(10, font_h);
|
|
|
|
|
2022-12-29 05:23:20 +01:00
|
|
|
if (does_overflow)
|
|
|
|
{
|
|
|
|
TextOverflow overflow;
|
|
|
|
overflow.lang = lang;
|
|
|
|
overflow.text = textbook_store(&textbook_main, str);
|
|
|
|
overflow.max_w = max_w;
|
|
|
|
overflow.max_h = max_h;
|
|
|
|
overflow.max_w_px = max_w_px;
|
|
|
|
overflow.max_h_px = max_h_px;
|
|
|
|
overflow.multiline = max_h > 1;
|
2023-01-16 21:29:50 +01:00
|
|
|
overflow.flags = print_flags;
|
2022-12-29 05:23:20 +01:00
|
|
|
|
|
|
|
text_overflows.push_back(overflow);
|
|
|
|
|
|
|
|
vlog_warn("\"%s\" DOESN'T FIT into %s which is %dx%d or %dx%dpx",
|
|
|
|
str, max, max_w, max_h, max_w_px, max_h_px
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vlog_debug("\"%s\" fits into %s which is %dx%d or %dx%dpx",
|
|
|
|
str, max, max_w, max_h, max_w_px, max_h_px
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return does_overflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void max_check_string_plural(unsigned char form, const char* str, const char* max, const char* var, unsigned int expect)
|
|
|
|
{
|
|
|
|
if (str == NULL || var == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create an args index from just the name of the variable.
|
|
|
|
* Also get rid of all other placeholders.*/
|
|
|
|
char args_index[60];
|
|
|
|
vformat_buf(args_index, sizeof(args_index), "{var}:int, _:int", "var:str", var);
|
|
|
|
|
|
|
|
char buf[20*SCREEN_WIDTH_CHARS + 1];
|
|
|
|
|
|
|
|
if (expect > 100)
|
|
|
|
{
|
|
|
|
/* Treat `expect` as a single example, it's the number of digits that's most important */
|
|
|
|
if (form_for_count(expect) == form)
|
|
|
|
{
|
|
|
|
vformat_buf(buf, sizeof(buf), str, args_index, expect, 0);
|
|
|
|
|
|
|
|
max_check_string(buf, max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Test all numbers from 0 to `expect`, since if we have wordy numbers, they have differing lengths */
|
|
|
|
for (unsigned int test = 0; test <= expect; test++)
|
|
|
|
{
|
|
|
|
if (form_for_count(test) == form)
|
|
|
|
{
|
|
|
|
vformat_buf(buf, sizeof(buf), str, args_index, test, 0);
|
|
|
|
|
|
|
|
if (max_check_string(buf, max))
|
|
|
|
{
|
|
|
|
/* One is enough */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tally_untranslated(const char* tra, int* counter)
|
|
|
|
{
|
|
|
|
/* Count this translation in the untranslated count if it's untranslated. */
|
|
|
|
if (!show_translator_menu)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tra == NULL || tra[0] == '\0')
|
|
|
|
{
|
|
|
|
(*counter)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loadtext_strings(bool check_max)
|
|
|
|
{
|
|
|
|
tinyxml2::XMLDocument doc;
|
|
|
|
tinyxml2::XMLHandle hDoc(&doc);
|
|
|
|
tinyxml2::XMLElement* pElem;
|
|
|
|
|
|
|
|
if (!load_lang_doc("strings", doc))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FOR_EACH_XML_ELEMENT(hDoc, pElem)
|
|
|
|
{
|
|
|
|
EXPECT_ELEM(pElem, "string");
|
|
|
|
|
|
|
|
const char* eng = pElem->Attribute("english");
|
|
|
|
const char* tra = pElem->Attribute("translation");
|
|
|
|
|
Add support for string cases in strings.xml (gendered Rescued/Missing)
I wanted to not complicate the system with different string cases (like
cgettext) if possible, and I have been able to keep the main strings a
simple English=Translation mapping thus far, but apparently strings
like "Rescued!" (which are one string in English), have to be
translated for the correct gender in some languages. So this was a good
time to add support for string cases anyway.
It's a number that can be given to a string to specify the specific
case it's used, to disambiguate identical English keys. In the case of
"Rescued!" and "Missing...", male versions of the string are case 1,
female versions are case 2, and Viridian being missing is case 3. Of
course, if a language doesn't need to use different variants, it can
simply fill in the same string for the different cases.
If any other string needs to switch to different cases: distinguish
them in the English strings.xml with the case="N" attribute (N=1 and
higher), sync language files from the translator menu (existing
translations for the uncased string will simply be copied to all cases)
and change loc::gettext("...") to loc::gettext_case("...", 1),
loc::gettext_case("...", 2), etc.
2022-12-01 01:27:30 +01:00
|
|
|
char textcase = pElem->UnsignedAttribute("case", 0);
|
|
|
|
|
|
|
|
if (textcase == 0)
|
|
|
|
{
|
|
|
|
map_store_translation(
|
|
|
|
&textbook_main,
|
|
|
|
map_translation,
|
|
|
|
eng,
|
|
|
|
tra
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Only prefix with a disambiguator if a specific case number is set */
|
|
|
|
char* eng_prefixed = add_disambiguator(textcase, eng, NULL);
|
|
|
|
if (eng_prefixed == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
map_store_translation(
|
|
|
|
&textbook_main,
|
|
|
|
map_translation,
|
|
|
|
eng_prefixed,
|
|
|
|
tra
|
|
|
|
);
|
2022-12-31 04:37:45 +01:00
|
|
|
VVV_free(eng_prefixed);
|
Add support for string cases in strings.xml (gendered Rescued/Missing)
I wanted to not complicate the system with different string cases (like
cgettext) if possible, and I have been able to keep the main strings a
simple English=Translation mapping thus far, but apparently strings
like "Rescued!" (which are one string in English), have to be
translated for the correct gender in some languages. So this was a good
time to add support for string cases anyway.
It's a number that can be given to a string to specify the specific
case it's used, to disambiguate identical English keys. In the case of
"Rescued!" and "Missing...", male versions of the string are case 1,
female versions are case 2, and Viridian being missing is case 3. Of
course, if a language doesn't need to use different variants, it can
simply fill in the same string for the different cases.
If any other string needs to switch to different cases: distinguish
them in the English strings.xml with the case="N" attribute (N=1 and
higher), sync language files from the translator menu (existing
translations for the uncased string will simply be copied to all cases)
and change loc::gettext("...") to loc::gettext_case("...", 1),
loc::gettext_case("...", 2), etc.
2022-12-01 01:27:30 +01:00
|
|
|
}
|
2022-12-29 05:23:20 +01:00
|
|
|
|
|
|
|
/* Only tally an untranslated string if English isn't blank */
|
|
|
|
if (eng != NULL && eng[0] != '\0')
|
|
|
|
{
|
|
|
|
tally_untranslated(tra, &n_untranslated[UNTRANSLATED_STRINGS]);
|
|
|
|
}
|
|
|
|
if (check_max)
|
|
|
|
{
|
|
|
|
/* VFormat placeholders distort the limits check.
|
|
|
|
* (max_check_string ignores NULL strings.) */
|
|
|
|
char* filled = vformat_alloc(tra, "_:int", 0);
|
|
|
|
max_check_string(filled, pElem->Attribute("max"));
|
2022-12-31 04:37:45 +01:00
|
|
|
VVV_free(filled);
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loadtext_strings_plural(bool check_max)
|
|
|
|
{
|
|
|
|
tinyxml2::XMLDocument doc;
|
|
|
|
tinyxml2::XMLHandle hDoc(&doc);
|
|
|
|
tinyxml2::XMLElement* pElem;
|
|
|
|
|
|
|
|
if (!load_lang_doc("strings_plural", doc))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FOR_EACH_XML_ELEMENT(hDoc, pElem)
|
|
|
|
{
|
|
|
|
EXPECT_ELEM(pElem, "string");
|
|
|
|
|
|
|
|
const char* eng_plural = pElem->Attribute("english_plural");
|
|
|
|
if (eng_plural == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tinyxml2::XMLElement* subElem;
|
|
|
|
FOR_EACH_XML_SUB_ELEMENT(pElem, subElem)
|
|
|
|
{
|
|
|
|
EXPECT_ELEM(subElem, "translation");
|
|
|
|
|
|
|
|
unsigned char form = subElem->IntAttribute("form", 0);
|
|
|
|
char* key = add_disambiguator(form+1, eng_plural, NULL);
|
|
|
|
if (key == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
map_store_translation(
|
|
|
|
&textbook_main,
|
|
|
|
map_translation_plural,
|
|
|
|
key,
|
|
|
|
subElem->Attribute("translation")
|
|
|
|
);
|
|
|
|
|
2022-12-31 04:37:45 +01:00
|
|
|
VVV_free(key);
|
2022-12-29 05:23:20 +01:00
|
|
|
|
|
|
|
tally_untranslated(subElem->Attribute("translation"), &n_untranslated[UNTRANSLATED_STRINGS_PLURAL]);
|
|
|
|
if (check_max)
|
|
|
|
{
|
|
|
|
max_check_string_plural(
|
|
|
|
form, subElem->Attribute("translation"),
|
|
|
|
pElem->Attribute("max"),
|
|
|
|
pElem->Attribute("var"), pElem->UnsignedAttribute("expect", 101)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool get_level_lang_path(bool custom_level, const char* cat, std::string& doc_path, std::string& doc_path_asset)
|
|
|
|
{
|
|
|
|
/* Calculate the path to a translation file for either the MAIN GAME or
|
|
|
|
* a CUSTOM LEVEL. cat can be "roomnames", "cutscenes", etc.
|
|
|
|
*
|
|
|
|
* doc_path and doc_path_asset are "out" parameters, and will be set to
|
|
|
|
* the appropriate filenames to use for language files outside of or
|
|
|
|
* inside level assets respectively (translations for custom levels can
|
|
|
|
* live in the main language folders too)
|
|
|
|
*
|
|
|
|
* Returns whether this is a (valid) custom level path. */
|
|
|
|
|
|
|
|
if (custom_level
|
|
|
|
&& custom_level_path != NULL
|
|
|
|
&& SDL_strncmp(custom_level_path, "levels/", 7) == 0
|
|
|
|
&& SDL_strlen(custom_level_path) > (sizeof(".vvvvvv")-1)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
/* Get rid of .vvvvvv */
|
|
|
|
size_t len = SDL_strlen(custom_level_path)-7;
|
|
|
|
doc_path = std::string(custom_level_path, len);
|
|
|
|
doc_path.append("/custom_");
|
|
|
|
doc_path.append(cat);
|
|
|
|
|
|
|
|
/* For the asset path, also get rid of the levels/LEVELNAME/ */
|
|
|
|
doc_path_asset = "custom_";
|
|
|
|
doc_path_asset.append(cat);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
doc_path = cat;
|
|
|
|
doc_path_asset = "";
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-24 04:16:56 +01:00
|
|
|
const char* get_level_original_lang(tinyxml2::XMLHandle& hDoc)
|
2022-12-29 05:23:20 +01:00
|
|
|
{
|
|
|
|
/* cutscenes and roomnames files can specify the original language as
|
|
|
|
* an attribute of the root tag to change the attribute names of the
|
|
|
|
* original text (normally "english"). This makes level translations
|
|
|
|
* less confusing if the original language isn't English. */
|
|
|
|
|
|
|
|
const char* original = NULL;
|
|
|
|
tinyxml2::XMLElement* pRoot = hDoc.FirstChildElement().ToElement();
|
|
|
|
if (pRoot != NULL)
|
|
|
|
{
|
|
|
|
original = pRoot->Attribute("original");
|
|
|
|
}
|
|
|
|
if (original == NULL)
|
|
|
|
{
|
|
|
|
original = "english";
|
|
|
|
}
|
|
|
|
return original;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string& get_level_lang_code(bool custom_level)
|
|
|
|
{
|
|
|
|
if (!custom_level || lang_custom == "")
|
|
|
|
{
|
|
|
|
return lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lang_custom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loadtext_cutscenes(bool custom_level)
|
|
|
|
{
|
|
|
|
tinyxml2::XMLDocument doc;
|
|
|
|
tinyxml2::XMLHandle hDoc(&doc);
|
|
|
|
tinyxml2::XMLElement* pElem;
|
|
|
|
|
|
|
|
std::string doc_path;
|
|
|
|
std::string doc_path_asset;
|
|
|
|
bool valid_custom_level = get_level_lang_path(custom_level, "cutscenes", doc_path, doc_path_asset);
|
|
|
|
if (custom_level && !valid_custom_level)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!load_lang_doc(doc_path, doc, get_level_lang_code(custom_level), doc_path_asset))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Textbook* textbook;
|
|
|
|
hashmap* map;
|
|
|
|
if (custom_level)
|
|
|
|
{
|
|
|
|
textbook = &textbook_custom;
|
|
|
|
map = map_translation_cutscene_custom;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textbook = &textbook_main;
|
|
|
|
map = map_translation_cutscene;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* original = get_level_original_lang(hDoc);
|
|
|
|
|
|
|
|
FOR_EACH_XML_ELEMENT(hDoc, pElem)
|
|
|
|
{
|
|
|
|
EXPECT_ELEM(pElem, "cutscene");
|
|
|
|
|
|
|
|
const char* script_id = textbook_store(textbook, pElem->Attribute("id"));
|
|
|
|
if (script_id == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
hashmap* cutscene_map = hashmap_create();
|
|
|
|
hashmap_set_free(
|
|
|
|
map,
|
2023-03-05 21:42:21 +01:00
|
|
|
script_id,
|
2022-12-29 05:23:20 +01:00
|
|
|
SDL_strlen(script_id),
|
|
|
|
(uintptr_t) cutscene_map,
|
|
|
|
callback_free_map_value,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
tinyxml2::XMLElement* subElem;
|
|
|
|
FOR_EACH_XML_SUB_ELEMENT(pElem, subElem)
|
|
|
|
{
|
|
|
|
EXPECT_ELEM(subElem, "dialogue");
|
|
|
|
|
|
|
|
const char* eng = subElem->Attribute(original);
|
|
|
|
const char* tra = subElem->Attribute("translation");
|
|
|
|
if (!custom_level)
|
|
|
|
{
|
|
|
|
tally_untranslated(tra, &n_untranslated[UNTRANSLATED_CUTSCENES]);
|
|
|
|
}
|
|
|
|
if (eng == NULL || tra == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2023-01-06 19:17:50 +01:00
|
|
|
const std::string eng_unwrapped = font::string_unwordwrap(eng);
|
2022-12-29 05:23:20 +01:00
|
|
|
char* eng_prefixed = add_disambiguator(subElem->UnsignedAttribute("case", 1), eng_unwrapped.c_str(), NULL);
|
|
|
|
if (eng_prefixed == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const char* tb_eng = textbook_store(textbook, eng_prefixed);
|
|
|
|
const char* tb_tra = textbook_store(textbook, tra);
|
2022-12-31 04:37:45 +01:00
|
|
|
VVV_free(eng_prefixed);
|
2022-12-29 05:23:20 +01:00
|
|
|
if (tb_eng == NULL || tb_tra == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
TextboxFormat format;
|
|
|
|
format.text = tb_tra;
|
|
|
|
format.tt = subElem->BoolAttribute("tt", false);
|
|
|
|
format.centertext = subElem->BoolAttribute("centertext", false);
|
|
|
|
format.pad_left = subElem->UnsignedAttribute("pad_left", 0);
|
|
|
|
format.pad_right = subElem->UnsignedAttribute("pad_right", 0);
|
|
|
|
unsigned short pad = subElem->UnsignedAttribute("pad", 0);
|
|
|
|
format.pad_left += pad;
|
|
|
|
format.pad_right += pad;
|
|
|
|
format.wraplimit_raw = subElem->UnsignedAttribute("wraplimit", 0);
|
|
|
|
format.wraplimit = format.wraplimit_raw;
|
|
|
|
if (format.wraplimit == 0)
|
|
|
|
{
|
|
|
|
format.wraplimit = 36*8 - (format.pad_left+format.pad_right)*8;
|
|
|
|
}
|
|
|
|
format.padtowidth = subElem->UnsignedAttribute("padtowidth", 0);
|
|
|
|
|
|
|
|
const TextboxFormat* tb_format = (TextboxFormat*) textbook_store_raw(
|
|
|
|
textbook,
|
|
|
|
&format,
|
|
|
|
sizeof(TextboxFormat)
|
|
|
|
);
|
|
|
|
if (tb_format == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2023-03-05 21:42:21 +01:00
|
|
|
hashmap_set(cutscene_map, tb_eng, SDL_strlen(tb_eng), (uintptr_t) tb_format);
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loadtext_numbers(void)
|
|
|
|
{
|
|
|
|
tinyxml2::XMLDocument doc;
|
|
|
|
tinyxml2::XMLHandle hDoc(&doc);
|
|
|
|
tinyxml2::XMLElement* pElem;
|
|
|
|
|
|
|
|
if (!load_lang_doc("numbers", doc))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FOR_EACH_XML_ELEMENT(hDoc, pElem)
|
|
|
|
{
|
|
|
|
EXPECT_ELEM(pElem, "number");
|
|
|
|
|
|
|
|
const char* value_str = pElem->Attribute("value");
|
|
|
|
int value = help.Int(value_str);
|
|
|
|
if (value >= 0 && value <= 100)
|
|
|
|
{
|
|
|
|
const char* tra = pElem->Attribute("translation");
|
|
|
|
if (tra == NULL)
|
|
|
|
{
|
|
|
|
tra = "";
|
|
|
|
}
|
|
|
|
number[value] = std::string(tra);
|
|
|
|
|
|
|
|
tally_untranslated(tra, &n_untranslated[UNTRANSLATED_NUMBERS]);
|
Add a system for selecting between wordy/wordy2
Some languages have different spellings of wordy numbers based on the
gender of the things they're counting (uno crewmate versus una trinket)
or what a number's role is in the sentence (e.g. twenta out of twentu).
We've always had the idea we couldn't support such complex differences
though, because the game can't be adapted to know what gender each
object will have and what word classes might exist in other languages,
so translators would in those cases just have to forgo the wordy
numbers and just let the game use "20 out of 20".
A solution we came up semi-recently though (after all translations were
finished except for Arabic), was to allow the translator to define
however many classes of wordy numbers they need, and fill them all out.
This would not need the game to be *adapted* for every language's
specific grammar and word genders/classes. Instead, the translator
would just choose their correct self-defined class at the time they use
`wordy` in the VFormat placeholder. Something like
{n|wordy|class=feminine}, or {n|wordy_feminine}.
So this would benefit several languages, but we came up with the
solution a little late for all languages to benefit from it. The Arabic
translators asked for two separate classes of wordy numbers though, so
my plan is to first just have a second list of wordy numbers
(translation2 in numbers.xml), which can be accessed by passing the
`wordy2` flag to VFormat, instead of `wordy`.
Once 2.4 is released, we can take our time to do it properly. This
would involve the ability for translators to define however many
classes they need, to name them what they want, and this name would
then be useable in VFormat placeholders. We can convert all existing
translations to have one class defined by default, such as "wordy", or
"translation" depending on implementation, but there's not so much
concern for maintaining backwards compatibility here, so we can do a
mass-switchover for all language files. That said, it wouldn't be too
hard to add a special case for "translation" being "wordy" either.
We can then ask translators if they would like to change anything with
the new system in place.
For now, we can use this system for Arabic, maybe Spanish since there
were complaints about uno/una, and *maybe* Dutch (it has a thing where
the number "one" is often capitalized differently, but it's not
mandatory per se)
2024-01-06 04:15:06 +01:00
|
|
|
|
|
|
|
// FIXME: implement a more flexible system later, where translators define the classes
|
|
|
|
tra = pElem->Attribute("translation2");
|
|
|
|
if (tra == NULL)
|
|
|
|
{
|
|
|
|
tra = "";
|
|
|
|
}
|
|
|
|
number2[value] = std::string(tra);
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
if (value >= 0 && value <= 199)
|
|
|
|
{
|
|
|
|
int form = pElem->IntAttribute("form", 0);
|
|
|
|
number_plural_form[value] = form;
|
|
|
|
if (value < 100)
|
|
|
|
{
|
|
|
|
number_plural_form[value+100] = form;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool fix_room_coords(bool custom_level, int* roomx, int* roomy)
|
|
|
|
{
|
|
|
|
*roomx %= 100;
|
|
|
|
*roomy %= 100;
|
|
|
|
|
|
|
|
if (!custom_level && *roomx == 9 && *roomy == 4)
|
|
|
|
{
|
|
|
|
// The Tower has two rooms, unify them
|
|
|
|
*roomy = 9;
|
|
|
|
}
|
|
|
|
|
|
|
|
int max_x = MAP_MAX_X;
|
|
|
|
int max_y = MAP_MAX_Y;
|
|
|
|
if (custom_level)
|
|
|
|
{
|
|
|
|
max_x = CUSTOM_MAP_MAX_X;
|
|
|
|
max_y = CUSTOM_MAP_MAX_Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !(*roomx < 0 || *roomy < 0 || *roomx > max_x || *roomy > max_y);
|
|
|
|
}
|
|
|
|
|
2022-11-27 20:06:08 +01:00
|
|
|
static unsigned coords_to_area(int roomx, int roomy)
|
|
|
|
{
|
|
|
|
if (!fix_room_coords(false, &roomx, &roomy))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We want to know per-area how many room names are untranslated... */
|
|
|
|
enum area_letter {
|
|
|
|
_, /* None */
|
|
|
|
S, /* SS1 */
|
|
|
|
L, /* Lab */
|
|
|
|
T, /* Tower */
|
|
|
|
Y, /* SS2 */
|
|
|
|
W, /* Warp */
|
|
|
|
I, /* Intermission */
|
|
|
|
G, /* Gravitron */
|
|
|
|
F /* Final */
|
|
|
|
};
|
|
|
|
static enum area_letter area_map[MAP_MAX_Y+1][MAP_MAX_Y+1] = {
|
|
|
|
{_,L,L,L,L,L,L,L,_,T,_,_,_,W,W,W,W,W,W,W},
|
|
|
|
{_,L,L,L,L,L,L,_,_,T,_,_,_,_,W,W,W,W,W,W},
|
|
|
|
{_,_,_,_,L,_,_,_,_,T,_,_,_,_,W,W,W,W,W,W},
|
|
|
|
{_,_,_,_,L,_,_,_,_,T,_,_,S,S,S,S,W,W,W,W},
|
|
|
|
{_,_,L,L,L,_,_,_,_,T,T,T,S,S,S,S,_,_,_,_},
|
|
|
|
{_,_,_,_,_,_,_,_,_,T,Y,Y,S,S,S,S,_,_,_,_},
|
|
|
|
{_,_,_,_,_,_,_,_,_,T,Y,Y,S,S,S,S,S,_,_,_},
|
|
|
|
{_,_,_,_,_,_,_,_,_,T,Y,Y,S,S,S,S,S,S,S,_},
|
|
|
|
{_,_,_,_,_,_,_,_,_,T,_,_,_,Y,Y,S,Y,Y,Y,_},
|
|
|
|
{_,_,_,_,_,_,_,_,T,T,_,_,_,Y,Y,Y,Y,Y,Y,_},
|
|
|
|
{_,_,_,_,_,_,_,_,_,T,_,_,_,Y,Y,Y,Y,Y,Y,_},
|
|
|
|
{_,_,_,_,_,_,_,_,_,T,_,Y,Y,Y,Y,Y,Y,Y,Y,_},
|
|
|
|
{_,_,_,_,_,_,_,_,_,T,_,Y,Y,Y,Y,Y,Y,_,Y,_},
|
|
|
|
{_,_,_,_,_,_,_,_,_,T,_,Y,Y,Y,Y,Y,Y,_,Y,_},
|
|
|
|
{_,_,_,_,_,_,_,_,_,T,_,Y,Y,_,_,_,_,_,Y,_},
|
|
|
|
{_,_,_,_,_,_,_,L,_,T,_,_,_,_,_,_,_,_,_,_},
|
|
|
|
{_,_,L,L,L,L,L,L,_,T,_,_,_,_,_,_,_,_,_,_},
|
|
|
|
{_,L,L,L,L,L,L,L,_,T,_,_,_,_,_,_,_,_,_,_},
|
|
|
|
{L,L,L,L,L,_,_,L,_,T,_,_,_,_,_,_,_,_,_,_},
|
|
|
|
{L,L,L,L,L,_,_,L,_,T,_,_,_,_,_,_,_,_,_,_}
|
|
|
|
};
|
|
|
|
static bool area_map_has_final = false;
|
|
|
|
|
|
|
|
if (!area_map_has_final)
|
|
|
|
{
|
|
|
|
static const enum area_letter final_map[9][14] = {
|
|
|
|
{_,_,_,_,_,_,_,_,_,_,_,_,G,F},
|
|
|
|
{_,_,_,_,_,_,_,_,_,_,_,_,G,F},
|
|
|
|
{_,_,_,_,_,_,_,_,_,_,_,_,G,F},
|
|
|
|
{F,F,F,F,F,F,F,F,F,F,_,_,G,F},
|
|
|
|
{F,F,F,F,F,_,F,F,F,F,_,_,G,F},
|
|
|
|
{_,_,_,_,_,_,_,_,F,F,F,F,F,F},
|
|
|
|
{_,_,_,_,_,F,F,F,F,F,F,_,_,_},
|
|
|
|
{_,_,_,_,_,_,_,_,_,_,_,_,_,_},
|
|
|
|
{I,I,I,I,I,I,I,I,I,I,I,I,I,I}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int y = 0; y < 9; y++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < 14; x++)
|
|
|
|
{
|
|
|
|
area_map[MAP_MAX_Y+1 - 9 + y][MAP_MAX_X+1 - 14 + x] = final_map[y][x];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
area_map_has_final = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (area_map[roomy][roomx] == 0)
|
|
|
|
{
|
|
|
|
vlog_error("LocalizationStorage: Room %d,%d has no area associated with it", roomx, roomy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return area_map[roomy][roomx];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_left_counter(const char* old_text, const char* new_text, int* counter, int* counter_area)
|
2022-12-29 05:23:20 +01:00
|
|
|
{
|
|
|
|
bool now_filled = new_text[0] != '\0';
|
|
|
|
if ((old_text == NULL || old_text[0] == '\0') && now_filled)
|
|
|
|
{
|
|
|
|
(*counter)--;
|
2022-11-27 20:06:08 +01:00
|
|
|
if (counter_area != NULL)
|
|
|
|
{
|
|
|
|
(*counter_area)--;
|
|
|
|
}
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
else if (old_text != NULL && old_text[0] != '\0' && !now_filled)
|
|
|
|
{
|
|
|
|
(*counter)++;
|
2022-11-27 20:06:08 +01:00
|
|
|
if (counter_area != NULL)
|
|
|
|
{
|
|
|
|
(*counter_area)++;
|
|
|
|
}
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool store_roomname_translation(bool custom_level, int roomx, int roomy, const char* tra, const char* explanation)
|
|
|
|
{
|
|
|
|
if (!fix_room_coords(custom_level, &roomx, &roomy))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have some arrays filled with pointers, and we need to change those pointers */
|
|
|
|
const char** ptr_translation;
|
|
|
|
const char** ptr_explanation;
|
|
|
|
int* ptr_n_untranslated;
|
2022-11-27 20:06:08 +01:00
|
|
|
int* ptr_n_untranslated_area = NULL;
|
2022-12-29 05:23:20 +01:00
|
|
|
int* ptr_n_unexplained;
|
|
|
|
if (custom_level)
|
|
|
|
{
|
|
|
|
ptr_translation = &translation_roomnames_custom[roomy][roomx];
|
|
|
|
ptr_explanation = &explanation_roomnames_custom[roomy][roomx];
|
|
|
|
ptr_n_untranslated = &n_untranslated_roomnames_custom;
|
|
|
|
ptr_n_unexplained = &n_unexplained_roomnames_custom;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ptr_translation = &translation_roomnames[roomy][roomx];
|
|
|
|
ptr_explanation = &explanation_roomnames[roomy][roomx];
|
|
|
|
ptr_n_untranslated = &n_untranslated_roomnames;
|
2022-11-27 20:06:08 +01:00
|
|
|
ptr_n_untranslated_area = &n_untranslated_roomnames_area[coords_to_area(roomx, roomy)];
|
2022-12-29 05:23:20 +01:00
|
|
|
ptr_n_unexplained = &n_unexplained_roomnames;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tra != NULL)
|
|
|
|
{
|
2022-11-27 20:06:08 +01:00
|
|
|
update_left_counter(*ptr_translation, tra, ptr_n_untranslated, ptr_n_untranslated_area);
|
2022-12-29 05:23:20 +01:00
|
|
|
*ptr_translation = textbook_store(&textbook_main, tra);
|
|
|
|
}
|
|
|
|
if (explanation != NULL)
|
|
|
|
{
|
2022-11-27 20:06:08 +01:00
|
|
|
update_left_counter(*ptr_explanation, explanation, ptr_n_unexplained, NULL);
|
2022-12-29 05:23:20 +01:00
|
|
|
*ptr_explanation = textbook_store(&textbook_main, explanation);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-08-27 14:30:10 +02:00
|
|
|
static void loadtext_roomnames(bool custom_level, bool check_max)
|
2022-12-29 05:23:20 +01:00
|
|
|
{
|
|
|
|
tinyxml2::XMLDocument doc;
|
|
|
|
tinyxml2::XMLHandle hDoc(&doc);
|
|
|
|
tinyxml2::XMLElement* pElem;
|
|
|
|
|
|
|
|
std::string doc_path;
|
|
|
|
std::string doc_path_asset;
|
|
|
|
bool valid_custom_level = get_level_lang_path(custom_level, "roomnames", doc_path, doc_path_asset);
|
|
|
|
if (custom_level && !valid_custom_level)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!load_lang_doc(doc_path, doc, get_level_lang_code(custom_level), doc_path_asset))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* original = get_level_original_lang(hDoc);
|
|
|
|
|
|
|
|
FOR_EACH_XML_ELEMENT(hDoc, pElem)
|
|
|
|
{
|
|
|
|
EXPECT_ELEM(pElem, "roomname");
|
|
|
|
|
|
|
|
int x = pElem->IntAttribute("x", -1);
|
|
|
|
int y = pElem->IntAttribute("y", -1);
|
|
|
|
|
|
|
|
if (custom_level)
|
|
|
|
{
|
|
|
|
/* Extra safeguard: make sure the original room name matches! */
|
|
|
|
const char* original_roomname = pElem->Attribute(original);
|
|
|
|
if (original_roomname == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2023-08-23 19:51:11 +02:00
|
|
|
|
2022-12-29 05:23:20 +01:00
|
|
|
const RoomProperty* const room = cl.getroomprop(x, y);
|
|
|
|
if (SDL_strcmp(original_roomname, room->roomname.c_str()) != 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
n_untranslated_roomnames_custom++;
|
|
|
|
n_unexplained_roomnames_custom++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n_untranslated_roomnames++;
|
|
|
|
n_unexplained_roomnames++;
|
2022-11-27 20:06:08 +01:00
|
|
|
n_untranslated_roomnames_area[coords_to_area(x, y)]++;
|
2023-08-27 14:30:10 +02:00
|
|
|
|
|
|
|
if (check_max)
|
|
|
|
{
|
|
|
|
max_check_string(pElem->Attribute("translation"), "40");
|
|
|
|
}
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
store_roomname_translation(
|
|
|
|
custom_level,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
pElem->Attribute("translation"),
|
|
|
|
show_translator_menu ? pElem->Attribute("explanation") : NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-27 14:30:10 +02:00
|
|
|
static void loadtext_roomnames_special(bool check_max)
|
2022-12-29 05:23:20 +01:00
|
|
|
{
|
|
|
|
tinyxml2::XMLDocument doc;
|
|
|
|
tinyxml2::XMLHandle hDoc(&doc);
|
|
|
|
tinyxml2::XMLElement* pElem;
|
|
|
|
|
|
|
|
if (!load_lang_doc("roomnames_special", doc))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FOR_EACH_XML_ELEMENT(hDoc, pElem)
|
|
|
|
{
|
|
|
|
EXPECT_ELEM(pElem, "roomname");
|
|
|
|
|
|
|
|
map_store_translation(
|
|
|
|
&textbook_main,
|
|
|
|
map_translation_roomnames_special,
|
|
|
|
pElem->Attribute("english"),
|
|
|
|
pElem->Attribute("translation")
|
|
|
|
);
|
|
|
|
|
2023-08-27 14:30:10 +02:00
|
|
|
if (check_max)
|
|
|
|
{
|
|
|
|
max_check_string(pElem->Attribute("translation"), "40");
|
|
|
|
}
|
|
|
|
|
2022-12-29 05:23:20 +01:00
|
|
|
tally_untranslated(pElem->Attribute("translation"), &n_untranslated[UNTRANSLATED_ROOMNAMES_SPECIAL]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadtext_custom(const char* custom_path)
|
|
|
|
{
|
|
|
|
resettext_custom(false);
|
|
|
|
if (custom_level_path == NULL && custom_path != NULL)
|
|
|
|
{
|
|
|
|
custom_level_path = SDL_strdup(custom_path);
|
|
|
|
}
|
|
|
|
loadtext_cutscenes(true);
|
2023-08-27 14:30:10 +02:00
|
|
|
loadtext_roomnames(true, false);
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void loadtext(bool check_max)
|
|
|
|
{
|
|
|
|
resettext(false);
|
|
|
|
loadmeta(langmeta);
|
|
|
|
|
|
|
|
if (lang == "en")
|
|
|
|
{
|
|
|
|
if (show_translator_menu)
|
|
|
|
{
|
|
|
|
// We may still need the room name explanations
|
2023-08-27 14:30:10 +02:00
|
|
|
loadtext_roomnames(false, false);
|
2022-12-29 05:23:20 +01:00
|
|
|
n_untranslated_roomnames = 0;
|
2022-11-27 20:06:08 +01:00
|
|
|
SDL_zeroa(n_untranslated_roomnames_area);
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
loadtext_numbers();
|
|
|
|
loadtext_strings(check_max);
|
|
|
|
loadtext_strings_plural(check_max);
|
|
|
|
loadtext_cutscenes(false);
|
2023-08-27 14:30:10 +02:00
|
|
|
loadtext_roomnames(false, check_max);
|
|
|
|
loadtext_roomnames_special(check_max);
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (custom_level_path != NULL)
|
|
|
|
{
|
|
|
|
loadtext_custom(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadlanguagelist(void)
|
|
|
|
{
|
|
|
|
// Load the list of languages for the language screen
|
|
|
|
languagelist.clear();
|
|
|
|
|
|
|
|
size_t opt = 0;
|
|
|
|
languagelist_curlang = 0;
|
2023-01-11 02:57:31 +01:00
|
|
|
EnumHandle handle = {};
|
|
|
|
const char* code;
|
|
|
|
while ((code = FILESYSTEM_enumerateLanguageCodes(&handle)) != NULL)
|
2022-12-29 05:23:20 +01:00
|
|
|
{
|
|
|
|
LangMeta meta;
|
2023-01-11 02:57:31 +01:00
|
|
|
loadmeta(meta, code);
|
2022-12-29 05:23:20 +01:00
|
|
|
if (meta.active)
|
|
|
|
{
|
|
|
|
languagelist.push_back(meta);
|
|
|
|
|
2023-01-11 02:57:31 +01:00
|
|
|
if (SDL_strcmp(lang.c_str(), code) == 0)
|
2022-12-29 05:23:20 +01:00
|
|
|
{
|
|
|
|
languagelist_curlang = opt;
|
|
|
|
}
|
|
|
|
opt++;
|
|
|
|
}
|
|
|
|
}
|
2023-01-11 02:57:31 +01:00
|
|
|
FILESYSTEM_freeEnumerate(&handle);
|
2022-12-29 05:23:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* map_lookup_text(hashmap* map, const char* eng, const char* fallback)
|
|
|
|
{
|
|
|
|
uintptr_t ptr_tra;
|
2023-03-05 21:42:21 +01:00
|
|
|
bool found = hashmap_get(map, eng, SDL_strlen(eng), &ptr_tra);
|
2022-12-29 05:23:20 +01:00
|
|
|
const char* tra = (const char*) ptr_tra;
|
|
|
|
|
|
|
|
if (found && tra != NULL && tra[0] != '\0')
|
|
|
|
{
|
|
|
|
return tra;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* add_disambiguator(char disambiguator, const char* original_string, size_t* ext_alloc_len)
|
|
|
|
{
|
|
|
|
/* Create a version of the string prefixed with the given byte.
|
|
|
|
* This byte is used when the English string is just not enough to identify the correct translation.
|
|
|
|
* It's needed to store plural forms, and when the same text appears multiple times in a cutscene.
|
2022-12-31 04:37:45 +01:00
|
|
|
* Caller must VVV_free. */
|
2022-12-29 05:23:20 +01:00
|
|
|
|
|
|
|
size_t alloc_len = 1+SDL_strlen(original_string)+1;
|
|
|
|
|
|
|
|
char* alloc = (char*) SDL_malloc(alloc_len);
|
|
|
|
if (alloc == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
alloc[0] = disambiguator;
|
|
|
|
SDL_memcpy(&alloc[1], original_string, alloc_len-1);
|
|
|
|
|
|
|
|
if (ext_alloc_len != NULL)
|
|
|
|
{
|
|
|
|
*ext_alloc_len = alloc_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace loc */
|