Beispiel #1
0
	std::string CapabilitiesGetLanguage () {
		
		char* country = NULL;
		char* language = NULL;
		
		locale_get(&language, &country);
		
		return std::string(language) + "-" + std::string(country);
		
	}
Beispiel #2
0
	const char* get_system_lang( ) {
		char* country = NULL;
    	char* language = NULL;
    	
    	locale_get(&language, &country);

    	bps_free(country);
    	bps_free(language);

    	return language;
	}
Beispiel #3
0
ccLanguageType CCApplication::getCurrentLanguage()
{
	ccLanguageType ret_language = kLanguageEnglish;
	char *language, *country;

	locale_get(&language, &country);

	if (strcmp(language, "en") == 0)
	{
		ret_language = kLanguageEnglish;
	}
	else if (strcmp(language, "fr") == 0)
	{
		ret_language = kLanguageFrench;
	}
	else if (strcmp(language, "de") == 0)
	{
		ret_language = kLanguageGerman;
	}
	else if (strcmp(language, "it") == 0)
	{
		ret_language = kLanguageItalian;
	}
	else if (strcmp(language, "es") == 0)
	{
		ret_language = kLanguageSpanish;
	}
	else if (strcmp(language, "ch") == 0)
	{
		ret_language = kLanguageChinese;
	}
	else if (strcmp(language, "ru") == 0)
	{
		ret_language = kLanguageRussian;
	}
	else if (strcmp(language, "ko") == 0)
	{
		ret_language = kLanguageKorean;
	}
	else if (strcmp(language, "ja") == 0)
	{
		ret_language = kLanguageJapanese;
	}
	else if (strcmp(language, "hu") == 0)
	{
		ret_language = kLanguageHungarian;
	}
    else if (strcmp(language, "pt") == 0)
    {
        ret_language = kLanguagePortuguese;
    }
    else if (strcmp(language, "ar") == 0)
    {
        ret_language = kLanguageArabic;
    }

	free(language);
	free(country);

    return ret_language;
}
Beispiel #4
0
/**
 * A sample application that demonstrates the BlackBerry Native APIs for
 * managing locale. The sample queries for the current locale and then listens
 * for locale update events.
 */
int
main(int argc, char *argv[])
{
    /*
     * Before we can listen for events from the BlackBerry Tablet OS platform
     * services, we need to initialize the BPS infrastructure
     */
    bps_initialize();

    if (setup_screen() != EXIT_SUCCESS) {
        printf("Unable to set up the screen. Exiting.");
        return 0;
    }

    /*
     * Once the BPS infrastructure has been initialized we can register for
     * events from the various BlackBerry Tablet OS platform services. The
     * Navigator service manages and delivers application life cycle and
     * visibility events.
     * For this sample, we request Navigator events so that we can track when
     * the system is terminating the application (NAVIGATOR_EXIT event) as well
     * as Locale events so we can be notified when the locale is updated
     */
    navigator_request_events(0);
    locale_request_events(0);
    dialog_request_events(0);

    /*
     * Create and display the dialog.
     */
    create_dialog();

    /*
     * Retrieve and display the current Locale using the locale_get(...) API
     */
    char* country = NULL;
    char* language = NULL;
    locale_get(&language, &country);
    display_locale(language, country);
    bps_free((char*)language);
    bps_free((char*)country);

   /*
    * Process Locale and Navigator events until we receive a NAVIGATOR_EXIT event.
    */
    int exit_application = 0;
    while (!exit_application) {
        /*
         * Using a negative timeout (-1) in the call to bps_get_event(...)
         * ensures that we don't busy wait by blocking until an event is
         * available.
         */
        bps_event_t *event = NULL;
        bps_get_event(&event, -1);

        if (event) {
            if (bps_event_get_domain(event) == locale_get_domain()) {
                /*
                 * If it is a LOCALE_INFO event then display the updated locale
                 * information
                 */
                if (LOCALE_INFO == bps_event_get_code(event)) {
                    /*
                     * The locale_event_get_language and locale_event_get_country
                     * calls return pointers to data within the event. When
                     * the event is destroyed below via the call to
                     * bps_event_destroy(event), the returned pointers would
                     * reference deallocated memory.
                     *
                     * To avoid potentially having pointers to dereferenced
                     * memory, we'll use local variables to store the pointers
                     * into the event data. This way, the pointers will go
                     * out of scope and thus cannot be used after the event
                     * is freed.
                     */
                    const char* language = locale_event_get_language(event);
                    const char* country = locale_event_get_country(event);
                    display_locale(language, country);
                }
            }

            /*
             * If it is a NAVIGATOR_EXIT event then set the exit_application
             * flag so the application will stop processing events, clean up
             * and exit
             */
            if (bps_event_get_domain(event) == navigator_get_domain()) {
                if (NAVIGATOR_EXIT == bps_event_get_code(event)) {
                    exit_application = 1;
                }
            }
        }
    }

    /*
     * Destroy the dialog, if it exists and cleanup screen resources.
     */
    destroy_dialog();
    cleanup_screen();

    /*
     * Clean up the BPS infrastructure and exit
     */
    bps_shutdown();
    return 0;
}
Beispiel #5
0
	void init() {
#ifdef _WIN32
	{
		char c[1024];
		GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SISO639LANGNAME,c,1024);
		if(c[0]!='\0'){
			locale=c;
			GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SISO3166CTRYNAME,c,1024);
			if(c[0]!='\0') locale+=std::string("_")+c;
		}
	}
