示例#1
0
/**
 * as_utils_locale_is_compatible:
 * @locale1: a locale string, or %NULL
 * @locale2: a locale string, or %NULL
 *
 * Calculates if one locale is compatible with another.
 * When doing the calculation the locale and language code is taken into
 * account if possible.
 *
 * Returns: %TRUE if the locale is compatible.
 *
 * Since: 0.9.5
 **/
gboolean
as_utils_locale_is_compatible (const gchar *locale1, const gchar *locale2)
{
	g_autofree gchar *lang1 = as_utils_locale_to_language (locale1);
	g_autofree gchar *lang2 = as_utils_locale_to_language (locale2);

	/* we've specified "don't care" and locale unspecified */
	if (locale1 == NULL && locale2 == NULL)
		return TRUE;

	/* forward */
	if (locale1 == NULL && locale2 != NULL) {
		const gchar *const *locales = g_get_language_names ();
		return g_strv_contains (locales, locale2) ||
		       g_strv_contains (locales, lang2);
	}

	/* backwards */
	if (locale1 != NULL && locale2 == NULL) {
		const gchar *const *locales = g_get_language_names ();
		return g_strv_contains (locales, locale1) ||
		       g_strv_contains (locales, lang1);
	}

	/* both specified */
	if (g_strcmp0 (locale1, locale2) == 0)
		return TRUE;
	if (g_strcmp0 (locale1, lang2) == 0)
		return TRUE;
	if (g_strcmp0 (lang1, locale2) == 0)
		return TRUE;
	return FALSE;
}
示例#2
0
void
panel_key_file_set_locale_string (GKeyFile    *keyfile,
				  const gchar *key,
				  const gchar *value)
{
	const char         *locale;
	const char * const *langs_pointer;
	int                 i;

	locale = NULL;
	langs_pointer = g_get_language_names ();
	for (i = 0; langs_pointer[i] != NULL; i++) {
		/* find first without encoding  */
		if (strchr (langs_pointer[i], '.') == NULL) {
			locale = langs_pointer[i]; 
			break;
		}
	}

	if (locale)
		g_key_file_set_locale_string (keyfile, G_KEY_FILE_DESKTOP_GROUP,
					      key, locale, value);
	else
		g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP,
				       key, value);
}
示例#3
0
void
panel_key_file_remove_locale_key (GKeyFile    *keyfile,
				  const gchar *key)
{
	const char * const *langs_pointer;
	int                 i;
	char               *locale_key;

	locale_key = NULL;
	langs_pointer = g_get_language_names ();
	for (i = 0; langs_pointer[i] != NULL; i++) {
		/* find first without encoding  */
		if (strchr (langs_pointer[i], '.') == NULL) {
			locale_key = g_strdup_printf ("%s[%s]",
						      key, langs_pointer[i]);
			if (g_key_file_has_key (keyfile, G_KEY_FILE_DESKTOP_GROUP,
						locale_key, NULL))
				break;

			g_free (locale_key);
			locale_key = NULL;
		}
	}

	if (locale_key) {
		g_key_file_remove_key (keyfile, G_KEY_FILE_DESKTOP_GROUP,
				       locale_key, NULL);
		g_free (locale_key);
	} else
		g_key_file_remove_key (keyfile, G_KEY_FILE_DESKTOP_GROUP,
				       key, NULL);
}
示例#4
0
/**
 * load_help_doc:
 */
