New library lib-strings for Identifier and internationalization

This commit is contained in:
Paul Licameli 2021-02-16 21:14:33 -05:00
parent 70c4898648
commit 45c6190c51
37 changed files with 75 additions and 50 deletions

View File

@ -4,6 +4,7 @@
# that it depends on
set( LIBRARIES
"lib-string-utils"
lib-strings
)
if ( ${_OPT}has_networking )

View File

@ -0,0 +1,35 @@
#[[
String wrapping types and internationalization support.
Identifier and specializations of TaggedIdentifier generate types of strings
used for different internal purposes, not meant for users to see (except
sometimes in macro programming), and the types do not implicitly interconvert.
TranslatableString holds the English msgid of a string meant for a user to see,
and can also bind formatting arguments. It can generate a translation later,
even if the global choice of locale changes during its lifetime. It does not
implicitly interconvert with wxString.
This library depends only on the wxBase subset of wxWidgets.
]]#
set( SOURCES
Identifier.cpp
Identifier.h
Internat.cpp
Internat.h
Languages.cpp
Languages.h
TranslatableString.cpp
TranslatableString.h
UnusedStrings.h
wxArrayStringEx.h
wxArrayStringEx.cpp
)
set( LIBRARIES
PRIVATE
wxBase
)
audacity_library( lib-strings "${SOURCES}" "${LIBRARIES}"
"" ""
)

View File

