Skip to content

Commit

Permalink
Merge branch 'release/v1.2' of github.com:ONLYOFFICE/AppServer into r…
Browse files Browse the repository at this point in the history
…elease/v1.2
  • Loading branch information
gopienkonikita committed May 24, 2022
2 parents 59d860b + ea4bfc9 commit f9f36e9
Show file tree
Hide file tree
Showing 146 changed files with 982 additions and 558 deletions.
149 changes: 79 additions & 70 deletions common/Tests/Frontend.Translations.Tests/LocalesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

using NUnit.Framework;

using UtfUnknown;

using WeCantSpell.Hunspell;

namespace Frontend.Translations.Tests
Expand All @@ -35,25 +33,25 @@ public static string BasePath
public List<KeyValuePair<string, string>> NotTranslatedToasts { get; set; }
public List<LanguageItem> CommonTranslations { get; set; }
public List<ParseJsonError> ParseJsonErrors { get; set; }
public List<JsonEncodingError> WrongEncodingJsonErrors { get; set; }
//public List<JsonEncodingError> WrongEncodingJsonErrors { get; set; }

private static string _md5ExcludesPath = "../../../md5-excludes.json";

private static string _encodingExcludesPath = "../../../encoding-excludes.json";
//private static string _encodingExcludesPath = "../../../encoding-excludes.json";

private static List<string> md5Excludes = File.Exists(_md5ExcludesPath)
? JsonConvert.DeserializeObject<List<string>>(File.ReadAllText(_md5ExcludesPath))
: new List<string>();

private static List<string> encodingExcludes = File.Exists(_encodingExcludesPath)
? JsonConvert.DeserializeObject<List<string>>(File.ReadAllText(_encodingExcludesPath))
: new List<string>();
//private static List<string> encodingExcludes = File.Exists(_encodingExcludesPath)
// ? JsonConvert.DeserializeObject<List<string>>(File.ReadAllText(_encodingExcludesPath))
// : new List<string>();

[OneTimeSetUp]
public void Setup()
{
ParseJsonErrors = new List<ParseJsonError>();
WrongEncodingJsonErrors = new List<JsonEncodingError>();
//WrongEncodingJsonErrors = new List<JsonEncodingError>();

var packageJsonPath = Path.Combine(BasePath, @"package.json");

Expand Down Expand Up @@ -82,13 +80,13 @@ where filePath.Contains("public\\locales\\")
{
try
{
var result = CharsetDetector.DetectFromFile(path);
//var result = CharsetDetector.DetectFromFile(path);

if (!encodingExcludes.Contains(result.Detected.EncodingName))
{
WrongEncodingJsonErrors.Add(
new JsonEncodingError(path, result.Detected));
}
//if (!encodingExcludes.Contains(result.Detected.EncodingName))
//{
// WrongEncodingJsonErrors.Add(
// new JsonEncodingError(path, result.Detected));
//}

#if SORT

Expand Down Expand Up @@ -345,6 +343,17 @@ public void SpellCheckTest()
Assert.AreEqual(0, errorsCount, message);
}

[Test]
[Category("FastRunning")]
public void SingleKeyFilesTest()
{
var singleKeyTranslationFiles = TranslationFiles
.Where(t => t.Language == "en" && t.Translations.Count == 1)
.ToList();

Assert.AreEqual(0, singleKeyTranslationFiles.Count, "Translations files with single key:\r\n" + string.Join("\r\n", singleKeyTranslationFiles.Select(d => $"\r\nKey='{d.Translations.First().Key}':\r\n{d.FilePath}'")));
}

[Test]
[Category("FastRunning")]
public void DublicatesFilesByMD5HashTest()
Expand Down Expand Up @@ -1064,25 +1073,25 @@ public void WrongTranslationVariablesTest()
Assert.AreEqual(0, errorsCount, message);
}

[Test]
[Category("FastRunning")]
public void TranslationsEncodingTest()
{
/*//Convert to UTF-8
foreach (var issue in WrongEncodingJsonErrors)
{
if (issue.DetectionDetail.Encoding == null)
continue;
//[Test]
//[Category("FastRunning")]
//public void TranslationsEncodingTest()
//{
// /*//Convert to UTF-8
// foreach (var issue in WrongEncodingJsonErrors)
// {
// if (issue.DetectionDetail.Encoding == null)
// continue;

ConvertFileEncoding(issue.Path, issue.Path, issue.DetectionDetail.Encoding, Encoding.UTF8);
}*/
// ConvertFileEncoding(issue.Path, issue.Path, issue.DetectionDetail.Encoding, Encoding.UTF8);
// }*/

var message = $"Next files have encoding issues:\r\n\r\n";
// var message = $"Next files have encoding issues:\r\n\r\n";

Assert.AreEqual(0, WrongEncodingJsonErrors.Count,
message + string.Join("\r\n", WrongEncodingJsonErrors
.Select(e => $"File path = '{e.Path}' potentially wrong file encoding: {e.DetectionDetail.EncodingName}")));
}
// Assert.AreEqual(0, WrongEncodingJsonErrors.Count,
// message + string.Join("\r\n", WrongEncodingJsonErrors
// .Select(e => $"File path = '{e.Path}' potentially wrong file encoding: {e.DetectionDetail.EncodingName}")));
//}