static xmlDocPtr
load_help_doc (void)
{
	xmlDocPtr helpdoc = NULL;
	const gchar * const *langs = g_get_language_names ();
	gchar *dirname, *helpfile;
	gint i;
	dirname = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "gda-sql", "help", NULL);
	for (i = 0; langs[i]; i++) {
		helpfile = g_build_filename (dirname, langs[i], "gda-sql-help.xml", NULL);
		if (g_file_test (helpfile, G_FILE_TEST_EXISTS))
			helpdoc = xmlParseFile (helpfile);
		g_free (helpfile);
		if (helpdoc)
			break;
	}

	if (!helpdoc) {
		/* default to the "C" one */
		helpfile = g_build_filename (dirname, "C", "gda-sql-help.xml", NULL);
		if (g_file_test (helpfile, G_FILE_TEST_EXISTS))
			helpdoc = xmlParseFile (helpfile);
		g_free (helpfile);
	}
	g_free (dirname);
	return helpdoc;
}
/* Adapted from yelp-toc-pager.c */
static xmlChar *
xml_get_and_trim_names (xmlNodePtr node)
{
        xmlNodePtr cur;
        xmlChar *keep_lang = NULL;
        xmlChar *value;
        int j, keep_pri = INT_MAX;

        const gchar * const * langs = g_get_language_names ();

        value = NULL;

        for (cur = node->children; cur; cur = cur->next) {
                if (! xmlStrcmp (cur->name, GVC_SOUND_NAME)) {
                        xmlChar *cur_lang = NULL;
                        int cur_pri = INT_MAX;

                        cur_lang = xmlNodeGetLang (cur);

                        if (cur_lang) {
                                for (j = 0; langs[j]; j++) {
                                        if (g_str_equal (cur_lang, langs[j])) {
                                                cur_pri = j;
                                                break;
                                        }
                                }
                        } else {
                                cur_pri = INT_MAX - 1;
                        }

                        if (cur_pri <= keep_pri) {
                                if (keep_lang)
                                        xmlFree (keep_lang);
                                if (value)
                                        xmlFree (value);

                                value = xmlNodeGetContent (cur);

                                keep_lang = cur_lang;
                                keep_pri = cur_pri;
                        } else {
                                if (cur_lang)
                                        xmlFree (cur_lang);
                        }
                }
        }

        /* Delete all GVC_SOUND_NAME nodes */
        cur = node->children;
        while (cur) {
                xmlNodePtr this = cur;
                cur = cur->next;
                if (! xmlStrcmp (this->name, GVC_SOUND_NAME)) {
                        xmlUnlinkNode (this);
                        xmlFreeNode (this);
                }
        }

        return value;
}
示例#6
0
/** @brief Find an absolute path to a localized version of a given
 *  relative path to a html or html related file.
 *  If no localized version exists, an absolute path to the file
 *  is searched for. If that file doesn't exist either, returns NULL.
 *
 *  @warning file_name should be a simple path fragment. It shouldn't
 *  contain xml:// or http:// or <whatever>:// other protocol specifiers.
 *
 *  If passed a string which g_path_is_absolute declares an absolute
 *  path, return the argument.
 *
 *  Otherwise, assume that file_name is a well-formed relative path and
 *  try to find a file with its path relative to
 *  \li a localized subdirectory in the html directory
 *      of the user's configuration directory
 *      (e.g. $HOME/.gnucash/html/de_DE, $HOME/.gnucash/html/en,...)
 *  \li a localized subdirectory in the gnucash documentation directory
 *      (e.g. /usr/share/doc/gnucash/C,...)
 *  \li the html directory of the user's configuration directory
 *      (e.g. $HOME/.gnucash/html)
 *  \li the gnucash documentation directory
 *      (e.g. /usr/share/doc/gnucash/)
 *  \li last resort option: the gnucash data directory
 *      (e.g. /usr/share/gnucash/)
 *
 *  The paths are searched for in that order. If a matching file is
 *  found, return the absolute path to it.

 *  If one isn't found, return NULL.
 *
 *  @param file_name The file path to resolve
 *
 *  @return An absolute file path or NULL if no file is found.
 */
gchar *
gnc_path_find_localized_html_file (const gchar *file_name)
{
    gchar *loc_file_name = NULL;
    gchar *full_path = NULL;
    const gchar * const *lang;
    int i;

    if (!file_name || *file_name == '\0')
        return NULL;

    /* An absolute path is returned unmodified. */
    if (g_path_is_absolute (file_name))
        return g_strdup (file_name);

    /* First try to find the file in any of the localized directories
     * the user has set up on his system
     */
    for (lang = g_get_language_names (); *lang; lang++)
    {
        loc_file_name = g_build_filename (*lang, file_name, (gchar *)NULL);
        full_path = gnc_path_find_localized_html_file_internal (loc_file_name);
        g_free (loc_file_name);
        if (full_path != NULL)
            return full_path;
    }

    /* If not found in a localized directory, try to find the file
     * in any of the base directories
     */
    return gnc_path_find_localized_html_file_internal (file_name);

}
示例#7
0
/**
 * category_find_preset:
 *
 * find a user language compatible file for category preset
 *
 * Return value: a pathname to the file or NULL
 *
 */
