Beispiel #1
0
/* The meego desktop files are using the qt translation system to get
 * localized strings using catalog and string ids. QApplication and
 * MLocale are needed for loading the translation catalogs. The
 * returned string is a multi-string one which has parts of different
 * length separated by '\x9C' unicode escape sequences.
 *
 * FIXME: This is insane, try to get rid of at least some of the extra
 * layers here.
 */
gchar *
tracker_meego_translate (const gchar *catalogue,
                         const gchar *id)
{
	/* Get the system default locale */
	MLocale locale;

	/* Load the catalog from disk if not already there */
	if(!locale.isInstalledTrCatalog (catalogue)) {
		locale.installTrCatalog (catalogue);
		MLocale::setDefault (locale);
	}

	gchar *ret = g_strdup (qtTrId (id).toUtf8 ().data ());

	/* We only want the first string of the multi-string, so if
	 * the separator character is found (encoded as C2:9C in UTF-8),
	 * we just end the string in that point */
	gchar *next_string = strstr (ret, "\xC2\x9C");
	if (next_string) {
		*next_string = '\0';
	}

	return ret;
}
void TestBirthdayPlugin::testLocaleChange()
{
    MGConfItem store(QLatin1String("/meegotouch/i18n/language"));
    store.set(QLatin1String("en"));

    // Leave the time to react to locale change
    loopWait(1000);

    // Use the C locale so it can be changed to a different locale later.
    MLocale locale;
    QVERIFY2(locale.isValid(), "Invalid locale");

    if (not locale.isInstalledTrCatalog(QLatin1String("calendar"))) {
        locale.installTrCatalog(QLatin1String("calendar"));
    }

    locale.connectSettings();
    MLocale::setDefault(locale);

    // Open calendar database, which should have been created by the birthday plugin.
    mKCal::ExtendedCalendar::Ptr calendar =
        mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone()));
    mKCal::ExtendedStorage::Ptr storage =
        mKCal::ExtendedCalendar::defaultStorage(calendar);
    storage->open();
    QVERIFY2(not storage->notebook(calNotebookId).isNull(), "No calendar database found");

    // Check if locale name for calendar matches calendar name.
    //QVERIFY2(locale.isInstalledTrCatalog(QLatin1String("calendar")), "Calendar locale catalog not installed");
    const QString cLocaleCalendarName = qtTrId("qtn_caln_birthdays");
    QCOMPARE(storage->notebook(calNotebookId)->name(), cLocaleCalendarName);

    // Change locale and check name again.
    store.set(QLatin1String("fi"));

    loopWait(calendarTimeout);

    const QString finnishLocaleCalendarName = qtTrId("qtn_caln_birthdays");

    QVERIFY2(storage->notebook(calNotebookId)->name() != cLocaleCalendarName, "Calendar name was not updated on locale change");
    QCOMPARE(storage->notebook(calNotebookId)->name(), finnishLocaleCalendarName);

    // Close the calendar.
    QVERIFY2(storage->close(), "Error closing the calendar");
}