/// <summary>
/// Converts a file from one encoding to another.
Expand All @@ -1091,46 +1100,46 @@ public void TranslationsEncodingTest()
/// <param name=”destPath”>the destination for the converted file</param>
/// <param name=”sourceEncoding”>the original file encoding</param>
/// <param name=”destEncoding”>the encoding to which the contents should be converted</param>
public static void ConvertFileEncoding(string sourcePath, string destPath,
Encoding sourceEncoding, Encoding destEncoding)
{
// If the destination’s parent doesn’t exist, create it.
var parent = Path.GetDirectoryName(Path.GetFullPath(destPath));
if (!Directory.Exists(parent))
{
Directory.CreateDirectory(parent);
}
// If the source and destination encodings are the same, just copy the file.
if (sourceEncoding == destEncoding)
{
File.Copy(sourcePath, destPath, true);
return;
}
// Convert the file.
string tempName = null;
try
{
tempName = Path.GetTempFileName();
using (StreamReader sr = new StreamReader(sourcePath, sourceEncoding, false))
{
using (StreamWriter sw = new StreamWriter(tempName, false, destEncoding))
{
int charsRead;
char[] buffer = new char[128 * 1024];
while ((charsRead = sr.ReadBlock(buffer, 0, buffer.Length)) > 0)
{
sw.Write(buffer, 0, charsRead);
}
}
}
File.Delete(destPath);
File.Move(tempName, destPath);
}
finally
{
File.Delete(tempName);
}
}
//public static void ConvertFileEncoding(string sourcePath, string destPath,
// Encoding sourceEncoding, Encoding destEncoding)
//{
// // If the destination’s parent doesn’t exist, create it.
// var parent = Path.GetDirectoryName(Path.GetFullPath(destPath));
// if (!Directory.Exists(parent))
// {
// Directory.CreateDirectory(parent);
// }
// // If the source and destination encodings are the same, just copy the file.
// if (sourceEncoding == destEncoding)
// {
// File.Copy(sourcePath, destPath, true);
// return;
// }
// // Convert the file.
// string tempName = null;
// try
// {
// tempName = Path.GetTempFileName();
// using (StreamReader sr = new StreamReader(sourcePath, sourceEncoding, false))
// {
// using (StreamWriter sw = new StreamWriter(tempName, false, destEncoding))
// {
// int charsRead;
// char[] buffer = new char[128 * 1024];
// while ((charsRead = sr.ReadBlock(buffer, 0, buffer.Length)) > 0)
// {
// sw.Write(buffer, 0, charsRead);
// }
// }
// }
// File.Delete(destPath);
// File.Move(tempName, destPath);
// }
// finally
// {
// File.Delete(tempName);
// }
//}

/*[Test]
public void TempTest()
Expand Down

This file was deleted.

Loading

0 comments on commit f9f36e9

Please sign in to comment.