mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49:43 +01:00
Write max_local to language files during sync
If your language has a bigger font, the max attribute isn't really helpful to you as a translator, so the sync feature adds a special max_local attribute which is accurate to the font size. This was already documented in advance. If used, we now also write an attribute in the root tag of strings.xml and strings_plural.xml, that looks like max_local_for="12x12". I decided to add this attribute after finding out the Excel macros would be really hard to change to only show a max_local column if it is ever used (it'd need to look ahead through the strings until it finds a string with a max, or remove the column if no string has used it), but it's also a convenience for translators.
This commit is contained in:
parent
11b372c741
commit
17d3c756c7
3 changed files with 64 additions and 1 deletions
|
@ -16,6 +16,43 @@
|
||||||
namespace loc
|
namespace loc
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static void write_max_local(tinyxml2::XMLElement* pElem, uint8_t glyph_w, uint8_t glyph_h)
|
||||||
|
{
|
||||||
|
const char* max;
|
||||||
|
if ((max = pElem->Attribute("max")) != NULL)
|
||||||
|
{
|
||||||
|
unsigned short max_w, max_h, max_local_w, max_local_h;
|
||||||
|
if (parse_max(max, &max_w, &max_h))
|
||||||
|
{
|
||||||
|
max_local_w = (max_w*8) / glyph_w;
|
||||||
|
max_local_h = (max_h*10) / SDL_max(10, glyph_h);
|
||||||
|
|
||||||
|
if (max_local_h == 0)
|
||||||
|
{
|
||||||
|
max_local_h = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buf[16];
|
||||||
|
if (max_h == 1)
|
||||||
|
{
|
||||||
|
SDL_snprintf(buf, sizeof(buf), "%d", max_local_w);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SDL_snprintf(buf, sizeof(buf), "%d*%d", max_local_w, max_local_h);
|
||||||
|
}
|
||||||
|
pElem->SetAttribute("max_local", buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void write_max_local_decl(tinyxml2::XMLDocument* doc, uint8_t glyph_w, uint8_t glyph_h)
|
||||||
|
{
|
||||||
|
char buf[16];
|
||||||
|
SDL_snprintf(buf, sizeof(buf), "%dx%d", glyph_w, glyph_h);
|
||||||
|
doc->FirstChildElement()->SetAttribute("max_local_for", buf);
|
||||||
|
}
|
||||||
|
|
||||||
static void sync_lang_file(const std::string& langcode)
|
static void sync_lang_file(const std::string& langcode)
|
||||||
{
|
{
|
||||||
/* Update translation files for the given language with new strings from templates.
|
/* Update translation files for the given language with new strings from templates.
|
||||||
|
@ -26,6 +63,10 @@ static void sync_lang_file(const std::string& langcode)
|
||||||
lang = langcode;
|
lang = langcode;
|
||||||
loadtext(false);
|
loadtext(false);
|
||||||
|
|
||||||
|
uint8_t glyph_w = 8, glyph_h = 8;
|
||||||
|
font::glyph_dimensions(PR_FONT_IDX(langmeta.font_idx), &glyph_w, &glyph_h);
|
||||||
|
bool max_local_needed = glyph_w != 8 || glyph_h != 8;
|
||||||
|
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
tinyxml2::XMLHandle hDoc(&doc);
|
tinyxml2::XMLHandle hDoc(&doc);
|
||||||
tinyxml2::XMLElement* pElem;
|
tinyxml2::XMLElement* pElem;
|
||||||
|
@ -86,6 +127,11 @@ static void sync_lang_file(const std::string& langcode)
|
||||||
|
|
||||||
if (load_lang_doc("strings", doc, "en"))
|
if (load_lang_doc("strings", doc, "en"))
|
||||||
{
|
{
|
||||||
|
if (max_local_needed)
|
||||||
|
{
|
||||||
|
write_max_local_decl(&doc, glyph_w, glyph_h);
|
||||||
|
}
|
||||||
|
|
||||||
FOR_EACH_XML_ELEMENT(hDoc, pElem)
|
FOR_EACH_XML_ELEMENT(hDoc, pElem)
|
||||||
{
|
{
|
||||||
EXPECT_ELEM(pElem, "string");
|
EXPECT_ELEM(pElem, "string");
|
||||||
|
@ -119,6 +165,11 @@ static void sync_lang_file(const std::string& langcode)
|
||||||
|
|
||||||
pElem->SetAttribute("translation", tra);
|
pElem->SetAttribute("translation", tra);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (max_local_needed)
|
||||||
|
{
|
||||||
|
write_max_local(pElem, glyph_w, glyph_h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FILESYSTEM_saveTiXml2Document((langcode + "/strings.xml").c_str(), doc);
|
FILESYSTEM_saveTiXml2Document((langcode + "/strings.xml").c_str(), doc);
|
||||||
|
@ -134,10 +185,20 @@ static void sync_lang_file(const std::string& langcode)
|
||||||
form_id_used[number_plural_form[num]] = true;
|
form_id_used[number_plural_form[num]] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (max_local_needed)
|
||||||
|
{
|
||||||
|
write_max_local_decl(&doc, glyph_w, glyph_h);
|
||||||
|
}
|
||||||
|
|
||||||
FOR_EACH_XML_ELEMENT(hDoc, pElem)
|
FOR_EACH_XML_ELEMENT(hDoc, pElem)
|
||||||
{
|
{
|
||||||
EXPECT_ELEM(pElem, "string");
|
EXPECT_ELEM(pElem, "string");
|
||||||
|
|
||||||
|
if (max_local_needed)
|
||||||
|
{
|
||||||
|
write_max_local(pElem, glyph_w, glyph_h);
|
||||||
|
}
|
||||||
|
|
||||||
pElem->DeleteChildren();
|
pElem->DeleteChildren();
|
||||||
|
|
||||||
const char* eng_plural = pElem->Attribute("english_plural");
|
const char* eng_plural = pElem->Attribute("english_plural");
|
||||||
|
|
|
@ -252,7 +252,7 @@ void resettext(bool final_shutdown)
|
||||||
resettext_custom(final_shutdown);
|
resettext_custom(final_shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parse_max(const char* max, unsigned short* max_w, unsigned short* max_h)
|
bool parse_max(const char* max, unsigned short* max_w, unsigned short* max_h)
|
||||||
{
|
{
|
||||||
/* Parse a max string, like "33" or "33*3", into two shorts.
|
/* 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. */
|
* Returns true if successful and max_w/max_h have gotten valid values, false otherwise. */
|
||||||
|
|
|
@ -68,6 +68,8 @@ unsigned char form_for_count(int n);
|
||||||
void unloadtext_custom(void);
|
void unloadtext_custom(void);
|
||||||
void resettext(bool final_shutdown);
|
void resettext(bool final_shutdown);
|
||||||
|
|
||||||
|
bool parse_max(const char* max, unsigned short* max_w, unsigned short* max_h);
|
||||||
|
|
||||||
const char* get_level_original_lang(tinyxml2::XMLHandle& hDoc);
|
const char* get_level_original_lang(tinyxml2::XMLHandle& hDoc);
|
||||||
|
|
||||||
bool store_roomname_translation(bool custom_level, int roomx, int roomy, const char* tra, const char* explanation);
|
bool store_roomname_translation(bool custom_level, int roomx, int roomy, const char* tra, const char* explanation);
|
||||||
|
|
Loading…
Reference in a new issue