gchar *category_find_preset(gchar **lang)
{
gchar **langs;
gchar *filename;
gboolean exists;
guint i;

	DB( g_print("** category_find_preset **\n") );

	langs = (gchar **)g_get_language_names ();

	DB( g_print(" -> %d languages detected\n", g_strv_length(langs)) );

	for(i=0;i<g_strv_length(langs);i++)
	{
		DB( g_print(" -> %d '%s'\n", i, langs[i]) );
		filename = g_strdup_printf("hb-categories-%s.csv", langs[i]);
		gchar *pathfilename = g_build_filename(homebank_app_get_datas_dir(), filename, NULL);
		exists = g_file_test(pathfilename, G_FILE_TEST_EXISTS);
		DB( g_print(" -> '%s' exists=%d\n", pathfilename, exists) );
		if(exists)
		{
			g_free(filename);
			*lang = langs[i];
			return pathfilename;
		}
		g_free(filename);
		g_free(pathfilename);
	}

	DB( g_print("return NULL\n") );

	*lang = NULL;
	return NULL;
}
示例#8
0
static void fb_login(PurpleAccount *account)
{
	FacebookAccount *fba;
	gchar *postdata, *encoded_username, *encoded_password, *encoded_charset_test;
	const gchar* const *languages;
	const gchar *locale;
	
	/* Create account and initialize state */
	fba = g_new0(FacebookAccount, 1);
	fba->account = account;
	fba->pc = purple_account_get_connection(account);
	fba->uid = -1;
	fba->last_messages_download_time = time(NULL) - 60; /* 60 secs is a safe buffer */
	fba->cookie_table = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, g_free);
	fba->hostname_ip_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, g_free);
	fba->sent_messages_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, NULL);
	fba->auth_buddies = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, NULL);

	g_hash_table_replace(fba->cookie_table, g_strdup("test_cookie"),
			g_strdup("1"));

	account->gc->proto_data = fba;

	/* Error localized in libpurple jabber.c */
	if (!purple_ssl_is_supported()) {
		purple_connection_error_reason (purple_account_get_connection(account),
				PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
				_("Server requires TLS/SSL for login.  No TLS/SSL support found."));
		return;
	}

	purple_connection_set_state(fba->pc, PURPLE_CONNECTING);
	purple_connection_update_progress(fba->pc, _("Connecting"), 1, 3);

	encoded_username = g_strdup(purple_url_encode(
			purple_account_get_username(fba->account)));
	encoded_password = g_strdup(purple_url_encode(
			purple_account_get_password(fba->account)));
	encoded_charset_test = g_strdup(purple_url_encode("€,´,€,´,水,Д,Є"));
	languages = g_get_language_names();
	locale = languages[0];
	if (locale == NULL || g_str_equal(locale, "C"))
		locale = "en_US";

	g_hash_table_replace(fba->cookie_table, g_strdup("lsd"), g_strdup("abcde"));
	postdata = g_strdup_printf(
			"charset_test=%s&locale=%s&email=%s&pass=%s&pass_placeHolder=Password&persistent=1&login=Login&charset_test=%s&lsd=abcde",
			encoded_charset_test, locale, encoded_username, encoded_password, encoded_charset_test);
	g_free(encoded_username);
	g_free(encoded_password);
	g_free(encoded_charset_test);

	fb_post_or_get(fba, FB_METHOD_POST | FB_METHOD_SSL, "login.facebook.com",
			"/login.php?login_attempt=1&_fb_noscript=1", postdata, fb_login_cb, NULL, FALSE);
	g_free(postdata);
}
gchar *
fb_util_get_locale(void)
{
    const gchar * const *langs;
    const gchar *lang;
    gchar *chr;
    guint i;

    static const gchar chrs[] = {'.', '@'};

    langs = g_get_language_names();
    lang = langs[0];

    if (g_strcmp0(lang, "C") == 0) {
        return g_strdup("en_US");
    }

    for (i = 0; i < G_N_ELEMENTS(chrs); i++) {
        chr = strchr(lang, chrs[i]);

        if (chr != NULL) {
            return g_strndup(lang, chr - lang);
        }
    }

    return g_strdup(lang);
}
示例#10
0
文件: util.c 项目: micove/awn-extras
char* _desktop_entry_get_localized_name (DesktopAgnosticFDODesktopEntry *entry)
{
  char *result;

  result = desktop_agnostic_fdo_desktop_entry_get_localestring (entry,
                                                                "Name",
                                                                NULL);

  // workaround for older versions of lda which don't support NULL locale param
  if (result == NULL)
  {
    const gchar* const * languages = g_get_language_names ();
    int i = 0;

    while (result == NULL && languages[i] != NULL)
    {
      result =
        desktop_agnostic_fdo_desktop_entry_get_localestring (entry,
                                                             "Name",
                                                             languages[i]);
      i++;
    }
  }

  return result ? result : desktop_agnostic_fdo_desktop_entry_get_name (entry);
}
static void
save_entry (GtkEntry *entry, GKeyFile *key_file, const char *uri)
{
	GError *error;
	ItemEntry *item_entry;
	const char *val;
	gchar **languages;

	item_entry = g_object_get_data (G_OBJECT (entry), "item_entry");
	val = gtk_entry_get_text (entry);

	if (strcmp (val, item_entry->current_value) == 0) {
		return; /* No actual change, don't update file */
	}

	g_free (item_entry->current_value);
	item_entry->current_value = g_strdup (val);
	
	if (item_entry->localized) {
		languages = (gchar **) g_get_language_names ();
		g_key_file_set_locale_string (key_file, MAIN_GROUP, item_entry->field, languages[0], val);
	} else {
		g_key_file_set_string (key_file, MAIN_GROUP, item_entry->field, val);
	}

	error = NULL;

	if (!_g_key_file_save_to_uri (key_file, uri, &error)) {
		g_warning ("%s", error->message);
		g_error_free (error);
	}
}
示例#12
0
static gchar *
gimp_help_get_locales (GimpGuiConfig *config)
{
  if (config->help_locales && strlen (config->help_locales))
    return g_strdup (config->help_locales);

  return g_strjoinv (":", (gchar **) g_get_language_names ());
}
static void
help_display (void)
{
	GError     *error = NULL;
	char       *command;
	const char *lang;
	char       *uri = NULL;
	GdkScreen  *gscreen;
	int         i;

	const char * const * langs = g_get_language_names ();

	for (i = 0; langs[i] != NULL; i++)
	{
		lang = langs[i];
		if (strchr (lang, '.'))
		{
			continue;
		}

		uri = g_build_filename (DATADIR,
		                        "/mate/help/user-guide/",
		                        lang,
		                        "/user-guide.xml",
		                        NULL);

		if (g_file_test (uri, G_FILE_TEST_EXISTS))
		{
			break;
		}
	}

	command = g_strconcat ("mate-open ghelp://",
	                       uri,
	                       "?prefs-screensaver",
	                       NULL);
	gscreen = gdk_screen_get_default ();
	gdk_spawn_command_line_on_screen (gscreen, command, &error);

	if (error != NULL)
	{
		GtkWidget *d;

		d = gtk_message_dialog_new (NULL,
		                            GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
		                            GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
		                            "%s", error->message);
		gtk_dialog_run (GTK_DIALOG (d));
		gtk_widget_destroy (d);
		g_error_free (error);
	}

	g_free (command);
	g_free (uri);
}
示例#14
0
static gboolean
shell_utils_manage_quick_reference (EShell *shell,
                                    gboolean only_test)
{
    const gchar * const *language_names;
    gboolean app_launched = FALSE;
    gboolean found_any = FALSE;

    language_names = g_get_language_names ();
    while (*language_names != NULL && !app_launched) {
        const gchar *language = *language_names++;
        gchar *filename;

        /* This must be a valid language AND a language with
         * no encoding suffix.  The next language should have
         * no encoding suffix. */
        if (language == NULL || strchr (language, '.') != NULL)
            continue;

        filename = g_build_filename (
                       EVOLUTION_HELPDIR, "quickref",
                       language, "quickref.pdf", NULL);

        if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
            found_any = TRUE;

            if (!only_test) {
                GFile *file;
                gchar *uri;
                GError *error = NULL;

                file = g_file_new_for_path (filename);
                uri = g_file_get_uri (file);

                app_launched = g_app_info_launch_default_for_uri (
                                   uri, NULL, &error);

                if (error != NULL) {
                    /* FIXME Show an error dialog. */
                    g_warning ("%s", error->message);
                    g_error_free (error);
                }

                g_object_unref (file);
                g_free (uri);
            }
        }

        g_free (filename);
    }

    return found_any;
}
示例#15
0
static void  lunar_calendar_day_selected(GtkCalendar *gcalendar)
{
	guint year, month, day;
	GError *error = NULL;
	LunarCalendar *calendar;
	gchar *holiday, *format, *strtime, *color;

	calendar = LUNAR_CALENDAR(gcalendar);

	if (getenv("LUNAR_CALENDAR_IGNORE_NON_CHINESE") != NULL)
	{
		const gchar* const * langs =  g_get_language_names();

		if (langs[0] && langs[0][0] != '\0')
			if (!g_str_has_prefix(langs[0], "zh_")) {
				g_object_set (gcalendar, "show-details", FALSE, NULL);
				return;
			}
	}

	gtk_calendar_get_date(gcalendar, &year, &month, &day);
	lunar_date_set_solar_date(calendar->date, year, month + 1, day, 3, &error);
	if (error != NULL) {
		g_clear_error (&error);
		return;
	}

	color = rgba_to_string(calendar->rgba);
	holiday = lunar_date_get_holiday(calendar->date, "\n");
	if (holiday != NULL) {
		format = g_strdup_printf("%s\n%s\n%s\n%s\n<span color=\"%s\">%s</span>",
				_("%(year)-%(month)-%(day)"),
				_("%(YUE)yue%(RI)"),
				_("%(Y60)nian%(M60)yue%(D60)ri"),
				_("shengxiao: %(shengxiao)"),
				color,
				holiday);
	} else {
		format = g_strdup_printf("%s\n%s\n%s\n%s",
				_("%(year)-%(month)-%(day)"),
				_("%(YUE)yue%(RI)"),
				_("%(Y60)nian%(M60)yue%(D60)ri"),
				_("shengxiao: %(shengxiao)"));
	}
	strtime = lunar_date_strftime(calendar->date, format);
	g_free(color);
	g_free(holiday);
	g_free(format);

	gtk_widget_set_tooltip_markup(GTK_WIDGET(gcalendar), strtime);
	g_free(strtime);
}
示例#16
0
static char* _mime_type_get_desc( const char* file_path, const char* locale )
{
    int fd;
    struct stat statbuf;   // skip stat64
    char *buffer, *_locale, *desc;
    //char file_path[ 256 ];  //sfm to improve speed, file_path is passed

    //g_snprintf( file_path, 256, "%s/mime/%s.xml", data_dir, type );

    fd = open ( file_path, O_RDONLY, 0 );
    if ( G_UNLIKELY( fd == -1 ) )
        return NULL;
    if( G_UNLIKELY( fstat ( fd, &statbuf ) == -1 ) )
    {
        close( fd );
        return NULL;
    }
#ifdef HAVE_MMAP
    buffer = (char*)mmap( NULL, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0 );
#else
    buffer = (char*)g_malloc( statbuf.st_size );
    if( read( fd, buffer, statbuf.st_size ) == -1 )
    {
        g_free( buffer );
        buffer = (char*)-1;
    }
#endif
    close( fd );
    if ( G_UNLIKELY( buffer == (void*)-1 ) )
        return NULL;

    _locale = NULL;
    if( ! locale )
    {
        const char* const * langs = g_get_language_names();
        char* dot = strchr( langs[0], '.' );
        if( dot )
            locale = _locale = g_strndup( langs[0], (size_t)(dot - langs[0]) );
        else
            locale = langs[0];
    }
    desc = parse_xml_desc( buffer, statbuf.st_size, locale );
    g_free( _locale );

#ifdef HAVE_MMAP
    munmap ( buffer, statbuf.st_size );
#else
    g_free( buffer );
#endif
    return desc;
}
示例#17
0
static const char *
get_language (void)
{
	const char * const *langs_pointer;
	int i;

	langs_pointer = g_get_language_names ();
	for (i = 0; langs_pointer[i] != NULL; i++) {
		/* find first without encoding */
		if (strchr (langs_pointer[i], '.') == NULL) {
		return langs_pointer[i];
		}
	}
	return NULL;
} 
示例#18
0
/* {{{ proto array Glib::getLanguageNames()
	   Checks the version of the GLib library the extension was compiled against.
	   Returns TRUE if the version of the GLib header files compiled against are the same as or newer than the passed-in version. 
   */
