Internationalize file type choices for Nyquist as we do in C++ ...
... That is, present translators with msgids containing only the descriptions of the file types. No punctuation. This eliminates the last wxFileDialog, replacing it with FileDialogWrapper.
This commit is contained in:
parent
3542eb4ca0
commit
f1ae8109ee
|
@ -20,7 +20,8 @@ $copyright (_ "Released under terms of the GNU General Public License version 2"
|
|||
$control fxname (_ "Select target EQ effect") choice (("Graphic" (_ "Graphic EQ"))
|
||||
("FilterCurve" (_ "Filter Curve EQ"))) 0
|
||||
|
||||
$control infile (_ "Equalization XML file") file "" "*default*/EQCurves.xml" "XML file|*.xml;*.XML|All files|*.*;*" "open,exists"
|
||||
$control infile (_ "Equalization XML file") file "" "*default*/EQCurves.xml" (((_ "XML file") (xml XML))
|
||||
((_ "All files") (""))) "open,exists"
|
||||
|
||||
$control overwrite (_ "If output text file exists") choice (("Append" (_ "Append number"))
|
||||
("Overwrite" (_ "Overwrite"))
|
||||
|
|
|
@ -17,7 +17,12 @@ $copyright (_ "Released under terms of the GNU General Public License version 2"
|
|||
|
||||
|
||||
;i18n-hint: "Browse..." is text on a button that launches a file browser.
|
||||
$control files (_ "Select file(s) to install") file (_ "Browse...") "~/Desktop/" "Plug-in|*.ny;*.NY|Lisp file|*.lsp;*.LSP|HTML file|*.htm;*.HTM;*.html;*.HTML|Text file|*.txt;*.TXT|All supported|*.ny;*.NY;*.lsp;*.LSP;*.htm;*.HTM;*.html;*.HTML;*.txt;*.TXT|All files|*.*;*" "open,exists,multiple"
|
||||
$control files (_ "Select file(s) to install") file (_ "Browse...") "~/Desktop/" (((_ "Plug-in") (ny NY))
|
||||
((_ "Lisp file") (lsp LSP))
|
||||
((_ "HTML file") (htm HTM html HTML))
|
||||
((_ "Text file") (txt TXT))
|
||||
((_ "All supported") (ny NY lsp LSP htm HTM html HTML txt TXT))
|
||||
((_ "All files") (""))) "open,exists,multiple"
|
||||
$control overwrite (_ "Allow overwriting") choice ((_ "Disallow") (_ "Allow")) 0
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,10 @@ $copyright (_ "Released under terms of the GNU General Public License version 2"
|
|||
|
||||
$control number (_ "Limit output to first") int-text (_ "samples") 100 1 1000000
|
||||
$control units (_ "Measurement scale") choice ((_ "dB") (_ "Linear")) 0
|
||||
$control filename (_ "Export data to") file (_ "Select a file") "*default*/sample-data.txt" "Text file|*.txt;*.TXT|CSV files|*.csv;*.CSV|HTML files|*.html;*.HTML;*.htm;*.HTM|All files|*.*;*" "save,overwrite"
|
||||
$control filename (_ "Export data to") file (_ "Select a file") "*default*/sample-data.txt" (((_ "Text file") (txt TXT))
|
||||
((_ "CSV files") (csv CSV))
|
||||
((_ "HTML files") (html HTML htm HTM))
|
||||
((_ "All files") (""))) "save,overwrite"
|
||||
$control fileformat (_ "Index (text files only)") choice ((_ "None")
|
||||
("Count" (_ "Sample Count"))
|
||||
("Time" (_ "Time Indexed")))
|
||||
|
|
|
@ -8,7 +8,8 @@ $author (_ "Steve Daulton")
|
|||
$release 2.3.0
|
||||
$copyright (_ "Released under terms of the GNU General Public License version 2")
|
||||
|
||||
$control filename (_ "Select file") file "" "*default*/sample-data.txt" "Text file|*.txt;*.TXT|All files|*.*;*" "open,exists"
|
||||
$control filename (_ "Select file") file "" "*default*/sample-data.txt" (((_ "Text file") (txt TXT))
|
||||
((_ "All files") (""))) "open,exists"
|
||||
$control bad-data (_ "Invalid data handling") choice (("ThrowError" (_ "Throw Error"))
|
||||
("ReadAsZero" (_ "Read as Zero"))) 0
|
||||
|
||||
|
|
|
@ -1657,6 +1657,48 @@ std::vector<EnumValueSymbol> NyquistEffect::ParseChoice(const wxString & text)
|
|||
return results;
|
||||
}
|
||||
|
||||
FileExtensions NyquistEffect::ParseFileExtensions(const wxString & text)
|
||||
{
|
||||
// todo: error handling
|
||||
FileExtensions results;
|
||||
if (text[0] == wxT('(')) {
|
||||
Tokenizer tzer;
|
||||
tzer.Tokenize(text, true, 1, 1);
|
||||
for (const auto &token : tzer.tokens)
|
||||
results.push_back( UnQuote( token ) );
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
FileNames::FileType NyquistEffect::ParseFileType(const wxString & text)
|
||||
{
|
||||
// todo: error handling
|
||||
FileNames::FileType result;
|
||||
if (text[0] == wxT('(')) {
|
||||
Tokenizer tzer;
|
||||
tzer.Tokenize(text, true, 1, 1);
|
||||
auto &tokens = tzer.tokens;
|
||||
if ( tokens.size() == 2 )
|
||||
result =
|
||||
{ UnQuoteMsgid( tokens[0] ), ParseFileExtensions( tokens[1] ) };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
FileNames::FileTypes NyquistEffect::ParseFileTypes(const wxString & text)
|
||||
{
|
||||
// todo: error handling
|
||||
FileNames::FileTypes results;
|
||||
if (text[0] == wxT('(')) {
|
||||
Tokenizer tzer;
|
||||
tzer.Tokenize(text, true, 1, 1);
|
||||
auto &types = tzer.tokens;
|
||||
for (auto &type : types)
|
||||
results.push_back( ParseFileType( type ) );
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
void NyquistEffect::RedirectOutput()
|
||||
{
|
||||
mRedirectOutput = true;
|
||||
|
@ -1686,7 +1728,7 @@ void NyquistEffect::Stop()
|
|||
mStop = true;
|
||||
}
|
||||
|
||||
wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens,
|
||||
TranslatableString NyquistEffect::UnQuoteMsgid(const wxString &s, bool allowParens,
|
||||
wxString *pExtraString)
|
||||
{
|
||||
if (pExtraString)
|
||||
|
@ -1695,7 +1737,8 @@ wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens,
|
|||
int len = s.length();
|
||||
if (len >= 2 && s[0] == wxT('\"') && s[len - 1] == wxT('\"')) {
|
||||
auto unquoted = s.Mid(1, len - 2);
|
||||
return wxGetTranslation( unquoted );
|
||||
// Sorry, no context strings, yet
|
||||
return TranslatableString{ unquoted, {} };
|
||||
}
|
||||
else if (allowParens &&
|
||||
len >= 2 && s[0] == wxT('(') && s[len - 1] == wxT(')')) {
|
||||
|
@ -1708,12 +1751,13 @@ wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens,
|
|||
// ("InternalString" (_ "Visible string"))
|
||||
// Recur to find the two strings
|
||||
*pExtraString = UnQuote(tokens[0], false);
|
||||
return UnQuote(tokens[1]);
|
||||
return UnQuoteMsgid(tokens[1]);
|
||||
}
|
||||
else {
|
||||
// Assume the first token was _ -- we don't check that
|
||||
// And the second is the string, which is internationalized
|
||||
return UnQuote( tokens[1], false );
|
||||
// Sorry, no context strings, yet
|
||||
return UnQuoteMsgid( tokens[1], false );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1721,7 +1765,13 @@ wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens,
|
|||
}
|
||||
else
|
||||
// If string was not quoted, assume no translation exists
|
||||
return s;
|
||||
return Verbatim( s );
|
||||
}
|
||||
|
||||
wxString NyquistEffect::UnQuote(const wxString &s, bool allowParens,
|
||||
wxString *pExtraString)
|
||||
{
|
||||
return UnQuoteMsgid( s, allowParens, pExtraString ).Translation();
|
||||
}
|
||||
|
||||
double NyquistEffect::GetCtrlValue(const wxString &s)
|
||||
|
@ -2088,6 +2138,13 @@ bool NyquistEffect::Parse(
|
|||
ctrl.choices = ParseChoice(ctrl.label);
|
||||
ctrl.label = wxT("");
|
||||
}
|
||||
else if (tokens[3] == wxT("file")) {
|
||||
ctrl.type = NYQ_CTRL_FILE;
|
||||
ctrl.fileTypes = ParseFileTypes(tokens[6]);
|
||||
// will determine file dialog styles:
|
||||
ctrl.highStr = UnQuote( tokens[7] );
|
||||
ctrl.label = wxT("");
|
||||
}
|
||||
else {
|
||||
ctrl.label = UnQuote( ctrl.label );
|
||||
|
||||
|
@ -2106,8 +2163,6 @@ bool NyquistEffect::Parse(
|
|||
ctrl.type = NYQ_CTRL_INT_TEXT;
|
||||
else if (tokens[3] == wxT("time"))
|
||||
ctrl.type = NYQ_CTRL_TIME;
|
||||
else if (tokens[3] == wxT("file"))
|
||||
ctrl.type = NYQ_CTRL_FILE;
|
||||
else
|
||||
{
|
||||
wxString str;
|
||||
|
@ -2767,18 +2822,11 @@ void NyquistEffect::BuildEffectWindow(ShuttleGui & S)
|
|||
S.AddSpace(10, 10);
|
||||
|
||||
// Get default file extension if specified in wildcards
|
||||
wxString defaultExtension;
|
||||
size_t len = ctrl.lowStr.length();
|
||||
int characters = ctrl.lowStr.Find("*");
|
||||
|
||||
if (characters != wxNOT_FOUND)
|
||||
{
|
||||
if (static_cast<int>(ctrl.lowStr.find("|", characters)) != wxNOT_FOUND)
|
||||
len = ctrl.lowStr.find("|", characters) - 1;
|
||||
if (static_cast<int>(ctrl.lowStr.find(";", characters)) != wxNOT_FOUND)
|
||||
len = std::min(static_cast<int>(len), static_cast<int>(ctrl.lowStr.find(";", characters)) - 1);
|
||||
|
||||
defaultExtension = ctrl.lowStr.wxString::Mid(characters + 1, len - characters);
|
||||
FileExtension defaultExtension;
|
||||
if (!ctrl.fileTypes.empty()) {
|
||||
const auto &type = ctrl.fileTypes[0];
|
||||
if ( !type.extensions.empty() )
|
||||
defaultExtension = type.extensions[0];
|
||||
}
|
||||
resolveFilePath(ctrl.valStr, defaultExtension);
|
||||
|
||||
|
@ -3014,36 +3062,6 @@ void NyquistEffect::OnFileButton(wxCommandEvent& evt)
|
|||
{
|
||||
int i = evt.GetId() - ID_FILE;
|
||||
NyqControl & ctrl = mControls[i];
|
||||
ctrl.lowStr.Trim(true).Trim(false); // Wildcard filter.
|
||||
|
||||
// Basic sanity check of wildcard flags so that we
|
||||
// don't show scary wxFAIL_MSG from wxParseCommonDialogsFilter.
|
||||
if (!ctrl.lowStr.empty())
|
||||
{
|
||||
bool validWildcards = true;
|
||||
size_t wildcards = 0;
|
||||
wxStringTokenizer tokenizer(ctrl.lowStr, "|");
|
||||
while (tokenizer.HasMoreTokens())
|
||||
{
|
||||
wxString token = tokenizer.GetNextToken().Trim(true).Trim(false);
|
||||
if (token.empty())
|
||||
{
|
||||
validWildcards = false;
|
||||
break;
|
||||
}
|
||||
wildcards += 1;
|
||||
}
|
||||
// Users should not normally see this, unless they are writing Nyquist plug-ins.
|
||||
if (wildcards % 2 != 0 || !validWildcards || ctrl.lowStr.EndsWith("|"))
|
||||
{
|
||||
Effect::MessageBox(
|
||||
XO("Invalid wildcard string in 'path' control.'\n"
|
||||
"Using empty string instead."),
|
||||
wxOK | wxICON_EXCLAMATION | wxCENTRE,
|
||||
XO("Error") );
|
||||
ctrl.lowStr = "";
|
||||
}
|
||||
}
|
||||
|
||||
// Get style flags:
|
||||
// Ensure legal combinations so that wxWidgets does not throw an assert error.
|
||||
|
@ -3087,18 +3105,18 @@ void NyquistEffect::OnFileButton(wxCommandEvent& evt)
|
|||
wxFileName fname = ctrl.valStr;
|
||||
wxString defaultDir = fname.GetPath();
|
||||
wxString defaultFile = fname.GetName();
|
||||
wxString message = _("Select a file");
|
||||
auto message = XO("Select a file");
|
||||
|
||||
if (flags & wxFD_MULTIPLE)
|
||||
message = _("Select one or more files");
|
||||
message = XO("Select one or more files");
|
||||
else if (flags & wxFD_SAVE)
|
||||
message = _("Save file as");
|
||||
message = XO("Save file as");
|
||||
|
||||
wxFileDialog openFileDialog(mUIParent->FindWindow(ID_FILE + i),
|
||||
FileDialogWrapper openFileDialog(mUIParent->FindWindow(ID_FILE + i),
|
||||
message,
|
||||
defaultDir,
|
||||
defaultFile,
|
||||
ctrl.lowStr, // wildcard filter
|
||||
ctrl.fileTypes,
|
||||
flags); // styles
|
||||
|
||||
if (openFileDialog.ShowModal() == wxID_CANCEL)
|
||||
|
@ -3128,7 +3146,7 @@ void NyquistEffect::OnFileButton(wxCommandEvent& evt)
|
|||
mUIParent->FindWindow(ID_Text + i)->GetValidator()->TransferToWindow();
|
||||
}
|
||||
|
||||
void NyquistEffect::resolveFilePath(wxString& path, wxString extension /* empty string */)
|
||||
void NyquistEffect::resolveFilePath(wxString& path, FileExtension extension /* empty string */)
|
||||
{
|
||||
#if defined(__WXMSW__)
|
||||
path.Replace("/", wxFileName::GetPathSeparator());
|
||||
|
@ -3181,7 +3199,7 @@ void NyquistEffect::resolveFilePath(wxString& path, wxString extension /* empty
|
|||
{
|
||||
path = fname.GetPathWithSep() + _("untitled");
|
||||
if (!extension.empty())
|
||||
path = path + extension;
|
||||
path = path + '.' + extension;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#define __AUDACITY_EFFECT_NYQUIST__
|
||||
|
||||
#include "../Effect.h"
|
||||
#include "../../FileNames.h"
|
||||
|
||||
#include "nyx.h"
|
||||
|
||||
|
@ -49,6 +50,7 @@ public:
|
|||
wxString name;
|
||||
wxString label;
|
||||
std::vector<EnumValueSymbol> choices;
|
||||
FileNames::FileTypes fileTypes;
|
||||
wxString valStr;
|
||||
wxString lowStr;
|
||||
wxString highStr;
|
||||
|
@ -137,6 +139,10 @@ private:
|
|||
wxString EscapeString(const wxString & inStr);
|
||||
static std::vector<EnumValueSymbol> ParseChoice(const wxString & text);
|
||||
|
||||
FileExtensions ParseFileExtensions(const wxString & text);
|
||||
FileNames::FileType ParseFileType(const wxString & text);
|
||||
FileNames::FileTypes ParseFileTypes(const wxString & text);
|
||||
|
||||
static int StaticGetCallback(float *buffer, int channel,
|
||||
long start, long len, long totlen,
|
||||
void *userdata);
|
||||
|
@ -161,7 +167,7 @@ private:
|
|||
bool q { false };
|
||||
int paren{ 0 };
|
||||
wxString tok;
|
||||
wxArrayString tokens;
|
||||
wxArrayStringEx tokens;
|
||||
|
||||
bool Tokenize(
|
||||
const wxString &line, bool eof,
|
||||
|
@ -169,6 +175,8 @@ private:
|
|||
};
|
||||
bool Parse(Tokenizer &tokenizer, const wxString &line, bool eof, bool first);
|
||||
|
||||
static TranslatableString UnQuoteMsgid(const wxString &s, bool allowParens = true,
|
||||
wxString *pExtraString = nullptr);
|
||||
static wxString UnQuote(const wxString &s, bool allowParens = true,
|
||||
wxString *pExtraString = nullptr);
|
||||
double GetCtrlValue(const wxString &s);
|
||||
|
@ -183,7 +191,7 @@ private:
|
|||
void OnTime(wxCommandEvent & evt);
|
||||
void OnFileButton(wxCommandEvent & evt);
|
||||
|
||||
void resolveFilePath(wxString & path, wxString extension = {});
|
||||
void resolveFilePath(wxString & path, FileExtension extension = {});
|
||||
bool validatePath(wxString path);
|
||||
wxString ToTimeFormat(double t);
|
||||
|
||||
|
|
Loading…
Reference in New Issue