mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 08:09:32 +02:00
namespace for Languages, which does not depend on FileNames...
(some small code duplication of code for path lists results)
This commit is contained in:
parent
e31593c06a
commit
ad5f895f65
@ -75,9 +75,10 @@ LangChoiceDialog::LangChoiceDialog(wxWindow * parent,
|
|||||||
wxDialogWrapper(parent, id, title)
|
wxDialogWrapper(parent, id, title)
|
||||||
{
|
{
|
||||||
SetName();
|
SetName();
|
||||||
GetLanguages(mLangCodes, mLangNames);
|
const auto &paths = FileNames::AudacityPathList();
|
||||||
int lang =
|
Languages::GetLanguages(paths, mLangCodes, mLangNames);
|
||||||
make_iterator_range( mLangCodes ).index( GetSystemLanguageCode() );
|
int lang = make_iterator_range( mLangCodes )
|
||||||
|
.index( Languages::GetSystemLanguageCode(paths) );
|
||||||
|
|
||||||
ShuttleGui S(this, eIsCreating);
|
ShuttleGui S(this, eIsCreating);
|
||||||
|
|
||||||
@ -105,7 +106,8 @@ void LangChoiceDialog::OnOk(wxCommandEvent & WXUNUSED(event))
|
|||||||
int ndx = mChoice->GetSelection();
|
int ndx = mChoice->GetSelection();
|
||||||
mLang = mLangCodes[ndx];
|
mLang = mLangCodes[ndx];
|
||||||
|
|
||||||
wxString slang = GetSystemLanguageCode();
|
auto slang =
|
||||||
|
Languages::GetSystemLanguageCode(FileNames::AudacityPathList());
|
||||||
int sndx = make_iterator_range( mLangCodes ).index( slang );
|
int sndx = make_iterator_range( mLangCodes ).index( slang );
|
||||||
wxString sname;
|
wxString sname;
|
||||||
|
|
||||||
|
@ -32,40 +32,40 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Languages.h"
|
#include "Languages.h"
|
||||||
|
#include "audacity/Types.h"
|
||||||
#include "MemoryX.h"
|
#include "MemoryX.h"
|
||||||
|
|
||||||
#include "Internat.h"
|
#include "Internat.h"
|
||||||
|
|
||||||
#include <wx/defs.h>
|
#include <wx/defs.h>
|
||||||
|
#include <wx/dir.h>
|
||||||
|
#include <wx/filename.h>
|
||||||
#include <wx/intl.h>
|
#include <wx/intl.h>
|
||||||
#include <wx/textfile.h>
|
#include <wx/textfile.h>
|
||||||
|
|
||||||
#include "FileNames.h"
|
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
using LangHash = std::unordered_map<wxString, TranslatableString>;
|
using LangHash = std::unordered_map<wxString, TranslatableString>;
|
||||||
using ReverseLangHash = std::unordered_map<TranslatableString, wxString>;
|
using ReverseLangHash = std::unordered_map<TranslatableString, wxString>;
|
||||||
|
|
||||||
static bool TranslationExists(const FilePaths &audacityPathList, wxString code)
|
static void FindFilesInPathList(const wxString & pattern,
|
||||||
|
const FilePaths & pathList, FilePaths & results)
|
||||||
|
{
|
||||||
|
wxFileName ff;
|
||||||
|
for (const auto &path : pathList) {
|
||||||
|
ff = path + wxFILE_SEP_PATH + pattern;
|
||||||
|
wxDir::GetAllFiles(ff.GetPath(), &results, ff.GetFullName(), wxDIR_FILES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool TranslationExists(const FilePaths &pathList, wxString code)
|
||||||
{
|
{
|
||||||
FilePaths results;
|
FilePaths results;
|
||||||
FileNames::FindFilesInPathList(wxString::Format(wxT("%s/audacity.mo"),
|
FindFilesInPathList(code + L"/audacity.mo", pathList, results);
|
||||||
code),
|
|
||||||
audacityPathList,
|
|
||||||
results);
|
|
||||||
#if defined(__WXMAC__)
|
#if defined(__WXMAC__)
|
||||||
FileNames::FindFilesInPathList(wxString::Format(wxT("%s.lproj/audacity.mo"),
|
FindFilesInPathList(code + L".lproj/audacity.mo", pathList, results);
|
||||||
code),
|
|
||||||
audacityPathList,
|
|
||||||
results);
|
|
||||||
#endif
|
#endif
|
||||||
|
FindFilesInPathList(code + L"/LC_MESSAGES/audacity.mo", pathList, results);
|
||||||
FileNames::FindFilesInPathList(wxString::Format(wxT("%s/LC_MESSAGES/audacity.mo"),
|
|
||||||
code),
|
|
||||||
audacityPathList,
|
|
||||||
results);
|
|
||||||
|
|
||||||
return (results.size() > 0);
|
return (results.size() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,12 +74,14 @@ static bool TranslationExists(const FilePaths &audacityPathList, wxString code)
|
|||||||
#include <wx/osx/core/cfstring.h>
|
#include <wx/osx/core/cfstring.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxString GetSystemLanguageCode()
|
namespace Languages {
|
||||||
|
|
||||||
|
wxString GetSystemLanguageCode(const FilePaths &pathList)
|
||||||
{
|
{
|
||||||
wxArrayString langCodes;
|
wxArrayString langCodes;
|
||||||
TranslatableStrings langNames;
|
TranslatableStrings langNames;
|
||||||
|
|
||||||
GetLanguages(langCodes, langNames);
|
GetLanguages(pathList, langCodes, langNames);
|
||||||
|
|
||||||
int sysLang = wxLocale::GetSystemLanguage();
|
int sysLang = wxLocale::GetSystemLanguage();
|
||||||
|
|
||||||
@ -128,7 +130,7 @@ wxString GetSystemLanguageCode()
|
|||||||
return wxT("en");
|
return wxT("en");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetLanguages(
|
void GetLanguages( FilePaths pathList,
|
||||||
wxArrayString &langCodes, TranslatableStrings &langNames)
|
wxArrayString &langCodes, TranslatableStrings &langNames)
|
||||||
{
|
{
|
||||||
static const char *const utf8Names[] = {
|
static const char *const utf8Names[] = {
|
||||||
@ -209,13 +211,15 @@ void GetLanguages(
|
|||||||
return localLanguageName;
|
return localLanguageName;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
auto audacityPathList = FileNames::AudacityPathList();
|
|
||||||
|
|
||||||
#if defined(__WXGTK__)
|
#if defined(__WXGTK__)
|
||||||
FileNames::AddUniquePathToPathList(
|
{
|
||||||
wxString::Format(wxT("%s/share/locale"),
|
wxFileName pathNorm{ wxString{INSTALL_PREFIX} + L"/share/locale" };
|
||||||
wxT(INSTALL_PREFIX)),
|
pathNorm.Normalize();
|
||||||
audacityPathList);
|
const wxString newPath{ pathNorm.GetFullPath() };
|
||||||
|
if (pathList.end() ==
|
||||||
|
std::find(pathList.begin(), pathList.end(), newPath))
|
||||||
|
pathList.push_back(newPath);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// For each language in our list we look for a corresponding entry in
|
// For each language in our list we look for a corresponding entry in
|
||||||
@ -257,14 +261,14 @@ void GetLanguages(
|
|||||||
name = found->second;
|
name = found->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TranslationExists(audacityPathList, fullCode)) {
|
if (TranslationExists(pathList, fullCode)) {
|
||||||
code = fullCode;
|
code = fullCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tempHash[code].empty())
|
if (!tempHash[code].empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (TranslationExists(audacityPathList, code) || code==wxT("en")) {
|
if (TranslationExists(pathList, code) || code==wxT("en")) {
|
||||||
tempCodes.push_back(code);
|
tempCodes.push_back(code);
|
||||||
tempNames.push_back(name);
|
tempNames.push_back(name);
|
||||||
tempHash[code] = name;
|
tempHash[code] = name;
|
||||||
@ -281,7 +285,7 @@ void GetLanguages(
|
|||||||
wxString code;
|
wxString code;
|
||||||
code = wxT("en-simple");
|
code = wxT("en-simple");
|
||||||
auto name = XO("Simplified");
|
auto name = XO("Simplified");
|
||||||
if (TranslationExists(audacityPathList, code) ) {
|
if (TranslationExists(pathList, code) ) {
|
||||||
tempCodes.push_back(code);
|
tempCodes.push_back(code);
|
||||||
tempNames.push_back(name);
|
tempNames.push_back(name);
|
||||||
tempHash[code] = name;
|
tempHash[code] = name;
|
||||||
@ -309,3 +313,5 @@ void GetLanguages(
|
|||||||
langCodes.push_back(reverseHash[tempNames[j]]);
|
langCodes.push_back(reverseHash[tempNames[j]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -16,10 +16,25 @@ class wxString;
|
|||||||
|
|
||||||
#include "audacity/Types.h"
|
#include "audacity/Types.h"
|
||||||
|
|
||||||
|
namespace Languages {
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@param pathList paths to search for .mo files, grouped into subdirectories for the different
|
||||||
|
languages
|
||||||
|
@param[out] langCodes two-letter language abbreviations (like "fr") or language and country
|
||||||
|
(like "pt_BR")
|
||||||
|
@param[out] langNames corresponding autonyms of those languages (like "Português")
|
||||||
|
*/
|
||||||
AUDACITY_DLL_API
|
AUDACITY_DLL_API
|
||||||
void GetLanguages(
|
void GetLanguages( FilePaths pathList,
|
||||||
wxArrayString &langCodes, TranslatableStrings &langNames);
|
wxArrayString &langCodes, TranslatableStrings &langNames);
|
||||||
|
|
||||||
wxString GetSystemLanguageCode();
|
/*!
|
||||||
|
@param pathList paths to search for .mo files, grouped into subdirectories for the different languages
|
||||||
|
*/
|
||||||
|
AUDACITY_DLL_API
|
||||||
|
wxString GetSystemLanguageCode(const FilePaths &pathList);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // __AUDACITY_LANGUAGES__
|
#endif // __AUDACITY_LANGUAGES__
|
||||||
|
@ -102,7 +102,8 @@ void GUIPrefs::GetRangeChoices(
|
|||||||
void GUIPrefs::Populate()
|
void GUIPrefs::Populate()
|
||||||
{
|
{
|
||||||
// First any pre-processing for constructing the GUI.
|
// First any pre-processing for constructing the GUI.
|
||||||
GetLanguages(mLangCodes, mLangNames);
|
Languages::GetLanguages(
|
||||||
|
FileNames::AudacityPathList(), mLangCodes, mLangNames);
|
||||||
|
|
||||||
GetRangeChoices(&mRangeChoices, &mRangeCodes, &mDefaultRangeIndex);
|
GetRangeChoices(&mRangeChoices, &mRangeCodes, &mDefaultRangeIndex);
|
||||||
|
|
||||||
@ -261,7 +262,8 @@ wxString GUIPrefs::InitLang( wxString langCode )
|
|||||||
// Use the system default language if one wasn't specified or if the user selected System.
|
// Use the system default language if one wasn't specified or if the user selected System.
|
||||||
if (langCode.empty())
|
if (langCode.empty())
|
||||||
{
|
{
|
||||||
langCode = GetSystemLanguageCode();
|
langCode =
|
||||||
|
Languages::GetSystemLanguageCode(FileNames::AudacityPathList());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the language
|
// Initialize the language
|
||||||
@ -297,7 +299,7 @@ wxString GUIPrefs::SetLang( const wxString & lang )
|
|||||||
}
|
}
|
||||||
if (!info)
|
if (!info)
|
||||||
{
|
{
|
||||||
result = GetSystemLanguageCode();
|
result = Languages::GetSystemLanguageCode(FileNames::AudacityPathList());
|
||||||
info = wxLocale::FindLanguageInfo(result);
|
info = wxLocale::FindLanguageInfo(result);
|
||||||
if (!info)
|
if (!info)
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user