PHP_METHOD(Glib, getLanguageNames)
{
	const gchar* const *langs;
	int i;

	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}
	langs = g_get_language_names();

	array_init(return_value);
	for (i = 0; langs[i]; i++) {
		add_next_index_string(return_value, (char *)langs[i], 1);
	}
}
示例#19
0
static int
language_level (const char *lang)
{
  const char * const *lang_list;
  int i;

  /* The returned list is sorted from most desirable to least
     desirable and always contains the default locale "C". */
  lang_list = g_get_language_names ();

  for (i = 0; lang_list[i]; i++)
    if (strcmp (lang_list[i], lang) == 0)
      return 1000-i;

  return 0;
}
示例#20
0
/**
 * as_get_current_locale:
 *
 * Returns a locale string as used in the AppStream specification.
 *
 * Returns: (transfer full): A locale string, free with g_free()
 */
gchar*
as_get_current_locale (void)
{
	const gchar * const *locale_names;
	gchar *tmp;
	gchar *locale;

	locale_names = g_get_language_names ();
	/* set active locale without UTF-8 suffix */
	locale = g_strdup (locale_names[0]);
	tmp = g_strstr_len (locale, -1, ".UTF-8");
	if (tmp != NULL)
		*tmp = '\0';

	return locale;
}
static gchar*
mate_da_xml_get_string (const xmlNode *parent, const gchar *val_name)
{
    const gchar * const *sys_langs;
    xmlChar *node_lang;
    xmlNode *element;
    gchar *ret_val = NULL;
    xmlChar *xml_val_name;
    gint len;
    gint i;

    g_return_val_if_fail (parent != NULL, ret_val);
    g_return_val_if_fail (parent->children != NULL, ret_val);
    g_return_val_if_fail (val_name != NULL, ret_val);

#if GLIB_CHECK_VERSION (2, 6, 0)
    sys_langs = g_get_language_names ();
#endif

    xml_val_name = xmlCharStrdup (val_name);
    len = xmlStrlen (xml_val_name);

    for (element = parent->children; element != NULL; element = element->next) {
	if (!xmlStrncmp (element->name, xml_val_name, len)) {
	    node_lang = xmlNodeGetLang (element);

	    if (node_lang == NULL) {
		ret_val = (gchar *) xmlNodeGetContent (element);
	    }
	    else {
		for (i = 0; sys_langs[i] != NULL; i++) {
		    if (!strcmp (sys_langs[i], node_lang)) {
			ret_val = (gchar *) xmlNodeGetContent (element);
			/* since sys_langs is sorted from most desirable to
			 * least desirable, exit at first match
			 */
			break;
		    }
		}
	    }
	    xmlFree (node_lang);
	}
    }

    xmlFree (xml_val_name);
    return ret_val;
}
示例#22
0
static char *
get_default_spell_languages (void)
{
	const gchar* const *langs = g_get_language_names ();
	char *last = NULL;
	char *p;
	char lang_list[64];
	char *ret = lang_list;
	int i;

	if (langs != NULL)
	{
		memset (lang_list, 0, sizeof(lang_list));

		for (i = 0; langs[i]; i++)
		{
			if (g_ascii_strncasecmp (langs[i], "C", 1) != 0 && strlen (langs[i]) >= 2)
			{
				/* Avoid duplicates */
				if (!last || !g_str_has_prefix (langs[i], last))
				{
					if (last != NULL)
					{
						g_free(last);
						g_strlcat (lang_list, ",", sizeof(lang_list));
					}

					/* ignore .utf8 */
					if ((p = strchr (langs[i], '.')))
						*p='\0';

					last = g_strndup (langs[i], 2);

					g_strlcat (lang_list, langs[i], sizeof(lang_list));
				}
			}
		}

		g_free (last);

		if (lang_list[0])
			return g_strdup (ret);
	}

	return g_strdup ("en");
}
static void
command_quick_reference (BonoboUIComponent *uih,
                         EShellWindow *window,
                         const char *path)
{
    char *quickref;
    const gchar * const *language_names;

    language_names = g_get_language_names ();
    while (*language_names != NULL) {
        const gchar *lang = *language_names++;

        /* This has to be a valid language AND a language with
         * no encoding postfix.  The language will come up without
         * encoding next */
        if (lang == NULL || strchr (lang, '.') != NULL)
            continue;

        quickref = g_build_filename (EVOLUTION_HELPDIR, "quickref", lang, "quickref.pdf", NULL);
        if (g_file_test (quickref, G_FILE_TEST_EXISTS)) {
            GFile *file = g_file_new_for_path (quickref);

            if (file) {
                GError *error = NULL;
                char *uri = g_file_get_uri (file);

                g_app_info_launch_default_for_uri (uri, NULL, &error);

                if (error) {
                    g_warning ("%s", error->message);
                    g_error_free (error);
                }

                g_object_unref (file);
                g_free (uri);
            }

            g_free (quickref);
            return;
        }

        g_free (quickref);
    }
}
示例#24
0
static gboolean
get_language (RetroCore *self,
              unsigned  *language)
{
  static const struct { const gchar *locale; enum RetroLanguage language; } values[] = {
    { "ar", RETRO_LANGUAGE_ARABIC },
    { "de", RETRO_LANGUAGE_GERMAN },
    { "en", RETRO_LANGUAGE_ENGLISH },
    { "eo", RETRO_LANGUAGE_ESPERANTO },
    { "es", RETRO_LANGUAGE_SPANISH },
    { "fr", RETRO_LANGUAGE_FRENCH },
    { "it", RETRO_LANGUAGE_ITALIAN },
    { "jp", RETRO_LANGUAGE_JAPANESE },
    { "ko", RETRO_LANGUAGE_KOREAN },
    { "nl", RETRO_LANGUAGE_DUTCH },
    { "pl", RETRO_LANGUAGE_POLISH },
    { "pt_BR", RETRO_LANGUAGE_PORTUGUESE_BRAZIL },
    { "pt_PT", RETRO_LANGUAGE_PORTUGUESE_PORTUGAL },
    { "ru", RETRO_LANGUAGE_RUSSIAN },
    { "vi", RETRO_LANGUAGE_VIETNAMESE },
    { "zh_CN", RETRO_LANGUAGE_CHINESE_SIMPLIFIED },
    { "zh_HK", RETRO_LANGUAGE_CHINESE_TRADITIONAL },
    { "zh_SG", RETRO_LANGUAGE_CHINESE_SIMPLIFIED },
    { "zh_TW", RETRO_LANGUAGE_CHINESE_TRADITIONAL },
    { "C", RETRO_LANGUAGE_DEFAULT },
  };

  const gchar * const *locales = g_get_language_names ();
  gsize locale_i, language_i = 0;

  for (locale_i = 0; locales[locale_i] != NULL; locale_i++) {
    for (language_i = 0;
         !g_str_equal (values[language_i].locale, "C") &&
         !g_str_equal (locales[locale_i], values[language_i].locale);
         language_i++);
    if (!g_str_equal (values[language_i].locale, "C"))
      break;
  }

  *language = values[language_i].language;

  return TRUE;
}
示例#25
0
文件: mdmconfig.c 项目: AlbertJP/mdm
/**
 * mdm_config_get_translated_string
 *
 * Gets translated string configuration value from daemon via
 * GET_CONFIG socket command.  It stores the value in a hash so
 * subsequent access is faster.  This does similar logic to
 * ve_config_get_trasnlated_string, requesting the value for 
 * each language and returning the default value if none is
 * found.
 */ 
