1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2026-04-26 20:43:22 +02:00

Доработка проверки перевода

This commit is contained in:
Anton Titovets
2025-12-13 12:37:35 +03:00
parent 25c0436dc5
commit e7f5cec4d9
7 changed files with 5931 additions and 6033 deletions
-4
View File
@@ -2,15 +2,11 @@ src/ru/OPI/src/CommonModules/OPI_Тесты/** linguist-vendored
src/ru/OPI/src/CommonModules/OPI_ТестыCLI/** linguist-vendored
src/ru/OInt/** linguist-vendored
src/en/** linguist-vendored
service/** linguist-vendored
ci/** linguist-vendored
media/** linguist-vendored
docs/** linguist-vendored
src/ru/cli/data/Classes/internal/Classes/** linguist-vendored
src/en/cli/data/Classes/internal/Classes/** linguist-vendored
*.iss linguist-vendored
*.bat linguist-vendored
* text=auto
* text eol=lf
*.png binary
+120 -118
View File
@@ -1,11 +1,11 @@
-- Модуль для рекурсивного сканирования файлов на наличие кириллицы
local lfs = require("lfs")
-- Основная функция сканирования
function scan_directory_for_cyrillic(directory_path, extensions)
function scan_directory_for_cyrillic(directory_path, extensions, translation_dict_path)
local results = {}
-- Нормализуем расширения (добавляем точку если нет)
local translation_dict = {}
if translation_dict_path then
translation_dict = load_translation_dictionary(translation_dict_path)
end
local normalized_extensions = {}
for _, ext in ipairs(extensions) do
if string.sub(ext, 1, 1) ~= "." then
@@ -14,135 +14,137 @@ function scan_directory_for_cyrillic(directory_path, extensions)
normalized_extensions[string.lower(ext)] = true
end
-- Рекурсивно сканируем директорию
scan_directory_recursive(directory_path, normalized_extensions, results)
local files = get_all_files(directory_path)
return results
end
-- Рекурсивное сканирование директории
function scan_directory_recursive(path, extensions, results)
local attr = lfs.attributes(path)
if not attr then
print("Ошибка: не удается получить доступ к " .. path)
return
end
if attr.mode == "directory" then
-- Сканируем содержимое директории
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local file_path = path .. "/" .. file
scan_directory_recursive(file_path, extensions, results)
end
end
elseif attr.mode == "file" then
-- Проверяем расширение файла
local file_ext = string.lower(get_file_extension(path))
if extensions[file_ext] then
-- Сканируем файл на кириллицу
local cyrillic_found = scan_file_for_cyrillic(path)
if #cyrillic_found > 0 then
table.insert(results, {
file = path,
cyrillic_strings = cyrillic_found
})
for _, file_path in ipairs(files) do
local file_ext = string.lower(get_file_extension(file_path))
if normalized_extensions[file_ext] then
local cyrillic_lines = scan_file_for_cyrillic_with_dict(file_path, false, translation_dict)
for i, line in ipairs(cyrillic_lines) do
local key = file_path .. ":" .. i
results[key] = line
end
end
end
end
-- Получение расширения файла
function get_file_extension(filename)
local ext = filename:match("^.+(%..+)$")
return ext or ""
end
-- Сканирование файла на наличие кириллицы
function scan_file_for_cyrillic(file_path)
local cyrillic_strings = {}
local file = io.open(file_path, "r")
if not file then
print("Ошибка: не удается открыть файл " .. file_path)
return cyrillic_strings
end
local seen_values = {}
local deduplicated = {}
local line_number = 0
for line in file:lines() do
line_number = line_number + 1
if has_cyrillic(line) then
table.insert(cyrillic_strings, {
line_number = line_number,
content = line
})
for key, value in pairs(results) do
if not seen_values[value] then
seen_values[value] = true
deduplicated[key] = value
end
end
file:close()
return cyrillic_strings
return deduplicated
end
-- Проверка наличия кириллицы в строке
function has_cyrillic(text)
local cyrillic_pattern = "[а-яё]"
return string.find(string.lower(text), cyrillic_pattern) ~= nil
end
-- Функция для красивого вывода результатов
function print_scan_results(results)
if #results == 0 then
print("Кириллица не найдена в файлах с указанными расширениями.")
return
end
print("Найдено файлов с кириллицей: " .. #results)
print(string.rep("=", 50))
for _, result in ipairs(results) do
print("Файл: " .. result.file)
print("Строк с кириллицей: " .. #result.cyrillic_strings)
-- Показываем первые 3 строки с кириллицей
local max_lines = math.min(3, #result.cyrillic_strings)
for i = 1, max_lines do
local line_info = result.cyrillic_strings[i]
print(" Строка " .. line_info.line_number .. ": " .. string.sub(line_info.content, 1, 100))
end
if #result.cyrillic_strings > 3 then
print(" ... и еще " .. (#result.cyrillic_strings - 3) .. " строк")
end
print(string.rep("-", 30))
end
end
-- Функция для получения только списка файлов с кириллицей
function get_files_with_cyrillic(directory_path, extensions)
local results = scan_directory_for_cyrillic(directory_path, extensions)
function get_all_files(directory_path)
local files = {}
local command
for _, result in ipairs(results) do
table.insert(files, result.file)
if package.config:sub(1,1) == '\\' then
-- Windows
command = 'dir "' .. directory_path .. '" /s /b /a-d'
else
-- Unix/Linux
command = 'find "' .. directory_path .. '" -type f'
end
local handle = io.popen(command)
if handle then
for line in handle:lines() do
table.insert(files, line)
end
handle:close()
end
return files
end
-- Функция для подсчета общего количества строк с кириллицей
function count_cyrillic_lines(directory_path, extensions)
local results = scan_directory_for_cyrillic(directory_path, extensions)
local total_files = #results
local total_lines = 0
for _, result in ipairs(results) do
total_lines = total_lines + #result.cyrillic_strings
function get_file_extension(filename)
local ext = filename:match("^.+(%..+)$")
return ext or ""
end
function load_translation_dictionary(json_path)
local file = io.open(json_path, "r")
if not file then
return {}
end
return {
files_count = total_files,
lines_count = total_lines
}
end
local content = file:read("*all")
file:close()
local dict = {}
for key, value in string.gmatch(content, '"([^"]+)"%s*:%s*"([^"]+)"') do
dict[key] = value
end
return dict
end
function table_length(t)
local count = 0
for _ in pairs(t) do count = count + 1 end
return count
end
function has_untranslated_cyrillic(line, translation_dict)
local cleaned_line = line
for key, value in pairs(translation_dict) do
if has_cyrillic(key) then
cleaned_line = string.gsub(cleaned_line, key, "")
end
if has_cyrillic(value) then
cleaned_line = string.gsub(cleaned_line, value, "")
end
end
return has_cyrillic(cleaned_line)
end
function scan_file_for_cyrillic_with_dict(file_path, show_progress, translation_dict)
local cyrillic_lines = {}
local file = io.open(file_path, "r")
if not file then
return cyrillic_lines
end
for line in file:lines() do
if has_cyrillic(line) then
if table_length(translation_dict) == 0 or has_untranslated_cyrillic(line, translation_dict) then
table.insert(cyrillic_lines, line)
end
end
end
file:close()
return cyrillic_lines
end
function scan_file_for_cyrillic(file_path, show_progress)
return scan_file_for_cyrillic_with_dict(file_path, show_progress, {})
end
function has_cyrillic(text)
for i = 1, string.len(text) do
local byte = string.byte(text, i)
if byte >= 208 and byte <= 209 then
local next_byte = string.byte(text, i + 1)
if next_byte then
local unicode = (byte - 208) * 64 + (next_byte - 128)
if (unicode >= 16 and unicode <= 47) or -- А-Я
(unicode >= 48 and unicode <= 79) or -- а-я
unicode == 81 or unicode == 113 then -- Ё, ё
return true
end
end
end
end
return false
end
Binary file not shown.
@@ -19,10 +19,13 @@
КаталогОригинала = Новый Файл(ПутьОригинала);
КаталогОригинала = КаталогОригинала.ПолноеИмя;
Для Каждого Язык Из Языки Цикл
СловарьИсключений = КаталогСловарей + Язык + "_post.json";
ПеревестиПоСловарю(КаталогСловарей, Язык, ФайлыПеревода, Корень);
ПроверитьПеревод(Корень + Язык);
ПроверитьПеревод(Корень + Язык, СловарьИсключений);
КонецЦикла;
@@ -254,7 +257,7 @@
КонецПроцедуры
Процедура ПроверитьПеревод(Знач Путь)
Процедура ПроверитьПеревод(Знач Путь, Знач СловарьИсключений)
МассивРасширений = Новый Массив;
МассивРасширений.Добавить("os");
@@ -265,14 +268,16 @@
МассивАргументов = Новый Массив;
МассивАргументов.Добавить(Путь);
МассивАргументов.Добавить(МассивРасширений);
МассивАргументов.Добавить(СловарьИсключений);
Результат = Lua.ВызватьФункцию("scan_directory_for_cyrillic", МассивАргументов);
Для Каждого ОшибкаПеревода Из Результат Цикл
Сообщить(СтрШаблон(" Ошибка перевода!
Сообщить(СтрШаблон("
| Ошибка перевода!
| Файл: %1
| Строка: %2
|", ОшибкаПеревода["file"], ОшибкаПеревода["cyrillic_strings"]));
|", ОшибкаПеревода.Ключ, ОшибкаПеревода.Значение));
КонецЦикла;
Если Результат.Количество() > 0 Тогда
+5795 -5792
View File
File diff suppressed because it is too large Load Diff
+7 -1
View File
@@ -28,5 +28,11 @@
"Base-Project: OpenIntegrations":"Base-Project: OpenIntegrationsENG",
"(\"https://example.com/path\")": "(\"https://example.com/путь\")",
"\"cyrillic\"":"\"кириллица\"",
"=cyrillic":"=кириллица"
"=cyrillic":"=кириллица",
"!ForLuaCheck1": "ЭтотОбъект",
"!ForLuaCheck2": "кириллица",
"!ForLuaCheck3": "путь",
"!ForLuaCheck4": "Ожидаем",
"!ForLuaCheck5": "Ожидаем.Что"
}
-114
View File
@@ -1,114 +0,0 @@
#!/usr/bin/env python3
"""
Пример простого gRPC сервера для тестирования DLL.
Требует: pip install grpcio grpcio-tools
"""
import grpc
from concurrent import futures
import time
# Генерируем код из proto (в реальном проекте это делается заранее)
import subprocess
import os
# Создаем proto файл
proto_content = '''
syntax = "proto3";
package example;
service ExampleService {
rpc SayHello (HelloRequest) returns (HelloResponse);
rpc GetUser (GetUserRequest) returns (User);
}
message HelloRequest {
string name = 1;
}
message HelloResponse {
string message = 1;
}
message GetUserRequest {
int32 user_id = 1;
}
message User {
int32 id = 1;
string name = 2;
string email = 3;
bool active = 4;
}
'''
# Сохраняем proto файл
with open('example.proto', 'w') as f:
f.write(proto_content)
# Генерируем Python код
subprocess.run([
'python', '-m', 'grpc_tools.protoc',
'--python_out=.',
'--grpc_python_out=.',
'example.proto'
])
# Импортируем сгенерированные модули
import example_pb2
import example_pb2_grpc
class ExampleServiceServicer(example_pb2_grpc.ExampleServiceServicer):
def SayHello(self, request, context):
return example_pb2.HelloResponse(
message=f"Привет, {request.name}! Ответ от gRPC сервера."
)
def GetUser(self, request, context):
# Имитируем базу данных пользователей
users = {
1: {"name": "Иван Иванов", "email": "ivan@example.com", "active": True},
2: {"name": "Петр Петров", "email": "petr@example.com", "active": False},
3: {"name": "Анна Сидорова", "email": "anna@example.com", "active": True},
}
user_data = users.get(request.user_id)
if user_data:
return example_pb2.User(
id=request.user_id,
name=user_data["name"],
email=user_data["email"],
active=user_data["active"]
)
else:
context.set_code(grpc.StatusCode.NOT_FOUND)
context.set_details(f'Пользователь с ID {request.user_id} не найден')
return example_pb2.User()
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
example_pb2_grpc.add_ExampleServiceServicer_to_server(
ExampleServiceServicer(), server
)
listen_addr = '[::]:50051'
server.add_insecure_port(listen_addr)
print(f"Запуск gRPC сервера на {listen_addr}")
print("Для тестирования используйте:")
print("1. Загрузите proto схему в DLL")
print("2. Подключитесь к http://localhost:50051")
print("3. Вызовите методы SayHello или GetUser")
server.start()
try:
while True:
time.sleep(86400) # Ждем день
except KeyboardInterrupt:
print("Остановка сервера...")
server.stop(0)
if __name__ == '__main__':
serve()