@ -18,7 +18,7 @@
/*! String manipulations are discouraged, other than splitting and joining on separator characters.
Wherever GET is used to fetch the underlying wxString, there should be a comment explaining the need for it.
*/
class AUDACITY_DLL_API Identifier
class STRINGS_API Identifier
{
public:

View File

@ -42,7 +42,7 @@ wxArrayString Internat::exclude;
// This function allows us to replace Audacity by DarkAudacity without peppering
// the source code with changes. We split out this step, the customisation, as
// it is used on its own (without translation) in the wxTS macro.
AUDACITY_DLL_API const wxString& GetCustomSubstitution(const wxString& str2)
STRINGS_API const wxString& GetCustomSubstitution(const wxString& str2)
{
// If contains 'DarkAudacity, already converted.
if( str2.Contains( "DarkAudacity" ))
@ -60,7 +60,7 @@ AUDACITY_DLL_API const wxString& GetCustomSubstitution(const wxString& str2)
return wxTranslations::GetUntranslatedString(str3);
}
#else
AUDACITY_DLL_API const wxString& GetCustomSubstitution(const wxString& str1)
STRINGS_API const wxString& GetCustomSubstitution(const wxString& str1)
{
return str1 ;
}
@ -68,7 +68,7 @@ AUDACITY_DLL_API const wxString& GetCustomSubstitution(const wxString& str1)
// In any translated string, we can replace the name 'Audacity' by 'DarkAudacity'
// without requiring translators to see extra strings for the two versions.
AUDACITY_DLL_API const wxString& GetCustomTranslation(const wxString& str1)
STRINGS_API const wxString& GetCustomTranslation(const wxString& str1)
{
const wxString& str2 = wxGetTranslation( str1 );
return GetCustomSubstitution( str2 );

View File

@ -20,8 +20,8 @@
class wxArrayString;
class wxArrayStringEx;
extern AUDACITY_DLL_API const wxString& GetCustomTranslation(const wxString& str1 );
extern AUDACITY_DLL_API const wxString& GetCustomSubstitution(const wxString& str1 );
extern STRINGS_API const wxString& GetCustomTranslation(const wxString& str1 );
extern STRINGS_API const wxString& GetCustomSubstitution(const wxString& str1 );
// Marks string for substitution only.
#define _TS( s ) GetCustomSubstitution( s )
@ -100,7 +100,7 @@ extern AUDACITY_DLL_API const wxString& GetCustomSubstitution(const wxString& st
#define XPC(sing, plur, n, c) \
TranslatableString{ wxT(sing), {} }.Context(c).Plural<(n)>( wxT(plur) )
class AUDACITY_DLL_API Internat
class STRINGS_API Internat
{
public:
/** \brief Initialize internationalisation support. Call this once at

View File

@ -36,6 +36,7 @@
#include "wxArrayStringEx.h"
#include "Internat.h"
#include "wxArrayStringEx.h"
#include <wx/defs.h>
#include <wx/dir.h>

View File

@ -26,33 +26,33 @@ namespace Languages {
(like "pt_BR")
@param[out] langNames corresponding autonyms of those languages (like "Português")
*/
AUDACITY_DLL_API
STRINGS_API
void GetLanguages( FilePaths pathList,
wxArrayString &langCodes, TranslatableStrings &langNames);
/*!
@param pathList paths to search for .mo files, grouped into subdirectories for the different languages
*/
AUDACITY_DLL_API
STRINGS_API
wxString GetSystemLanguageCode(const FilePaths &pathList);
/*!
@param audacityPathList paths to search for .mo files, grouped into subdirectories for the different languages
@param lang a language code; or if empty or "System", then default to system language.
@return the language code actually used which is not lang if lang cannot be found. */
AUDACITY_DLL_API
STRINGS_API
wxString SetLang( const FilePaths &audacityPathList, const wxString & lang );
/*! @return the last language code that was set */
AUDACITY_DLL_API
STRINGS_API
wxString GetLang();
/*! @return the last language code that was set (minus country code) */
AUDACITY_DLL_API
STRINGS_API
wxString GetLangShort();
/*! @return a string as from setlocale() */
AUDACITY_DLL_API
STRINGS_API
wxString GetLocaleName();
}

View File

@ -29,7 +29,7 @@ class Identifier;
Implicit conversions to and from wxString are intentionally disabled
*/
class AUDACITY_DLL_API TranslatableString {
class STRINGS_API TranslatableString {
enum class Request;
template< size_t N > struct PluralTemp;

View File

@ -156,14 +156,10 @@ list( APPEND SOURCES
HistoryWindow.cpp
HistoryWindow.h
HitTestResult.h
Identifier.cpp
Identifier.h
ImageManipulation.cpp
ImageManipulation.h
InconsistencyException.cpp
InconsistencyException.h
Internat.cpp
Internat.h
InterpolateAudio.cpp
InterpolateAudio.h
KeyboardCapture.cpp
@ -174,8 +170,6 @@ list( APPEND SOURCES
LabelTrack.h
LangChoice.cpp
LangChoice.h
Languages.cpp
Languages.h
Legacy.cpp
Legacy.h
LightThemeAsCeeCode.h
@ -326,13 +320,10 @@ list( APPEND SOURCES
TrackPanelResizerCell.h
TrackUtilities.cpp
TrackUtilities.h
TranslatableString.cpp
TranslatableString.h
UIHandle.cpp
UIHandle.h
UndoManager.cpp
UndoManager.h
UnusedStrings.h
UserException.cpp
UserException.h
ViewInfo.cpp
@ -349,8 +340,6 @@ list( APPEND SOURCES
ZoomInfo.cpp
ZoomInfo.h
float_cast.h
wxArrayStringEx.cpp
wxArrayStringEx.h
wxFileNameWrapper.h
# Commands

View File

@ -12,7 +12,7 @@
#ifndef __AUDACITY_KEYBOARD__
#define __AUDACITY_KEYBOARD__
#include "../Identifier.h"
#include "Identifier.h"
#include <wx/defs.h>
class wxKeyEvent;

View File

@ -23,7 +23,7 @@
#include <wx/simplebook.h>
#include <wx/valgen.h>
#include "../Internat.h"
#include "Internat.h"
#include "../Prefs.h"
#include "../ProjectFileManager.h"
#include "../Shuttle.h"

View File

@ -35,7 +35,8 @@ Functions that find and load all LV2 plugins on the system.
#include <wx/log.h>
#include <wx/string.h>
#include "../../Internat.h"
#include "Internat.h"
#include "wxArrayStringEx.h"
#include "LV2Effect.h"
#include "lv2/event/event.h"

View File

@ -54,7 +54,7 @@ effects from this one class.
#include "../EffectManager.h"
#include "../../FileNames.h"
#include "../../LabelTrack.h"
#include "../../Languages.h"
#include "Languages.h"
#include "../../NoteTrack.h"
#include "../../TimeTrack.h"
#include "../../prefs/SpectrogramSettings.h"

View File

@ -49,9 +49,9 @@ but little else.
#include <memory>
#include "audacity/Types.h"
#include "../Identifier.h"
#include "../Internat.h"
#include "../wxArrayStringEx.h"
#include "Identifier.h"
#include "Internat.h"
#include "wxArrayStringEx.h"
class AudacityProject;
class ProgressDialog;

View File

@ -21,7 +21,7 @@ setting used in debugging batch (aka macros) processing.
#include <wx/intl.h>
#include <wx/textdlg.h>
#include "../Languages.h"
#include "Languages.h"
#include "../Prefs.h"
#include "../ShuttleGui.h"

View File

@ -23,7 +23,7 @@
#include <wx/choice.h>
#include <wx/defs.h>
#include "../Languages.h"
#include "Languages.h"
#include "../PluginManager.h"
#include "../Prefs.h"
#include "../ShuttleGui.h"

View File

@ -24,7 +24,7 @@
#include <wx/defs.h>
#include "../FileNames.h"
#include "../Languages.h"
#include "Languages.h"
#include "../Theme.h"
#include "../Prefs.h"
#include "../ShuttleGui.h"

View File

@ -21,7 +21,6 @@ Paul Licameli
#include <algorithm>
#include "../FFT.h"
#include "../Internat.h"
#include "../Prefs.h"
#include <cmath>

View File

@ -11,7 +11,6 @@ Paul Licameli
#ifndef __AUDACITY_WAVEFORM_SETTINGS__
#define __AUDACITY_WAVEFORM_SETTINGS__
#include "../Internat.h" // for TranslatableStrings
#include "../Prefs.h"
class EnumValueSymbols;

View File

@ -8,7 +8,7 @@ Paul Licameli split from class WaveTrack
**********************************************************************/
#include "../../../../Internat.h"
#include "Internat.h"
#include "WaveTrackViewConstants.h"
// static

View File

@ -22,7 +22,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../widgets/Overlay.h" // to inherit
#include "../../commands/CommandContext.h"
#include "../../commands/CommandManager.h" // for MenuTable
#include "../../Identifier.h"
#include "Identifier.h"
class AudacityProject;
class TranslatableString;

View File

@ -9,7 +9,7 @@
**********************************************************************/
#include "AudacityMessageBox.h"
#include "../Internat.h"
#include "Internat.h"
TranslatableString AudacityMessageBoxCaptionStr()
{

View File

@ -12,7 +12,7 @@
#define __AUDACITY_MESSAGE_BOX__
#include <wx/msgdlg.h>
#include "../Internat.h"
#include "Internat.h"
extern AUDACITY_DLL_API TranslatableString AudacityMessageBoxCaptionStr();

View File

@ -19,7 +19,7 @@
#include <wx/defs.h>
#include <wx/menu.h>
#include "../Internat.h"
#include "Internat.h"
#include "../Prefs.h"
#include <mutex>

View File

@ -17,7 +17,7 @@
#include <wx/weakref.h> // member variable
#include "Identifier.h"
#include "../wxArrayStringEx.h"
#include "wxArrayStringEx.h"
class wxConfigBase;
class wxMenu;

View File

@ -31,7 +31,7 @@ around to NEW positions.
#include "../AColor.h"
#include "../AllThemeResources.h"
#include "../Internat.h"
#include "Internat.h"
#include "../Theme.h"
////////////////////////////////////////////////////////////

View File

@ -17,7 +17,7 @@
#include <wx/defs.h>
#include <wx/chartype.h> // for typedef wxChar
#include "../Internat.h" // for TranslatableStrings
#include "Internat.h" // for TranslatableStrings
class wxString;
const TranslatableString &DefaultMultiDialogMessage();

View File

@ -24,7 +24,7 @@
#include <wx/defs.h>
#include <wx/control.h> // to inherit
#include "../Internat.h"
#include "Internat.h"
// One event type for each type of control. Event is raised when a control
// changes its format. Owners of controls of the same type can listen and

View File

@ -25,7 +25,7 @@ class wxCommandEvent;
#include <wx/menu.h> // to inherit wxMenu
#include "../MemoryX.h"
#include "../Internat.h"
#include "Internat.h"
#include "../commands/CommandManager.h"
class PopupMenuHandler;

View File

@ -33,7 +33,7 @@
#endif
#include "../Internat.h"
#include "Internat.h"
#include <wx/intl.h>
#include <locale.h> // for setlocale and LC_ALL

View File

@ -28,7 +28,7 @@
#include <wx/setup.h> // for wxUSE_* macros
#include "AudacityMessageBox.h"
#include "../Internat.h"
#include "Internat.h"
#ifdef __BORLANDC__
#pragma hdrstop

View File

@ -13,7 +13,7 @@
#include <wx/panel.h> // to inherit
#include <wx/dialog.h> // to inherit
#include "../Internat.h"
#include "Internat.h"
#include "Identifier.h"