static gchar *
_mdm_config_get_translated_string (const gchar *key,
				   gboolean reload,
				   gboolean *changed)
{
	const char * const *langs;
        char *newkey;
        char *def;
	int   i;

	/* Strip key */
	newkey = g_strdup (key);
	def    = strchr (newkey, '=');
	if (def != NULL)
		*def = '\0';

	langs = g_get_language_names ();

	for (i = 0; langs[i] != NULL; i++) {
                gchar *full;
		gchar *val;

		/*
		 * Pass TRUE for last argument so it doesn't print errors for
		 * failing to find the key, since this is expected
		 */
		full = g_strdup_printf ("%s[%s]", newkey, langs[i]);
		val = _mdm_config_get_string (full, reload, changed, TRUE);

		g_free (full);

                if (val != NULL) {
			g_free (newkey);
			return val;
		}
        }

	g_free (newkey);

	/* Print error if it fails this time */
	return _mdm_config_get_string (key, reload, changed, FALSE);
}
示例#26
0
gchar *
common_get_localized_filename (const gchar *str)
{
	const gchar *const *languages = g_get_language_names();
	int i = 0;

	while (languages[i] != NULL) {
		gchar *filename = g_strdup_printf (str, strcmp (languages[i], "C") ? languages[i] : "en");

		if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
			return filename;

		g_free (filename);
		i++;
	}

	g_warning ("No file found for %s", str);

	return NULL;
}
示例#27
0
文件: intl.c 项目: rennhak/Dia
/* low numbers are better */
int
intl_score_locale(const gchar *locale)
{
  const gchar * const *names = g_get_language_names ();
  int i = 0;

  /* NULL is same as C locale */
  if (!locale) {
    while (names[i] != NULL)
      ++i;
    return i;
  }
  while (names[i] != NULL) {
    if (strcmp(names[i], locale) == 0)
      break;
    ++i;
  }
  if (!names[i] != NULL) /* not found */
    i = G_MAXINT;
  return i;
}
示例#28
0
xmlNode *
e_xml_get_child_by_name_by_lang_list (const xmlNode *parent,
                                      const gchar *name,
                                      const GList *lang_list)
{
	gint best_lang_score = INT_MAX;

	g_return_val_if_fail (parent != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);

	if (lang_list == NULL) {
		const gchar * const *language_names;

		language_names = g_get_language_names ();
		while (*language_names != NULL)
			lang_list = g_list_append (
				(GList *) lang_list, (gchar *) * language_names++);
	}
	return e_xml_get_child_by_name_by_lang_list_with_score
		(parent,name,
		 lang_list,
		 &best_lang_score);
}
/*
 * matecomponent_activation_i18n_get_language_list:
 *
 * This computes a list of language strings that the user wants.  It searches in
 * the standard environment variables to find the list, which is sorted in order
 * from most desirable to least desirable.  The `C' locale is appended to the
 * list if it does not already appear (other routines depend on this
 * behaviour).
 *
 * The argument is ignored. It used to be the category to use for the locale.
 *
 * Return value: the list of languages, this list should not be freed as it is
 * owned by mate-i18n.
 */
