mirror of
https://github.com/weechat/weechat.git
synced 2026-06-25 20:36:38 +02:00
script: add option script.look.translate_description
This commit is contained in:
@@ -41,6 +41,7 @@ struct t_config_section *script_config_section_scripts = NULL;
|
||||
|
||||
struct t_config_option *script_config_look_columns;
|
||||
struct t_config_option *script_config_look_sort;
|
||||
struct t_config_option *script_config_look_translate_description;
|
||||
|
||||
/* script config, color section */
|
||||
|
||||
@@ -155,8 +156,8 @@ script_config_get_script_download_filename (struct t_repo_script *script)
|
||||
}
|
||||
|
||||
/*
|
||||
* script_config_refresh_cb: callback called when user changes xfer option that
|
||||
* needs a refresh of script list
|
||||
* script_config_refresh_cb: callback called when script buffer needs to be
|
||||
* refreshed
|
||||
*/
|
||||
|
||||
void
|
||||
@@ -171,12 +172,12 @@ script_config_refresh_cb (void *data, struct t_config_option *option)
|
||||
}
|
||||
|
||||
/*
|
||||
* script_config_change_sort_cb: callback called when default sort keys are
|
||||
* changed
|
||||
* script_config_reload_scripts_cb: callback called list of scripts must be
|
||||
* reloaded from file (plugins.xml.gz)
|
||||
*/
|
||||
|
||||
void
|
||||
script_config_change_sort_cb (void *data, struct t_config_option *option)
|
||||
script_config_reload_scripts_cb (void *data, struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -350,7 +351,14 @@ script_config_init ()
|
||||
"order; example: \"i,u\": installed scripts first, sorted by update "
|
||||
"date"),
|
||||
NULL, 0, 0, "p,n", NULL, 0,
|
||||
NULL, NULL, &script_config_change_sort_cb, NULL, NULL, NULL);
|
||||
NULL, NULL, &script_config_reload_scripts_cb, NULL, NULL, NULL);
|
||||
script_config_look_translate_description = weechat_config_new_option (
|
||||
script_config_file, ptr_section,
|
||||
"translate_description", "boolean",
|
||||
N_("translate description of scripts (if translation is available in "
|
||||
"your language, otherwise english version is used)"),
|
||||
NULL, 0, 0, "on", NULL, 0,
|
||||
NULL, NULL, &script_config_reload_scripts_cb, NULL, NULL, NULL);
|
||||
|
||||
/* color */
|
||||
ptr_section = weechat_config_new_section (script_config_file, "color",
|
||||
|
||||
@@ -26,6 +26,7 @@ struct t_repo_script;
|
||||
|
||||
extern struct t_config_option *script_config_look_columns;
|
||||
extern struct t_config_option *script_config_look_sort;
|
||||
extern struct t_config_option *script_config_look_translate_description;
|
||||
|
||||
extern struct t_config_option *script_config_color_status_popular;
|
||||
extern struct t_config_option *script_config_color_status_installed;
|
||||
|
||||
@@ -816,11 +816,13 @@ script_repo_file_read (int quiet)
|
||||
{
|
||||
char *filename, *ptr_line, line[4096], *pos, *pos2, *pos3;
|
||||
char *name, *value1, *value2, *value3, *value, *error;
|
||||
const char *version;
|
||||
char *locale, *locale_language;
|
||||
const char *version, *ptr_locale, *ptr_desc;
|
||||
gzFile file;
|
||||
struct t_repo_script *script;
|
||||
int version_number, version_ok, script_ok, length;
|
||||
struct tm tm_script;
|
||||
struct t_hashtable *descriptions;
|
||||
|
||||
script_get_loaded_scripts ();
|
||||
|
||||
@@ -866,6 +868,39 @@ script_repo_file_read (int quiet)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* get locale and locale_languages
|
||||
* example: if LANG=fr_FR.UTF-8, result is:
|
||||
* locale = "fr_FR"
|
||||
* locale_language = "fr"
|
||||
*/
|
||||
locale = NULL;
|
||||
locale_language = NULL;
|
||||
ptr_locale = weechat_info_get ("locale", NULL);
|
||||
if (ptr_locale)
|
||||
{
|
||||
pos = strchr (ptr_locale, '.');
|
||||
if (pos)
|
||||
locale = weechat_strndup (ptr_locale, pos - ptr_locale);
|
||||
else
|
||||
locale = strdup (ptr_locale);
|
||||
}
|
||||
if (locale)
|
||||
{
|
||||
pos = strchr (locale, '_');
|
||||
if (pos)
|
||||
locale_language = weechat_strndup (locale, pos - locale);
|
||||
else
|
||||
locale_language = strdup (locale);
|
||||
}
|
||||
|
||||
descriptions = weechat_hashtable_new (8,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
/* read plugins.xml.gz */
|
||||
while (!gzeof (file))
|
||||
{
|
||||
ptr_line = gzgets (file, line, sizeof (line) - 1);
|
||||
@@ -874,6 +909,7 @@ script_repo_file_read (int quiet)
|
||||
if (strstr (ptr_line, "<plugin id="))
|
||||
{
|
||||
script = script_repo_alloc ();
|
||||
weechat_hashtable_remove_all (descriptions);
|
||||
}
|
||||
else if (strstr (ptr_line, "</plugin>"))
|
||||
{
|
||||
@@ -895,20 +931,43 @@ script_repo_file_read (int quiet)
|
||||
}
|
||||
if (version_ok)
|
||||
{
|
||||
length = strlen (script->name) + 1 +
|
||||
strlen (script_extension[script->language]) + 1;
|
||||
script->name_with_extension = malloc (length);
|
||||
if (script->name_with_extension)
|
||||
ptr_desc = NULL;
|
||||
if (weechat_config_boolean (script_config_look_translate_description))
|
||||
{
|
||||
snprintf (script->name_with_extension,
|
||||
length,
|
||||
"%s.%s",
|
||||
script->name,
|
||||
script_extension[script->language]);
|
||||
/* try translated description (format "fr_FR") */
|
||||
ptr_desc = weechat_hashtable_get (descriptions,
|
||||
locale);
|
||||
if (!ptr_desc)
|
||||
{
|
||||
/* try translated description (format "fr") */
|
||||
ptr_desc = weechat_hashtable_get (descriptions,
|
||||
locale_language);
|
||||
}
|
||||
}
|
||||
if (!ptr_desc)
|
||||
{
|
||||
/* default description (english) */
|
||||
ptr_desc = weechat_hashtable_get (descriptions,
|
||||
"en");
|
||||
}
|
||||
if (ptr_desc)
|
||||
{
|
||||
script->description = strdup (ptr_desc);
|
||||
length = strlen (script->name) + 1 +
|
||||
strlen (script_extension[script->language]) + 1;
|
||||
script->name_with_extension = malloc (length);
|
||||
if (script->name_with_extension)
|
||||
{
|
||||
snprintf (script->name_with_extension,
|
||||
length,
|
||||
"%s.%s",
|
||||
script->name,
|
||||
script_extension[script->language]);
|
||||
}
|
||||
script_repo_update_status (script);
|
||||
script_repo_add (script);
|
||||
script_ok = 1;
|
||||
}
|
||||
script_repo_update_status (script);
|
||||
script_repo_add (script);
|
||||
script_ok = 1;
|
||||
}
|
||||
}
|
||||
if (!script_ok)
|
||||
@@ -948,8 +1007,17 @@ script_repo_file_read (int quiet)
|
||||
script->version = strdup (value);
|
||||
else if (strcmp (name, "license") == 0)
|
||||
script->license = strdup (value);
|
||||
else if (strcmp (name, "desc_en") == 0)
|
||||
script->description = strdup (value);
|
||||
else if (strncmp (name, "desc_", 5) == 0)
|
||||
{
|
||||
/*
|
||||
* store translated description in hashtable
|
||||
* (will be used later, by choosing
|
||||
* appropriate language according to locale)
|
||||
*/
|
||||
weechat_hashtable_set (descriptions,
|
||||
name + 5,
|
||||
value);
|
||||
}
|
||||
else if (strcmp (name, "tags") == 0)
|
||||
script->tags = strdup (value);
|
||||
else if (strcmp (name, "requirements") == 0)
|
||||
@@ -1034,6 +1102,13 @@ script_repo_file_read (int quiet)
|
||||
SCRIPT_PLUGIN_NAME);
|
||||
}
|
||||
|
||||
if (locale)
|
||||
free (locale);
|
||||
if (locale_language)
|
||||
free (locale_language);
|
||||
if (descriptions)
|
||||
weechat_hashtable_free (descriptions);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user