Skip to content
Snippets Groups Projects
Commit 72e3271b authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Load section or keys form [module:lang=<user-lang>] if it exists

This allow language-specific module options
parent b94ee020
No related branches found
No related tags found
No related merge requests found
Pipeline #8200 passed
/* modopts.js */
/* $Id: modopts.js,v 1.4 2019/01/11 09:26:34 rswindell Exp $ */
/* Load Synchronet JS Module Control/Enable options from ctrl/modopts.ini */
/* Parse a single .ini section using the argument (to load) as the section name */
/* and return an object containing the key=value pairs as properties */
/* To avoid over-writing the parent script's "argc" and "argv" values,
/* If the section [module:lang=user-lang] exists in the .ini file,
that section (or key value from it) will be returned instead of the [module] section.
*/
/* To avoid over-writing the parent script's "argc" and "argv" values,
pass a scope object to load(), like this:
options=load(new Object, "modopts.js", "your_module_name");
......@@ -25,13 +25,16 @@ function get_mod_options(modname, optname, default_optval)
return undefined;
}
var section = modname + ':lang=' + user.lang;
if(!user.lang || ini_file.iniGetSections().indexOf(section) < 0)
section = modname;
var val;
if(optname) // Get a specific option value (optionally, with default value)
val = ini_file.iniGetValue(modname, optname, default_optval);
val = ini_file.iniGetValue(section, optname, default_optval);
else // Get all options
val = ini_file.iniGetObject(modname, /* lowercase */false, /* blanks: */true);
val = ini_file.iniGetObject(section, /* lowercase */false, /* blanks: */true);
ini_file.close();
return val;
}
get_mod_options(argv[0], argv[1], argv[2]);
\ No newline at end of file
get_mod_options(argv[0], argv[1], argv[2]);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment