Skip to content

Commit

Permalink
Translate MessageBoxes to Italian; fix some bugs
Browse files Browse the repository at this point in the history
FIX: Fix a race condition in the "Validate files with JSON schema if name matches pattern" plugin command,
    which could cause the plugin to crash in some cases
CHANGE: Make some error messages clearer
FEAT: Translate all MessageBox captions and text to Italian (using Google Translate)
FEAT: Add Italian translation (using Google Translate) of:
    - All MessageBox captions and text
    - comments at start of schemasToFnamePatterns.json
    - tree node right-click context menu
  • Loading branch information
molsonkiko committed Aug 15, 2024
1 parent 66a81e3 commit db0a003
Show file tree
Hide file tree
Showing 10 changed files with 580 additions and 143 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4. Make it so JsonTools simply does nothing rather than causing Notepad++ to crash when attempting to run plugin commands on files with more than 2147483647 bytes.
5. Fixed number precision bug ([issue 78](https://github.com/molsonkiko/JsonToolsNppPlugin/issues/78)).
6. Rare bug [generating schemas from JSON](/docs/README.md#generating-json-schema-from-json), only seen with some arrays of objects.
7. Rare crash when saving [`schemasToFnamePatterns.json`](/docs/README.md#automatic-validation-of-json-against-json-schema) if [automatic validation after editing](/docs/README.md#automatically-check-for-errors-after-editing) is enabled.

## [8.0.0] - 2024-06-29

Expand Down
2 changes: 1 addition & 1 deletion JsonToolsNppPlugin/Forms/JsonToCsvForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Stringify iterables
{
Translator.ShowTranslatedMessageBox(
"While trying to create CSV from JSON, raised this exception:\r\n{0}",
"Exception while tabularizing JSON",
"Exception while converting JSON to CSV",
MessageBoxButtons.OK,
MessageBoxIcon.Error,
1, RemesParser.PrettifyException(ex));
Expand Down
2 changes: 1 addition & 1 deletion JsonToolsNppPlugin/Forms/SortForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void SortButton_Clicked(object sender, EventArgs e)
else
{
string gotType = JNode.FormatDtype(jsonAtPath.type);
Translator.ShowTranslatedMessageBox("JSON at the specified path must be object or array, got {0}",
Translator.ShowTranslatedMessageBox("JSON at the specified path must be object or array, got type {0}",
"JSON at specified path must be object or array",
MessageBoxButtons.OK, MessageBoxIcon.Error,
1, gotType);
Expand Down
30 changes: 28 additions & 2 deletions JsonToolsNppPlugin/Forms/TreeViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,32 @@ private void Tree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
}
NodeRightClickMenu.Show(MousePosition);
}
if (Translator.TryGetTranslationAtPath(new string[] {"forms", "TreeViewer", "controls"}, out JNode controlsTranslationsNode)
&& controlsTranslationsNode is JObject controlTranslations)
{
string[] controlNames = new string[] { "CopyValueMenuItem", "CopyKeyItem", "CopyPathItem", "ToggleSubtreesItem", "SelectThisItem", "OpenSortFormItem", "SelectAllChildrenItem" };
for (int ii = 0; ii < controlNames.Length; ii++)
{
string name = controlNames[ii];
if (controlTranslations.TryGetValue(name, out JNode translatedTextNode)
&& translatedTextNode.value is string s)
NodeRightClickMenu.Items[ii].Text = s;
}
if (controlTranslations.TryGetValue("LanguageNameStyleItem", out JNode langNameStyleNode) && langNameStyleNode.value is string langNameStyle && langNameStyle.Contains("{0}"))
{
PythonStyleItem.Text = string.Format(langNameStyle, "Python");
PythonStylePathItem.Text = string.Format(langNameStyle, "Python");
JavaScriptStyleItem.Text = string.Format(langNameStyle, "JavaScript");
JavaScriptStylePathItem.Text = string.Format(langNameStyle, "JavaScript");
RemesPathStyleItem.Text = string.Format(langNameStyle, "RemesPath");
RemesPathStylePathItem.Text = string.Format(langNameStyle, "RemesPath");
}
if (controlTranslations.TryGetValue("PathSeparatorStyleItem", out JNode pathSepStyleNode) && pathSepStyleNode.value is string pathSepStyleText)
{
path_separatorStyleItem.Text = pathSepStyleText;
path_separatorStylePathItem.Text = pathSepStyleText;
}
}
if (node.IsSelected)
// normally clicking a node selects it, so we don't need to explicitly invoke this method
// but if the node was already selected, we need to call it
Expand Down Expand Up @@ -1188,10 +1214,10 @@ public string KeyOfTreeNode(TreeNode node, KeyStyle style, char separator = JNod
catch (Exception ex)
{
Translator.ShowTranslatedMessageBox(
"While attempting to format key {0} using style, the following error occurred:\r\n{1}",
"While attempting to format key {0} using style {1}, the following error occurred:\r\n{2}",
"Error while formatting key of tree node",
MessageBoxButtons.OK, MessageBoxIcon.Error,
2, node.Name, ex);
2, node.Name, style, ex);
return "";
}
}
Expand Down
5 changes: 5 additions & 0 deletions JsonToolsNppPlugin/JSONTools/JNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,11 @@ public JRegex(Regex regex) : base(null, Dtype.REGEX, 0)
{
this.regex = regex;
}

public override JNode Copy()
{
return new JRegex(regex);
}
}

[System.Diagnostics.DebuggerDisplay("JSlicer({slicer})")]
Expand Down
54 changes: 36 additions & 18 deletions JsonToolsNppPlugin/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ public static void CompressJson()
catch (Exception ex)
{
Translator.ShowTranslatedMessageBox(
"While attempting to reformat the file's JSON, got a programmatic error:\r\n{0}",
"While attempting to reformat the file's JSON, got a programmatic error (likely due to a mistake in the source code):\r\n{0}",
"Programmatic error while reformatting JSON",
MessageBoxButtons.OK, MessageBoxIcon.Error,
1, RemesParser.PrettifyException(ex)
Expand Down Expand Up @@ -1794,13 +1794,31 @@ static void GenerateRandomJson()
static void WriteSchemasToFnamePatternsFile(JObject schemasToPatterns)
{
Npp.CreateConfigSubDirectoryIfNotExists();
List<string> commentsAtStartOfFile;
if (Translator.TryGetTranslationAtPath(new string[] {"fileComments", "schemasToFnamePatterns.json"}, out JNode fileCommentsNode)
&& fileCommentsNode is JArray fileCommentsArr)
{
commentsAtStartOfFile = new List<string>();
foreach (JNode child in fileCommentsArr.children)
{
if (child.value is string s)
commentsAtStartOfFile.Add("// " + s);
}
}
else
{
commentsAtStartOfFile = new List<string> {
"// this file determines when automatic JSON validation should be performed",
"// each key must be the filename of a JSON schema file",
"// each value must be a non-empty list of valid C# regular expressions (e.g., [\"blah.*\\\\.txt\"])",
"// thus, if this file contained {\"c:\\\\path\\\\to\\\\foo_schema.json\": [\"blah.*\\\\.txt\"]}",
"// it would automatically perform validation using \"c:\\\\path\\\\to\\\\foo_schema.json\" whenever a \".txt\" file with the substring \"blah\" in its name was opened.",
};
}
using (var fp = new StreamWriter(schemasToFnamePatternsFname, false, Encoding.UTF8))
{
fp.WriteLine("// this file determines when automatic JSON validation should be performed");
fp.WriteLine("// each key must be the filename of a JSON schema file");
fp.WriteLine("// each value must be a non-empty list of valid C# regular expressions (e.g., [\"blah.*\\\\.txt\"]");
fp.WriteLine("// thus, if this file contained {\"c:\\\\path\\\\to\\\\foo_schema.json\": [\"blah.*\\\\.txt\"]}");
fp.WriteLine("// it would automatically perform validation using \"c:\\\\path\\\\to\\\\foo_schema.json\" whenever a \".txt\" file with the substring \"blah\" in its name was opened.");
foreach (string comment in commentsAtStartOfFile)
fp.WriteLine(comment);
fp.Write(schemasToPatterns.PrettyPrint());
fp.Flush();
}
Expand All @@ -1827,8 +1845,8 @@ static void ParseSchemasToFnamePatternsFile()
catch (Exception ex)
{
Translator.ShowTranslatedMessageBox(
"Failed to parse the schemas to fname patterns file. Got error\r\n{0}",
"Couldn't parse schemas to fname patterns file",
"Failed to parse schemasToFnamePatterns.json. Got error\r\n{0}",
"Couldn't parse schemasToFnamePatterns.json",
MessageBoxButtons.OK, MessageBoxIcon.Error,
1, ex);
return;
Expand All @@ -1840,8 +1858,8 @@ static void ParseSchemasToFnamePatternsFile()
if (!validates && lints.Count > 0)
{
Translator.ShowTranslatedMessageBox(
"Validation of the schemas to fnames patterns JSON must be an object mapping filenames to non-empty arrays of valid regexes (strings).\r\nThere were the following validation problem(s):\r\n{0}",
"schemas to fnames patterns JSON badly formatted",
"schemasToFnamePatterns.json must be an object mapping filenames to non-empty arrays of valid regexes (strings).\r\nThere were the following validation problem(s):\r\n{0}",
"schemasToFnamePatterns.json badly formatted",
MessageBoxButtons.OK, MessageBoxIcon.Error,
1, JsonSchemaValidator.LintsAsJArrayString(lints));
schemasToFnamePatterns = new JObject();
Expand All @@ -1857,15 +1875,15 @@ static void ParseSchemasToFnamePatternsFile()
{
if (!new FileInfo(fname).Exists)
{
Translator.ShowTranslatedMessageBox(msgIfBadFname, msgIfBadFname, MessageBoxButtons.OK, MessageBoxIcon.Error, 1, fname);
Translator.ShowTranslatedMessageBox(msgIfBadFname, msgIfBadFname, MessageBoxButtons.OK, MessageBoxIcon.Error, 1, fname, fname);
schemasToFnamePatterns.children.Remove(fname);
continue;
}

}
catch
{
Translator.ShowTranslatedMessageBox(msgIfBadFname, msgIfBadFname, MessageBoxButtons.OK, MessageBoxIcon.Error, 1, fname);
Translator.ShowTranslatedMessageBox(msgIfBadFname, msgIfBadFname, MessageBoxButtons.OK, MessageBoxIcon.Error, 1, fname, fname);
schemasToFnamePatterns.children.Remove(fname);
continue;
}
Expand All @@ -1884,7 +1902,7 @@ static void ParseSchemasToFnamePatternsFile()
{
Translator.ShowTranslatedMessageBox(
"While testing all the regexes associated with file {0},\r\nregular expression {1} failed to compile due to an error:\r\n{2}",
"Regex did not compile (in schemas to fname patterns file)",
"Regex did not compile (in schemasToFnamePatterns.json)",
MessageBoxButtons.OK, MessageBoxIcon.Error,
3, fname, pattern, ex);
}
Expand All @@ -1898,7 +1916,7 @@ static void ParseSchemasToFnamePatternsFile()
}

/// <summary>
/// open the schemas to fname patterns file in Notepad++ so the user can edit it
/// open schemasToFnamePatterns.json in Notepad++ so the user can edit it
/// </summary>
static void MapSchemasToFnamePatterns()
{
Expand All @@ -1925,13 +1943,13 @@ static bool ValidateIfFilenameMatches(string fname, bool wasAutotriggered = fals
{
if (wasAutotriggered && Npp.editor.GetLength() > Main.settings.max_file_size_MB_slow_actions * 1e6)
return false;
foreach (string schemaFname in schemasToFnamePatterns.children.Keys)
foreach (string schemaFname in schemasToFnamePatterns.children.Keys.ToArray())
{
JArray fnamePatterns = (JArray)schemasToFnamePatterns[schemaFname];
foreach (JNode pat in fnamePatterns.children)
foreach (JNode pat in fnamePatterns.children.ToArray())
{
var regex = ((JRegex)pat).regex;
if (!regex.IsMatch(fname)) continue;
if (!(pat is JRegex jregex && jregex.regex.IsMatch(fname)))
continue;
// the filename matches a pattern for this schema, so we'll try to validate it.
ValidateJson(schemaFname, false, true, wasAutotriggered);
return true;
Expand Down
4 changes: 2 additions & 2 deletions JsonToolsNppPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("8.0.0.20")]
[assembly: AssemblyFileVersion("8.0.0.20")]
[assembly: AssemblyVersion("8.0.0.21")]
[assembly: AssemblyFileVersion("8.0.0.21")]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ To translate JsonTools to another language, just look at [`english.json5` in the
Currently JsonTools has been translated into the following languages:
| Language | First version with translation | Translator(s) | Translator is native speaker? |
|----------|--------------------------------|---------------|--------------------------------|
| [Italian](https://github.com/molsonkiko/JsonToolsNppPlugin/blob/main/translation/italian.json5) | [v8.0](/CHANGELOG.md#800---2024-06-29) | [conky77](https://github.com/conky77), [molsonkiko](https://github.com/molsonkiko) (only for `jsonLint` section) | Only conky77 |
| [Italian](https://github.com/molsonkiko/JsonToolsNppPlugin/blob/main/translation/italian.json5) | [v8.0](/CHANGELOG.md#800---2024-06-29) | [conky77](https://github.com/conky77), [molsonkiko](https://github.com/molsonkiko) (only for `messageBoxes` and `fileComments` sections) | Only conky77 |


The following aspects of JsonTools __can__ be translated:
Expand All @@ -175,6 +175,7 @@ The following aspects of JsonTools __can__ be translated:
The following aspects of JsonTools __may eventually__ be translated:
- This documentation
- Generic modal dialogs (for example, file-opening dialogs, directory selection dialogs)
- Error messsages (other than JSON syntax errors, which are already translated)

## Acknowledgments ##

Expand Down
Loading

0 comments on commit db0a003

Please sign in to comment.