mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-10-01 19:37:55 +03:00
Allow overriding hard-coded strings by system3.ini
Some strings ("戻る" and "次のページ" in menu, character names in DPS)
are not included in game files but are hard-coded in the executable.
Now those strings can be overridden by adding [string] section to
system3.ini. For example, system3.ini for English translation of DPS
may look like this:
[config]
game = dps
title = D.P.S - Dream Program System
[string]
back = Back
next_page = Next Page
dps_custom = Custom
dps_linus = Linus
dps_katsumi = Katsumi
dps_yumiko = Yumiko
dps_itsumi = Itsumi
dps_hitomi = Hitomi
dps_mariko = Mariko
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "encoding.h"
|
||||
|
||||
#define INIFILENAME "system3.ini"
|
||||
|
||||
@@ -53,6 +54,13 @@ std::pair<char*, char*> parse_keyval(char *line)
|
||||
return { trim(line), trim(eq + 1) };
|
||||
}
|
||||
|
||||
void init_string(std::string& s, Encoding* encoding, const char *dflt)
|
||||
{
|
||||
char *encoded = encoding->fromUtf8(s.empty() ? dflt : s.c_str());
|
||||
s = encoded;
|
||||
free(encoded);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Config::Config(int argc, char *argv[])
|
||||
@@ -97,6 +105,7 @@ void Config::load_ini()
|
||||
enum {
|
||||
NO_SECTION,
|
||||
CONFIG,
|
||||
STRING,
|
||||
} current_section = NO_SECTION;
|
||||
|
||||
char line[256];
|
||||
@@ -109,6 +118,8 @@ void Config::load_ini()
|
||||
if (sscanf(line, "[%[^]]]", val)) {
|
||||
if (strcasecmp(val, "config") == 0)
|
||||
current_section = CONFIG;
|
||||
else if (strcasecmp(val, "string") == 0)
|
||||
current_section = STRING;
|
||||
else
|
||||
WARNING(INIFILENAME ":%d Unknown section \"%s\"", lineno, val);
|
||||
} else if (current_section == CONFIG) {
|
||||
@@ -136,9 +147,51 @@ void Config::load_ini()
|
||||
title = val;
|
||||
else
|
||||
WARNING(INIFILENAME ":%d unknown key '%s'", lineno, key);
|
||||
} else if (current_section == STRING) {
|
||||
char *key, *val;
|
||||
std::tie(key, val) = parse_keyval(line);
|
||||
if (!key && !is_empty_line(line)) {
|
||||
WARNING(INIFILENAME ":%d parse error", lineno);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(key, "back"))
|
||||
strings.back = val;
|
||||
else if (!strcasecmp(key, "next_page"))
|
||||
strings.next_page = val;
|
||||
else if (!strcasecmp(key, "dps_custom"))
|
||||
strings.dps_custom = val;
|
||||
else if (!strcasecmp(key, "dps_linus"))
|
||||
strings.dps_linus = val;
|
||||
else if (!strcasecmp(key, "dps_katsumi"))
|
||||
strings.dps_katsumi = val;
|
||||
else if (!strcasecmp(key, "dps_yumiko"))
|
||||
strings.dps_yumiko = val;
|
||||
else if (!strcasecmp(key, "dps_itsumi"))
|
||||
strings.dps_itsumi = val;
|
||||
else if (!strcasecmp(key, "dps_hitomi"))
|
||||
strings.dps_hitomi = val;
|
||||
else if (!strcasecmp(key, "dps_mariko"))
|
||||
strings.dps_mariko = val;
|
||||
else
|
||||
WARNING(INIFILENAME ":%d unknown key '%s'", lineno, key);
|
||||
} else if (!is_empty_line(line)) {
|
||||
WARNING(INIFILENAME ":%d parse error", lineno);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
Strings Config::get_strings(Encoding* encoding, bool english) const
|
||||
{
|
||||
Strings strs = strings;
|
||||
init_string(strs.back, encoding, english ? "Back" : u8"戻る");
|
||||
init_string(strs.next_page, encoding, english ? "Next Page" : u8"次のページ");
|
||||
init_string(strs.dps_custom, encoding, u8"カスタム");
|
||||
init_string(strs.dps_linus, encoding, u8"リーナス");
|
||||
init_string(strs.dps_katsumi, encoding, u8"かつみ");
|
||||
init_string(strs.dps_yumiko, encoding, u8"由美子");
|
||||
init_string(strs.dps_itsumi, encoding, u8"いつみ");
|
||||
init_string(strs.dps_hitomi, encoding, u8"ひとみ");
|
||||
init_string(strs.dps_mariko, encoding, u8"真理子");
|
||||
return strs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user