Audacity 3.2.0
Namespaces | Typedefs | Functions | Variables
Languages.cpp File Reference

Determine installed languages. More...

#include "Languages.h"
#include <memory>
#include "wxArrayStringEx.h"
#include "Internat.h"
#include <wx/defs.h>
#include <wx/dir.h>
#include <wx/filename.h>
#include <wx/intl.h>
#include <wx/stdpaths.h>
#include <wx/textfile.h>
#include <wx/utils.h>
#include <clocale>
#include <unordered_map>
#include <CoreFoundation/CFPreferences.h>
#include <wx/osx/core/cfstring.h>
#include "FutureStrings.h"
Include dependency graph for Languages.cpp:

Go to the source code of this file.


namespace  Languages


using LangHash = std::unordered_map< wxString, TranslatableString >
using ReverseLangHash = std::unordered_map< TranslatableString, wxString >


static void FindFilesInPathList (const wxString &pattern, const FilePaths &pathList, FilePaths &results)
static bool TranslationExists (const FilePaths &pathList, wxString code)
wxString Languages::GetSystemLanguageCode (const FilePaths &pathList)
void Languages::GetLanguages (FilePaths pathList, wxArrayString &langCodes, TranslatableStrings &langNames)
wxString Languages::SetLang (const FilePaths &pathList, const wxString &lang)
wxString Languages::GetLocaleName ()
wxString Languages::GetLang ()
wxString Languages::GetLangShort ()


static std::unique_ptr< wxLocale > Languages::sLocale
static wxString Languages::sLocaleName

Detailed Description

Determine installed languages.

Figure out what translations are installed and return a list of language codes (like "es", "fr", or "pt-br") and corresponding language names (like "Español", "Français", and "Português"). We use our own list of translations of language names (i.e. "Français" instead of "French") but we fallback on the language name in wxWidgets if we don't have it listed.

This code is designed to work well with all of the current languages, but adapt to any language that wxWidgets supports. Other languages will only be supported if they're added to the database using wxLocale::AddLanguage.

But for the most part, this means that somebody could add a NEW translation and have it work immediately.

Definition in file Languages.cpp.

Typedef Documentation

◆ LangHash

using LangHash = std::unordered_map<wxString, TranslatableString>

Definition at line 52 of file Languages.cpp.

◆ ReverseLangHash

using ReverseLangHash = std::unordered_map<TranslatableString, wxString>

Definition at line 53 of file Languages.cpp.

Function Documentation

◆ FindFilesInPathList()

static void FindFilesInPathList ( const wxString &  pattern,
const FilePaths pathList,
FilePaths results 

Definition at line 55 of file Languages.cpp.

58 wxFileName ff;
59 for (const auto &path : pathList) {
60 ff = path + wxFILE_SEP_PATH + pattern;
61 wxDir::GetAllFiles(ff.GetPath(), &results, ff.GetFullName(), wxDIR_FILES);
62 }

Referenced by TranslationExists().

Here is the caller graph for this function:

◆ TranslationExists()

static bool TranslationExists ( const FilePaths pathList,
wxString  code 

Definition at line 65 of file Languages.cpp.

67 FilePaths results;
68 FindFilesInPathList(code + L"/", pathList, results);
69#if defined(__WXMAC__)
70 FindFilesInPathList(code + L".lproj/", pathList, results);
72 FindFilesInPathList(code + L"/LC_MESSAGES/", pathList, results);
73 return (results.size() > 0);
static void FindFilesInPathList(const wxString &pattern, const FilePaths &pathList, FilePaths &results)
Definition: Languages.cpp:55
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.

References FindFilesInPathList().

Referenced by Languages::GetLanguages().

Here is the call graph for this function:
Here is the caller graph for this function: