mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.9 KiB
62 lines
1.9 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Text.RegularExpressions;
|
|
using Squidex.Translator.State;
|
|
|
|
namespace Squidex.Translator.Processes
|
|
{
|
|
public class TranslateBackend
|
|
{
|
|
private readonly TranslationService service;
|
|
private readonly DirectoryInfo folder;
|
|
|
|
public TranslateBackend(DirectoryInfo folder, TranslationService service)
|
|
{
|
|
this.folder = Backend.GetFolder(folder);
|
|
|
|
this.service = service;
|
|
}
|
|
|
|
public void Run()
|
|
{
|
|
foreach (var (file, relativeName) in Backend.GetFilesCS(folder))
|
|
{
|
|
var content = File.ReadAllText(file.FullName);
|
|
|
|
var isReplaced = false;
|
|
|
|
content = Regex.Replace(content, "\"[^\"]*\"", match =>
|
|
{
|
|
var value = match.Value[1..^1];
|
|
|
|
string result = null;
|
|
|
|
if (value.IsPotentialMultiWordText())
|
|
{
|
|
service.Translate(relativeName, value, "Code", key =>
|
|
{
|
|
result = $"T.Get(\"{key}\")";
|
|
|
|
isReplaced = true;
|
|
});
|
|
}
|
|
|
|
return result ?? $"\"{value}\"";
|
|
});
|
|
|
|
if (isReplaced)
|
|
{
|
|
Console.WriteLine("-----------------------------");
|
|
Console.WriteLine("FILE {0} done", relativeName);
|
|
|
|
File.WriteAllText(file.FullName, content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|