Exemple #1
0
/// @brief Pick a language 
/// @return 
///
int AegisubLocale::PickLanguage() {
	// Get list
	wxArrayInt langs = GetAvailableLanguages();

	// Check if english is in it, else add it
	if (langs.Index(wxLANGUAGE_ENGLISH) == wxNOT_FOUND) {
		langs.Insert(wxLANGUAGE_ENGLISH,0);
	}

	// Check if user local language is available, if so, make it first
	int user = wxLocale::GetSystemLanguage();
	if (langs.Index(user) != wxNOT_FOUND) {
		langs.Remove(user);
		langs.Insert(user,0);
	}

	// Generate names
	wxArrayString langNames;
	for (size_t i=0;i<langs.Count();i++) {
		langNames.Add(wxLocale::GetLanguageName(langs[i]));
	}

	// Nothing to pick
	if (langs.Count() == 0) return -1;

	// Popup
	int picked = wxGetSingleChoiceIndex(_T("Please choose a language:"),_T("Language"),langNames,NULL,-1,-1,true,300,400);
	if (picked == -1) return -1;
	return langs[picked];
}
int AegisubLocale::PickLanguage() {
	wxArrayInt langs = GetAvailableLanguages();

	// Check if english is in it, else add it
	if (langs.Index(wxLANGUAGE_ENGLISH) == wxNOT_FOUND) {
		langs.Insert(wxLANGUAGE_ENGLISH, 0);
	}

	// Check if user local language is available, if so, make it first
	int user = wxLocale::GetSystemLanguage();
	if (langs.Index(user) != wxNOT_FOUND) {
		langs.Remove(user);
		langs.Insert(user, 0);
	}

	// Nothing to pick
	if (langs.empty()) return -1;

	// Only one language, so don't bother asking the user
	if (langs.size() == 1 && !locale)
		return langs[0];

	// Generate names
	wxArrayString langNames;
	for (size_t i = 0; i < langs.size(); ++i)
		langNames.Add(wxLocale::GetLanguageName(langs[i]));

	long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCENTRE;
	if (locale)
		style |= wxCANCEL;

	wxSingleChoiceDialog dialog(NULL, "Please choose a language:", "Language", langNames,
#if wxCHECK_VERSION(2, 9, 4)
			(void **)0,
#else
			0,
#endif
			style);
	if (dialog.ShowModal() == wxID_OK) {
		int picked = dialog.GetSelection();
		if (locale && langs[picked] == locale->GetLanguage())
			return -1;
		return langs[picked];
	}

	return -1;
}
/*
 * LanguageInit:  Initialize language menu when game entered.
 */
void LanguageInit(void)
{
   language_menu = CreatePopupMenu();

   // Add "Language" menu item.
   if (language_menu != NULL)
   {
      InsertMenu(cinfo->main_menu, MENU_POSITION_LANGUAGE, MF_STRING | MF_POPUP | MF_BYPOSITION, 
         (UINT) language_menu, GetString(hInst, IDS_LANGUAGE_MENU));
      DrawMenuBar(cinfo->hMain);
   }

   // Get available languages and populate the menu.
   Bool *avail_languages = GetAvailableLanguages();

   for (int i = 0; i < MAX_LANGUAGE_ID; i++)
      if (avail_languages[i] == 1)
         MenuAddLanguage(i);

   // Add a check to the selected language.
   CheckMenuItem(language_menu, cinfo->config->language + ID_LANGUAGE, MF_CHECKED);
}