#endif
		
#ifdef __APPLE__
		CFArrayRef localeIDs = CFLocaleCopyPreferredLanguages();
		if (localeIDs)
		{
			CFStringRef localeID = (CFStringRef)CFArrayGetValueAtIndex(localeIDs, 0);
			char tmp[16];
			if (CFStringGetCString(localeID, tmp, 16, kCFStringEncodingUTF8))
				locale = std::string(tmp);
			CFRelease(localeIDs);
		}
#endif

#if defined(TARGET_OS_HARMATTAN)
	std::cerr << "Get GConf default client\n";
	GConfClient *gconf = gconf_client_get_default();
	locale = std::string(gconf_client_get_string(gconf, "/meegotouch/i18n/region", NULL));
#elif defined(TARGET_BLACKBERRY)
	char *language = 0;
	char *country = 0;
	if (BPS_SUCCESS == locale_get(&language, &country) && language!= NULL && country != NULL) {
		std::stringstream ss;
		ss << language << "_" << country;
		locale = ss.str();

		bps_free(language);
		bps_free(country);
	}
#else
	char *cstr = getenv("LANG");
	if (cstr != NULL)
		locale = cstr;
	if (locale.size() < 2)
	{
		cstr = getenv("LC_ALL");
		if (cstr != NULL)
			locale = cstr;
	}
	
	if (locale == "zh-Hans") locale = "zh_CN"; //hack to make it work on iOS
	if (locale == "zh-Hant") locale = "zh_TW";
#endif
	//strip the charset part of the country and language code,
	//e.g. "pt_BR.UTF8" --> "pt_BR"
	size_t found = locale.find(".");
	if (found != std::string::npos) {
		locale = locale.substr(0, found);
	}
	if (locale.size() < 2)
		return;
	
	std::string filename = "./locale/" + locale + "/LC_MESSAGES/frogatto.mo";
	found = locale.find("@");
	if (!sys::file_exists(filename) && found != std::string::npos) {
		locale = locale.substr(0, found);
		filename = "./locale/" + locale + "/LC_MESSAGES/frogatto.mo";
	}
	//strip the country code, e.g. "de_DE" --> "de"
	found = locale.find("_");
	if (!sys::file_exists(filename) && found != std::string::npos) {
		locale = locale.substr(0, found);
		filename = "./locale/" + locale + "/LC_MESSAGES/frogatto.mo";
	}
	if (!sys::file_exists(filename))
		return;
	const std::string content = sys::read_file(module::map_file(filename));
	size_t size = content.size();
	if (size < sizeof(mo_header))
		return;
	mo_header* header = (mo_header*) content.c_str();
	if (header->magic != 0x950412de ||
	    header->version != 0 ||
	    header->o_offset + 8*header->number > size ||
	    header->t_offset + 8*header->number > size)
		return;
	mo_entry* original = (mo_entry*) (content.c_str() + header->o_offset);
	mo_entry* translated = (mo_entry*) (content.c_str() + header->t_offset);
	for (int i = 0; i < header->number; ++i) {
		if (original[i].offset + original[i].length > size ||
		    translated[i].offset + translated[i].length > size)
			return;
		const std::string msgid = content.substr(original[i].offset, original[i].length);
		const std::string msgstr = content.substr(translated[i].offset, translated[i].length);
		hashmap[msgid] = msgstr;
	}
}