// returns a wxString for the this accelerator.
// this function formats it using the <flags>-<keycode> format
// where <flags> maybe a hyphen-separated list of "shift|alt|ctrl"
- wxString ToString() const;
+ wxString ToString() const { return AsPossiblyLocalizedString(true); }
+
+ // same as above but without translating, useful if the string is meant to
+ // be stored in a file or otherwise stored, instead of being shown to the
+ // user
+ wxString ToRawString() const { return AsPossiblyLocalizedString(false); }
// returns true if the given string correctly initialized this object
// (i.e. if IsOk() returns true after this call)
private:
+ wxString AsPossiblyLocalizedString(bool localized) const;
+
// common part of Create() and FromString()
static bool ParseAccel(const wxString& str, int *flags, int *keycode);
*/
wxString ToString() const;
+ /**
+ Returns a textual representation of this accelerator which is
+ appropriate for saving in configuration files.
+
+ Unlike the string returned by ToString(), this one is never translated
+ so, while it's not suitable for showing to the user, it can be used to
+ uniquely identify the accelerator independently of the user language.
+
+ The returned string can still be parsed by FromString().
+
+ @since 2.9.4
+ */
+ wxString ToRawString() const;
+
/**
Parses the given string and sets the accelerator accordingly.
return ParseAccel(str, &m_flags, &m_keyCode);
}
-wxString wxAcceleratorEntry::ToString() const
+namespace
+{
+
+wxString PossiblyLocalize(const wxString& str, bool localize)
+{
+ return localize ? wxGetTranslation(str) : str;
+}
+
+}
+
+wxString wxAcceleratorEntry::AsPossiblyLocalizedString(bool localized) const
{
wxString text;
int flags = GetFlags();
if ( flags & wxACCEL_ALT )
- text += _("Alt+");
+ text += PossiblyLocalize(wxTRANSLATE("Alt+"), localized);
if ( flags & wxACCEL_CTRL )
- text += _("Ctrl+");
+ text += PossiblyLocalize(wxTRANSLATE("Ctrl+"), localized);
if ( flags & wxACCEL_SHIFT )
- text += _("Shift+");
+ text += PossiblyLocalize(wxTRANSLATE("Shift+"), localized);
#if defined(__WXMAC__) || defined(__WXCOCOA__)
if ( flags & wxACCEL_RAW_CTRL )
- text += _("RawCtrl+");
+ text += PossiblyLocalize(wxTRANSLATE("RawCtrl+"), localized);
#endif
const int code = GetKeyCode();
if ( code >= WXK_F1 && code <= WXK_F12 )
- text << _("F") << code - WXK_F1 + 1;
+ text << PossiblyLocalize(wxTRANSLATE("F"), localized)
+ << code - WXK_F1 + 1;
else if ( code >= WXK_NUMPAD0 && code <= WXK_NUMPAD9 )
- text << _("KP_") << code - WXK_NUMPAD0;
+ text << PossiblyLocalize(wxTRANSLATE("KP_"), localized)
+ << code - WXK_NUMPAD0;
else if ( code >= WXK_SPECIAL1 && code <= WXK_SPECIAL20 )
- text << _("SPECIAL") << code - WXK_SPECIAL1 + 1;
+ text << PossiblyLocalize(wxTRANSLATE("SPECIAL"), localized)
+ << code - WXK_SPECIAL1 + 1;
else // check the named keys
{
size_t n;
const wxKeyName& kn = wxKeyNames[n];
if ( code == kn.code )
{
- text << wxGetTranslation(kn.name);
+ text << PossiblyLocalize(kn.name, localized);
break;
}
}