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.
This commit is contained in:
Dav999-v
2022-12-01 01:27:30 +01:00
committed by Misa Elizabeth Kai
parent d147206c54
commit 795bdf886b
11 changed files with 137 additions and 34 deletions

View File

@@ -88,7 +88,31 @@ static void sync_lang_file(const std::string& langcode)
const char* eng = pElem->Attribute("english");
if (eng != NULL)
{
pElem->SetAttribute("translation", map_lookup_text(map_translation, eng, ""));
char textcase = pElem->UnsignedAttribute("case", 0);
const char* tra;
if (textcase == 0)
{
tra = map_lookup_text(map_translation, eng, "");
}
else
{
char* eng_prefixed = add_disambiguator(textcase, eng, NULL);
if (eng_prefixed == NULL)
{
/* Are we out of memory? Stop, don't blank our language files... */
return;
}
/* Note the fallback: if this string used to not be cased and now it is,
* simply fill in the old single variant we already had. */
tra = map_lookup_text(
map_translation,
eng_prefixed,
map_lookup_text(map_translation, eng, "")
);
SDL_free(eng_prefixed);
}
pElem->SetAttribute("translation", tra);
}
}
@@ -125,7 +149,7 @@ static void sync_lang_file(const std::string& langcode)
char* key = add_disambiguator(form_id+1, eng_plural, NULL);
if (key == NULL)
{
/* Are we out of memory? Stop, don't blank our language files... */
/* Out of memory or something, stop */
return;
}