2023-02-14 02:48:33 +01:00
|
|
|
#region locale
|
2023-11-19 09:05:42 +01:00
|
|
|
globalvar LOCALE, TEST_LOCALE, LOCALE_DEF;
|
2023-12-11 09:59:58 +01:00
|
|
|
LOCALE = {
|
|
|
|
fontDir: "",
|
|
|
|
config: { per_character_line_break: false },
|
|
|
|
};
|
2023-09-28 15:10:41 +02:00
|
|
|
TEST_LOCALE = false;
|
2023-11-19 09:05:42 +01:00
|
|
|
LOCALE_DEF = true;
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
function __initLocale() { #region
|
2023-12-08 10:11:48 +01: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
|
|
|
|
2023-11-18 03:47:11 +01:00
|
|
|
directory_verify(root);
|
|
|
|
if(check_version($"{root}/version"))
|
|
|
|
zip_unzip(lfile, root);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-12-11 09:59:58 +01:00
|
|
|
if(LOCALE_DEF) return;
|
|
|
|
|
2023-06-04 18:28:29 +02:00
|
|
|
loadLocale();
|
2023-11-19 09:05:42 +01:00
|
|
|
} #endregion
|
2023-06-04 18:28:29 +02:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
function __locale_file(file) { #region
|
2023-10-31 05:30:42 +01:00
|
|
|
var dirr = $"{DIRECTORY}Locale/{PREFERENCES.local}";
|
2023-12-08 03:50:09 +01:00
|
|
|
if(!directory_exists(dirr) || !file_exists_empty(dirr + file))
|
2023-06-05 18:27:53 +02:00
|
|
|
dirr = $"{DIRECTORY}Locale/en";
|
|
|
|
return dirr + file;
|
2023-11-19 09:05:42 +01:00
|
|
|
} #endregion
|
2023-06-05 18:27:53 +02:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
function loadLocale() { #region
|
2023-12-11 09:59:58 +01: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-11-19 09:05:42 +01:00
|
|
|
} #endregion
|
2023-06-04 18:28:29 +02:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
function __txtx(key, def = "") { #region
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-07-28 19:41:57 +02:00
|
|
|
|
2023-12-11 05:45:12 +01:00
|
|
|
if(LOCALE_DEF) return def;
|
|
|
|
|
2023-11-04 12:10:58 +01:00
|
|
|
if(key == "") return "";
|
2023-09-28 13:15:29 +02:00
|
|
|
if(TEST_LOCALE) {
|
2023-09-28 15:10:41 +02:00
|
|
|
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}\",");
|
2023-11-04 12:10:58 +01:00
|
|
|
return def;
|
2023-09-28 15:10:41 +02:00
|
|
|
}
|
|
|
|
return "";
|
2023-09-28 13:15:29 +02:00
|
|
|
}
|
|
|
|
|
2023-11-04 12:10:58 +01:00
|
|
|
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-11-19 09:05:42 +01:00
|
|
|
} #endregion
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
function __txt(txt, prefix = "") { #region
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-07-28 19:41:57 +02:00
|
|
|
|
2023-12-11 05:45:12 +01:00
|
|
|
if(LOCALE_DEF) return txt;
|
|
|
|
|
2023-11-04 12:10:58 +01:00
|
|
|
if(txt == "") return "";
|
2023-06-04 18:28:29 +02:00
|
|
|
var key = string_lower(txt);
|
|
|
|
key = string_replace_all(key, " ", "_");
|
|
|
|
|
2023-11-04 12:10:58 +01:00
|
|
|
if(TEST_LOCALE) {
|
|
|
|
if(!struct_has(LOCALE.word, key) && !struct_has(LOCALE.ui, key)) {
|
|
|
|
show_debug_message($"LOCALE: \"{key}\": \"{txt}\",");
|
|
|
|
return txt;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2023-12-11 05:45:12 +01:00
|
|
|
|
2023-06-04 18:28:29 +02:00
|
|
|
return __txtx(prefix + key, txt);
|
2023-11-19 09:05:42 +01:00
|
|
|
} #endregion
|
2023-06-05 18:27:53 +02:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
function __txta(txt) { #region
|
2023-09-28 15:10:41 +02:00
|
|
|
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-11-19 09:05:42 +01:00
|
|
|
} #endregion
|
2023-09-28 15:10:41 +02:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
function __txt_node_name(node, def = "") { #region
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-07-28 19:41:57 +02:00
|
|
|
|
2023-12-11 05:45:12 +01:00
|
|
|
if(LOCALE_DEF) return def;
|
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
if(TEST_LOCALE) {
|
|
|
|
if(!struct_has(LOCALE.node, node)) {
|
|
|
|
show_debug_message($"LOCALE [NODE]: \"{node}\": \"{def}\",");
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2023-09-28 15:10:41 +02:00
|
|
|
if(!struct_has(LOCALE.node, node))
|
|
|
|
return def;
|
2023-11-19 09:05:42 +01:00
|
|
|
|
|
|
|
return LOCALE.node[$ node].name;
|
|
|
|
} #endregion
|
2023-06-05 18:27:53 +02:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
function __txt_node_tooltip(node, def = "") { #region
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-12-11 05:45:12 +01:00
|
|
|
|
|
|
|
if(LOCALE_DEF) return def;
|
2023-11-19 09:05:42 +01:00
|
|
|
|
|
|
|
if(TEST_LOCALE) {
|
|
|
|
if(!struct_has(LOCALE.node, node)) {
|
|
|
|
show_debug_message($"LOCALE [TIP]: \"{node}\": \"{def}\",");
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2023-07-28 19:41:57 +02:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
if(!struct_has(LOCALE.node, node))
|
2023-09-28 15:10:41 +02:00
|
|
|
return def;
|
2023-11-19 09:05:42 +01:00
|
|
|
|
2023-09-28 15:10:41 +02:00
|
|
|
return LOCALE.node[$ node].tooltip;
|
2023-11-19 09:05:42 +01:00
|
|
|
} #endregion
|
2023-06-05 18:27:53 +02:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
function __txt_junction_name(node, type, index, def = "") { #region
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-07-28 19:41:57 +02:00
|
|
|
|
2023-12-11 05:45:12 +01:00
|
|
|
if(LOCALE_DEF) return def;
|
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
if(TEST_LOCALE) {
|
|
|
|
if(!struct_has(LOCALE.node, node)) {
|
|
|
|
show_debug_message($"LOCALE [JNAME]: \"{node}\": \"{def}\",");
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!struct_has(LOCALE.node, node))
|
2023-06-05 18:27:53 +02:00
|
|
|
return def;
|
|
|
|
|
|
|
|
var nde = LOCALE.node[$ node];
|
|
|
|
var lst = type == JUNCTION_CONNECT.input? nde.inputs : nde.outputs;
|
|
|
|
if(index >= array_length(lst)) return def;
|
|
|
|
|
|
|
|
return lst[index].name;
|
2023-11-19 09:05:42 +01:00
|
|
|
} #endregion
|
2023-06-05 18:27:53 +02:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
function __txt_junction_tooltip(node, type, index, def = "") { #region
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-07-28 19:41:57 +02:00
|
|
|
|
2023-12-11 05:45:12 +01:00
|
|
|
if(LOCALE_DEF) return def;
|
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
if(TEST_LOCALE) {
|
|
|
|
if(!struct_has(LOCALE.node, node)) {
|
|
|
|
show_debug_message($"LOCALE [JTIP]: \"{node}\": \"{def}\",");
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!struct_has(LOCALE.node, node))
|
2023-06-05 18:27:53 +02:00
|
|
|
return def;
|
|
|
|
|
|
|
|
var nde = LOCALE.node[$ node];
|
|
|
|
var lst = type == JUNCTION_CONNECT.input? nde.inputs : nde.outputs;
|
|
|
|
if(index >= array_length(lst)) return def;
|
|
|
|
|
|
|
|
return lst[index].tooltip;
|
2023-11-19 09:05:42 +01:00
|
|
|
} #endregion
|
2023-06-05 18:27:53 +02:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
function __txt_junction_data(node, type, index, def = []) { #region
|
2023-11-08 08:38:04 +01:00
|
|
|
INLINE
|
2023-09-28 15:10:41 +02:00
|
|
|
|
2023-12-11 05:45:12 +01:00
|
|
|
if(LOCALE_DEF) return def;
|
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
if(TEST_LOCALE) {
|
|
|
|
if(!struct_has(LOCALE.node, node)) {
|
|
|
|
show_debug_message($"LOCALE [DDATA]: \"{node}\": \"{def}\",");
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return [ "" ];
|
|
|
|
}
|
2023-10-02 04:53:30 +02:00
|
|
|
|
2023-11-19 09:05:42 +01:00
|
|
|
if(!struct_has(LOCALE.node, node))
|
|
|
|
return def;
|
|
|
|
|
2023-09-28 15:10:41 +02:00
|
|
|
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;
|
2023-11-19 09:05:42 +01:00
|
|
|
|
2023-09-28 15:10:41 +02:00
|
|
|
return lst[index].display_data;
|
2023-11-19 09:05:42 +01:00
|
|
|
} #endregion
|
2023-02-14 02:48:33 +01:00
|
|
|
#endregion
|