1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-07 07:12:34 +02:00

Fix format of tooltip text for toolbar buttons in RTL languages...

... No translatable strings were added, two were removed
This commit is contained in:
Paul Licameli 2017-09-11 21:11:42 -04:00
parent 954a974422
commit 731a2ac40c
6 changed files with 37 additions and 25 deletions

View File

@ -298,12 +298,3 @@ wxString Internat::StripAccelerators(const wxString &s)
} }
return result; return result;
} }
wxString Internat::Parenthesize(const wxString &str)
{
/* i18n-hint: An opening parenthesis, in some languages a right parenthesis */
auto open = _("(");
/* i18n-hint: A closing parenthesis, in some languages a left parenthesis */
auto close = _(")");
return open + str + close;
}

View File

@ -76,8 +76,6 @@ public:
* when they aren't, saving translators effort. */ * when they aren't, saving translators effort. */
static wxString StripAccelerators(const wxString& str); static wxString StripAccelerators(const wxString& str);
static wxString Parenthesize(const wxString &str);
static const wxArrayString &GetExcludedCharacters() static const wxArrayString &GetExcludedCharacters()
{ return exclude; } { return exclude; }

View File

@ -1287,24 +1287,51 @@ void CommandManager::TellUserWhyDisallowed( const wxString & Name, CommandFlag f
} }
wxString CommandManager::DescribeCommandsAndShortcuts wxString CommandManager::DescribeCommandsAndShortcuts
(const std::vector<wxString> &commands, const wxString &separator) const (const std::vector<wxString> &commands) const
{ {
wxString mark;
// This depends on the language setting and may change in-session after
// change of preferences:
bool rtl = (wxLayout_RightToLeft == wxTheApp->GetLayoutDirection());
if (rtl)
mark = wxT("\u200f");
static const wxString &separatorFormat = wxT("%s / %s");
wxString result; wxString result;
auto iter = commands.begin(), end = commands.end(); auto iter = commands.begin(), end = commands.end();
while (iter != end) { while (iter != end) {
result += *iter++; // If RTL, then the control character forces right-to-left sequencing of
// "/" -separated command names, and puts any "(...)" shortcuts to the
// left, consistently with accelerators in menus (assuming matching
// operating system prefernces for language), even if the command name
// was missing from the translation file and defaulted to the English.
auto piece = wxString::Format(wxT("%s%s"), mark, *iter++);
if (iter != end) { if (iter != end) {
if (!iter->empty()) { if (!iter->empty()) {
auto keyStr = GetKeyFromName(*iter); auto keyStr = GetKeyFromName(*iter);
if (!keyStr.empty()){ if (!keyStr.empty()){
result += wxT(" "); auto keyString = KeyStringDisplay(keyStr, true);
result += Internat::Parenthesize(KeyStringDisplay(keyStr, true)); auto format = wxT("%s %s(%s)");
#ifdef __WXMAC__
// The unicode controls push and pop left-to-right embedding.
// This keeps the directionally weak characters, such as uparrow
// for Shift, left of the key name,
// consistently with how menu accelerators appear, even when the
// system language is RTL.
format = wxT("%s %s(\u202a%s\u202c)");
#endif
// The mark makes correctly placed parentheses for RTL, even
// in the case that the piece is untranslated.
piece = wxString::Format(format, piece, mark, keyString);
} }
} }
++iter; ++iter;
} }
if (iter != end) if (result.empty())
result += separator; result = piece;
else
result = wxString::Format(separatorFormat, result, piece);
} }
return result; return result;
} }

View File

@ -270,9 +270,7 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
// non-user-visible command names. If a shortcut key is defined // non-user-visible command names. If a shortcut key is defined
// for the command, then it is appended, parenthesized, after the // for the command, then it is appended, parenthesized, after the
// user-visible string. // user-visible string.
const std::vector<wxString> &commands, const std::vector<wxString> &commands) const;
// If more than one pair of strings is given, then use this separator.
const wxString &separator = wxT(" / ")) const;
protected: protected:

View File

@ -832,7 +832,7 @@ void ToolBar::MakeAlternateImages(AButton &button, int idx,
} }
void ToolBar::SetButtonToolTip void ToolBar::SetButtonToolTip
(AButton &button, const std::vector<wxString> &commands, const wxString &separator) (AButton &button, const std::vector<wxString> &commands)
{ {
wxString result; wxString result;
const auto project = GetActiveProject(); const auto project = GetActiveProject();
@ -840,7 +840,7 @@ void ToolBar::SetButtonToolTip
project ? project->GetCommandManager() : nullptr; project ? project->GetCommandManager() : nullptr;
if (commandManager) if (commandManager)
result = result =
commandManager->DescribeCommandsAndShortcuts(commands, separator); commandManager->DescribeCommandsAndShortcuts(commands);
button.SetToolTip(result); button.SetToolTip(result);
} }

View File

@ -161,9 +161,7 @@ class ToolBar /* not final */ : public wxPanelWrapper
// non-user-visible command names. If a shortcut key is defined // non-user-visible command names. If a shortcut key is defined
// for the command, then it is appended, parenthesized, after the // for the command, then it is appended, parenthesized, after the
// user-visible string. // user-visible string.
const std::vector<wxString> &commands, const std::vector<wxString> &commands);
// If more than one pair of strings is given, then use this separator.
const wxString &separator = wxT(" / "));
protected: protected:
void SetButton(bool down, AButton *button); void SetButton(bool down, AButton *button);