Pixel-Composer/scripts/locale_data/locale_data.gml

157 lines
3.6 KiB
Text
Raw Normal View History

2023-02-14 02:48:33 +01:00
#region locale
globalvar LOCALE, TEST_LOCALE, LOCALE_USE_DEFAULT;
2023-02-14 02:48:33 +01:00
LOCALE = {}
TEST_LOCALE = false;
LOCALE_USE_DEFAULT = true;
2023-02-14 02:48:33 +01:00
function __initLocale() {
2023-06-05 18:27:53 +02:00
var lfile = $"data/locale/en.zip";
2023-06-04 18:28:29 +02:00
var root = $"{DIRECTORY}Locale";
2023-02-14 02:48:33 +01:00
if(!directory_exists(root))
directory_create(root);
2023-06-05 18:27:53 +02:00
zip_unzip(lfile, root);
2023-02-14 02:48:33 +01:00
2023-06-04 18:28:29 +02:00
loadLocale();
}
2023-06-05 18:27:53 +02:00
function __locale_file(file) {
2023-10-31 05:30:42 +01:00
var dirr = $"{DIRECTORY}Locale/{PREFERENCES.local}";
2023-06-05 18:27:53 +02:00
if(!directory_exists(dirr) || !file_exists(dirr + file))
dirr = $"{DIRECTORY}Locale/en";
return dirr + file;
}
2023-06-04 18:28:29 +02:00
function loadLocale() {
2023-06-05 18:27:53 +02:00
LOCALE.word = json_load_struct(__locale_file("/words.json"));
LOCALE.ui = json_load_struct(__locale_file("/UI.json"));
LOCALE.node = json_load_struct(__locale_file("/nodes.json"));
2023-06-05 19:41:01 +02:00
LOCALE.config = json_load_struct(__locale_file("/config.json"));
2023-06-05 18:27:53 +02:00
2023-10-31 05:30:42 +01:00
var fontDir = $"{DIRECTORY}Locale/{PREFERENCES.local}/fonts/";
2023-06-05 18:27:53 +02:00
LOCALE.fontDir = directory_exists(fontDir)? fontDir : noone;
2023-05-07 20:55:13 +02:00
2023-06-05 18:27:53 +02:00
print("FONT DIR: " + fontDir);
2023-06-04 18:28:29 +02:00
}
function __txtx(key, def = "") {
2023-11-08 08:38:04 +01:00
INLINE
2023-07-28 19:41:57 +02:00
if(key == "") return "";
2023-09-28 13:15:29 +02:00
if(TEST_LOCALE) {
if(!struct_has(LOCALE.word, key) && !struct_has(LOCALE.ui, key)) {
2023-09-28 13:15:29 +02:00
show_debug_message($"LOCALE: \"{key}\": \"{def}\",");
return def;
}
return "";
2023-09-28 13:15:29 +02:00
}
if(LOCALE_USE_DEFAULT) return def;
if(struct_has(LOCALE.word, key)) return LOCALE.word[$ key];
if(struct_has(LOCALE.ui, key)) return LOCALE.ui[$ key];
2023-05-07 20:55:13 +02:00
2023-06-05 18:27:53 +02:00
return def;
2023-02-14 02:48:33 +01:00
}
2023-06-04 18:28:29 +02:00
function __txt(txt, prefix = "") {
2023-11-08 08:38:04 +01:00
INLINE
2023-07-28 19:41:57 +02:00
if(txt == "") return "";
2023-06-04 18:28:29 +02:00
var key = string_lower(txt);
key = string_replace_all(key, " ", "_");
if(TEST_LOCALE) {
if(!struct_has(LOCALE.word, key) && !struct_has(LOCALE.ui, key)) {
show_debug_message($"LOCALE: \"{key}\": \"{txt}\",");
return txt;
}
return "";
}
if(LOCALE_USE_DEFAULT) return txt;
2023-06-04 18:28:29 +02:00
return __txtx(prefix + key, txt);
2023-02-14 02:48:33 +01:00
}
2023-06-05 18:27:53 +02:00
function __txta(txt) {
var _txt = __txt(txt);
for(var i = 1; i < argument_count; i++)
_txt = string_replace_all(_txt, "{" + string(i) + "}", string(argument[i]));
return _txt;
}
2023-06-17 14:30:49 +02:00
function __txt_node_name(node, def = "") {
2023-11-08 08:38:04 +01:00
INLINE
2023-07-28 19:41:57 +02:00
if(LOCALE_USE_DEFAULT) return def;
if(!struct_has(LOCALE.node, node))
return def;
if(TEST_LOCALE) return "";
2023-06-17 14:30:49 +02:00
return def;
2023-06-05 18:27:53 +02:00
}
function __txt_node_tooltip(node, def = "") {
2023-11-08 08:38:04 +01:00
INLINE
2023-07-28 19:41:57 +02:00
if(LOCALE_USE_DEFAULT) return def;
if(!struct_has(LOCALE.node, node))
return def;
if(TEST_LOCALE) return "";
return LOCALE.node[$ node].tooltip;
2023-06-05 18:27:53 +02:00
}
function __txt_junction_name(node, type, index, def = "") {
2023-11-08 08:38:04 +01:00
INLINE
2023-07-28 19:41:57 +02:00
if(LOCALE_USE_DEFAULT) return def;
2023-06-05 18:27:53 +02:00
if(!struct_has(LOCALE.node, node))
return def;
var nde = LOCALE.node[$ node];
var lst = type == JUNCTION_CONNECT.input? nde.inputs : nde.outputs;
if(index >= array_length(lst)) return def;
if(TEST_LOCALE) return "";
2023-06-05 18:27:53 +02:00
return lst[index].name;
}
function __txt_junction_tooltip(node, type, index, def = "") {
2023-11-08 08:38:04 +01:00
INLINE
2023-07-28 19:41:57 +02:00
if(LOCALE_USE_DEFAULT) return def;
2023-06-05 18:27:53 +02:00
if(!struct_has(LOCALE.node, node))
return def;
var nde = LOCALE.node[$ node];
var lst = type == JUNCTION_CONNECT.input? nde.inputs : nde.outputs;
if(index >= array_length(lst)) return def;
if(TEST_LOCALE) return "";
2023-06-05 18:27:53 +02:00
return lst[index].tooltip;
}
function __txt_junction_data(node, type, index, def = []) {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-07 09:09:18 +02:00
return def;
if(!struct_has(LOCALE.node, node))
return def;
var nde = LOCALE.node[$ node];
var lst = type == JUNCTION_CONNECT.input? nde.inputs : nde.outputs;
if(index >= array_length(lst)) return def;
if(!struct_has(lst[index], "display_data"))
return def;
if(TEST_LOCALE) return [ "" ];
return lst[index].display_data;
}
2023-02-14 02:48:33 +01:00
#endregion