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/
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file aegisublocale.cpp
|
|
|
|
/// @brief Enumerate available locales for picking translation on Windows
|
|
|
|
/// @ingroup utility
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
// Headers
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
#include <wx/intl.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <wx/dir.h>
|
|
|
|
#include <wx/filename.h>
|
|
|
|
#include <wx/choicdlg.h>
|
|
|
|
#include "aegisublocale.h"
|
2007-06-21 02:46:50 +02:00
|
|
|
#include "standard_paths.h"
|
2009-01-12 22:20:53 +01:00
|
|
|
#include <wx/stdpaths.h>
|
2006-01-16 22:02:54 +01:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Constructor
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
AegisubLocale::AegisubLocale () {
|
|
|
|
locale = NULL;
|
|
|
|
curCode = -1;
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief DOCME
|
|
|
|
///
|
2006-02-02 23:20:49 +01:00
|
|
|
AegisubLocale::~AegisubLocale() {
|
|
|
|
delete locale;
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Initialize
|
|
|
|
/// @param language
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
void AegisubLocale::Init(int language) {
|
|
|
|
if (language == -1) language = wxLANGUAGE_ENGLISH;
|
|
|
|
if (locale) delete locale;
|
2009-06-06 23:05:31 +02:00
|
|
|
|
|
|
|
if (!wxLocale::IsAvailable(language)) {
|
|
|
|
language = wxLANGUAGE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
curCode = language;
|
|
|
|
locale = new wxLocale(language);
|
2009-01-06 11:44:49 +01:00
|
|
|
|
2006-05-10 02:33:44 +02:00
|
|
|
#ifdef __WINDOWS__
|
2007-06-21 02:46:50 +02:00
|
|
|
locale->AddCatalogLookupPathPrefix(StandardPaths::DecodePath(_T("?data/locale/")));
|
2006-01-16 22:02:54 +01:00
|
|
|
locale->AddCatalog(_T("aegisub"));
|
2009-01-06 11:44:49 +01:00
|
|
|
#else
|
|
|
|
locale->AddCatalog(_T(GETTEXT_PACKAGE));
|
|
|
|
#endif
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
locale->AddCatalog(_T("wxstd"));
|
2006-05-06 16:38:53 +02:00
|
|
|
setlocale(LC_NUMERIC, "C");
|
|
|
|
setlocale(LC_CTYPE, "C");
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Pick a language
|
|
|
|
/// @return
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Get list of available languages
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
wxArrayInt AegisubLocale::GetAvailableLanguages() {
|
|
|
|
wxArrayInt final;
|
2009-01-01 03:16:09 +01:00
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
2006-01-16 22:02:54 +01:00
|
|
|
wxString temp1;
|
|
|
|
|
|
|
|
// Open directory
|
2007-06-21 02:46:50 +02:00
|
|
|
wxString folder = StandardPaths::DecodePath(_T("?data/locale/"));
|
2007-01-20 20:55:20 +01:00
|
|
|
wxDir dir;
|
|
|
|
if (!dir.Exists(folder)) return final;
|
|
|
|
if (!dir.Open(folder)) return final;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Enumerate folders
|
|
|
|
for (bool cont = dir.GetFirst(&temp1,_T(""),wxDIR_DIRS);cont;cont = dir.GetNext(&temp1)) {
|
|
|
|
// Check if .so exists inside folder
|
|
|
|
wxFileName file(folder + temp1 + _T("/aegisub.mo"));
|
|
|
|
if (file.FileExists()) {
|
|
|
|
const wxLanguageInfo *lang = wxLocale::FindLanguageInfo(temp1);
|
|
|
|
if (lang) {
|
|
|
|
final.Add(lang->Language);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-01 03:16:09 +01:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2009-09-02 10:18:11 +02:00
|
|
|
const wchar_t* langs[] = {
|
2009-01-01 06:37:47 +01:00
|
|
|
_T("ca"),
|
|
|
|
_T("da"),
|
|
|
|
_T("de"),
|
|
|
|
_T("es"),
|
|
|
|
_T("fr_FR"),
|
|
|
|
_T("hu"),
|
|
|
|
_T("it"),
|
2009-01-12 22:20:53 +01:00
|
|
|
_T("ja"),
|
2009-01-01 06:37:47 +01:00
|
|
|
_T("ko"),
|
|
|
|
_T("ru"),
|
|
|
|
_T("pt_BR"),
|
|
|
|
_T("zh_TW")
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t len = sizeof(langs)/sizeof(wchar_t*);
|
|
|
|
for (size_t i=0; i<len; i++) {
|
2009-01-01 03:16:09 +01:00
|
|
|
const wxLanguageInfo *lang = wxLocale::FindLanguageInfo(langs[i]);
|
|
|
|
|
2009-01-12 22:20:53 +01:00
|
|
|
// If the locale file doesn't exist then don't list it as an option.
|
|
|
|
wxString locDir = wxStandardPaths::Get().GetLocalizedResourcesDir(langs[i], wxStandardPathsBase::ResourceCat_Messages);
|
|
|
|
wxFileName file(wxString::Format(_T("%s/%s.mo"), locDir.c_str(), _T(GETTEXT_PACKAGE)));
|
|
|
|
if (lang && file.FileExists()) final.Add(lang->Language);
|
|
|
|
}
|
2009-01-01 03:16:09 +01:00
|
|
|
#endif
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
return final;
|
|
|
|
}
|
2009-07-29 07:43:02 +02:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|