const GList *
matecomponent_activation_i18n_get_language_list (const gchar *ignored)
{
    static GList *list = NULL;
    const char * const* langs;
    int i;

    MATECOMPONENT_ACTIVATION_LOCK ();

    if (list == NULL) {
        langs = g_get_language_names ();
        for (i = 0; langs[i] != NULL; i++) {
            list = g_list_prepend (list, g_strdup(langs[i]));
        }

        list = g_list_reverse (list);
    }

    MATECOMPONENT_ACTIVATION_UNLOCK ();

    return list;

}
示例#30
0
/**
 * ve_i18n_get_language_list:
 * @ignored: Not used anymore (Historically: Name of category to look
 *                 up, e.g. %"LC_MESSAGES").
 * 
 * Computes a list of applicable locale names, which can be used to e.g.
 * construct locale-dependent filenames or search paths. The returned list is
 * sorted from most desirable to least desirable and always contains the
 * default locale "C".
 * 
 * Return value: the list of languages, this list should not be freed as it is
 * owned by ve.
 **/
const GList *
ve_i18n_get_language_list (const gchar *category_name)
{
	static GStaticRecMutex lang_list_lock = G_STATIC_REC_MUTEX_INIT;
	static GList *list = NULL;
	const char * const* langs;
	int i;

	g_static_rec_mutex_lock (&lang_list_lock);

	if (list == NULL) {
		langs = g_get_language_names ();
		for (i = 0; langs[i] != NULL; i++) {
			list = g_list_prepend (list, g_strdup(langs[i]));
		}

		list = g_list_reverse (list);
	}

	g_static_rec_mutex_unlock (&lang_list_lock);

	return list;
}