2006-01-16 22:02:54 +01:00
|
|
|
// Copyright (c) 2005, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file aegisublocale.cpp
|
|
|
|
/// @brief Enumerate available locales for picking translation on Windows
|
|
|
|
/// @ingroup utility
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-10-02 21:28:55 +02:00
|
|
|
#include "aegisublocale.h"
|
|
|
|
|
2013-01-30 04:35:37 +01:00
|
|
|
#include "options.h"
|
|
|
|
|
|
|
|
#include <libaegisub/path.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
|
2012-09-22 18:51:39 +02:00
|
|
|
#include <algorithm>
|
2013-01-30 04:35:37 +01:00
|
|
|
#include <boost/locale.hpp>
|
2012-12-01 20:36:30 +01:00
|
|
|
#include <clocale>
|
2012-09-22 18:51:39 +02:00
|
|
|
#include <functional>
|
2009-09-10 15:06:40 +02:00
|
|
|
|
|
|
|
#include <wx/intl.h>
|
2009-09-11 00:48:29 +02:00
|
|
|
#include <wx/choicdlg.h> // Keep this last so wxUSE_CHOICEDLG is set.
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-10-02 21:28:55 +02:00
|
|
|
#ifndef AEGISUB_CATALOG
|
|
|
|
#define AEGISUB_CATALOG "aegisub"
|
|
|
|
#endif
|
2012-09-22 18:42:32 +02:00
|
|
|
|
2012-10-04 21:58:01 +02:00
|
|
|
wxTranslations *AegisubLocale::GetTranslations() {
|
|
|
|
wxTranslations *translations = wxTranslations::Get();
|
|
|
|
if (!translations) {
|
|
|
|
wxTranslations::Set(translations = new wxTranslations);
|
2013-01-30 04:35:37 +01:00
|
|
|
wxFileTranslationsLoader::AddCatalogLookupPathPrefix(config::path->Decode("?data/locale/").wstring());
|
2012-10-04 21:58:01 +02:00
|
|
|
}
|
|
|
|
return translations;
|
2012-09-22 18:42:32 +02:00
|
|
|
}
|
|
|
|
|
2012-10-02 21:28:55 +02:00
|
|
|
void AegisubLocale::Init(wxString const& language) {
|
2012-10-04 21:58:01 +02:00
|
|
|
wxTranslations *translations = GetTranslations();
|
2012-10-02 21:28:55 +02:00
|
|
|
translations->SetLanguage(language);
|
|
|
|
translations->AddCatalog(AEGISUB_CATALOG);
|
|
|
|
translations->AddStdCatalog();
|
2009-01-06 11:44:49 +01:00
|
|
|
|
2006-05-06 16:38:53 +02:00
|
|
|
setlocale(LC_NUMERIC, "C");
|
|
|
|
setlocale(LC_CTYPE, "C");
|
2012-10-02 21:28:55 +02:00
|
|
|
active_language = language;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-10-02 21:28:55 +02:00
|
|
|
wxString AegisubLocale::PickLanguage() {
|
2012-10-04 21:58:01 +02:00
|
|
|
wxArrayString langs = GetTranslations()->GetAvailableTranslations(AEGISUB_CATALOG);
|
2012-10-02 21:28:55 +02:00
|
|
|
langs.insert(langs.begin(), "en_US");
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Check if user local language is available, if so, make it first
|
2012-10-02 21:28:55 +02:00
|
|
|
const wxLanguageInfo *info = wxLocale::GetLanguageInfo(wxLocale::GetSystemLanguage());
|
|
|
|
if (info) {
|
2012-12-23 00:35:13 +01:00
|
|
|
auto it = std::find(langs.begin(), langs.end(), info->CanonicalName);
|
2012-10-02 21:28:55 +02:00
|
|
|
if (it != langs.end())
|
|
|
|
std::rotate(langs.begin(), it, it + 1);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-03-25 06:05:25 +02:00
|
|
|
// Nothing to pick
|
2012-10-02 21:28:55 +02:00
|
|
|
if (langs.empty()) return "";
|
2012-03-25 06:05:25 +02:00
|
|
|
|
|
|
|
// Only one language, so don't bother asking the user
|
2012-10-02 21:28:55 +02:00
|
|
|
if (langs.size() == 1 && !active_language)
|
2012-03-25 06:05:25 +02:00
|
|
|
return langs[0];
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// Generate names
|
|
|
|
wxArrayString langNames;
|
2013-11-21 18:13:36 +01:00
|
|
|
for (auto const& lang : langs) {
|
|
|
|
const wxLanguageInfo *info = wxLocale::FindLanguageInfo(lang);
|
2012-10-02 21:28:55 +02:00
|
|
|
if (info)
|
|
|
|
langNames.push_back(wxLocale::GetLanguageName(info->Language));
|
|
|
|
else
|
2013-11-21 18:13:36 +01:00
|
|
|
langNames.push_back(lang);
|
2012-10-02 21:28:55 +02:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-03-25 06:05:25 +02:00
|
|
|
long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCENTRE;
|
2012-10-02 21:28:55 +02:00
|
|
|
if (!active_language.empty())
|
2012-03-25 06:05:25 +02:00
|
|
|
style |= wxCANCEL;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-11-13 17:51:01 +01:00
|
|
|
wxSingleChoiceDialog dialog(nullptr, "Please choose a language:", "Language", langNames,
|
2013-11-21 18:13:36 +01:00
|
|
|
(void **)nullptr,
|
2012-08-03 04:32:30 +02:00
|
|
|
style);
|
2012-03-25 06:05:25 +02:00
|
|
|
if (dialog.ShowModal() == wxID_OK) {
|
|
|
|
int picked = dialog.GetSelection();
|
2012-10-02 21:28:55 +02:00
|
|
|
if (langs[picked] != active_language)
|
|
|
|
return langs[picked];
|
2012-03-25 06:05:25 +02:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-10-02 21:28:55 +02:00
|
|
|
return "";
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|