-
Notifications
You must be signed in to change notification settings - Fork 618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix locale scripts #2648
Merged
Merged
Fix locale scripts #2648
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a4f8d77
Fix locale scripts
Evgencheg 51e4b1b
Update Tools/ss14_ru/clean_duplicates.py
Evgencheg c99f33b
Update translation.sh
Evgencheg b1f5561
Update translation.bat
Evgencheg 34bb2f0
Update requirements.txt
Evgencheg cb7e982
Fix CRLF requirements.txt
Morb0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from fluentformatter import FluentFile, FluentFormatter | ||
from fluentformatter import FluentFile, FluentFormatter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import os | ||
import re | ||
import chardet | ||
from datetime import datetime | ||
|
||
def find_top_level_dir(start_dir): | ||
marker_file = 'SpaceStation14.sln' | ||
current_dir = start_dir | ||
while True: | ||
if marker_file in os.listdir(current_dir): | ||
return current_dir | ||
parent_dir = os.path.dirname(current_dir) | ||
if parent_dir == current_dir: | ||
print(f"Не удалось найти {marker_file} начиная с {start_dir}") | ||
exit(-1) | ||
current_dir = parent_dir | ||
|
||
def find_ftl_files(root_dir): | ||
ftl_files = [] | ||
for root, dirs, files in os.walk(root_dir): | ||
for file in files: | ||
if file.endswith('.ftl'): | ||
ftl_files.append(os.path.join(root, file)) | ||
return ftl_files | ||
|
||
def detect_encoding(file_path): | ||
with open(file_path, 'rb') as file: | ||
raw_data = file.read() | ||
return chardet.detect(raw_data)['encoding'] | ||
|
||
def parse_ent_blocks(file_path): | ||
try: | ||
encoding = detect_encoding(file_path) | ||
with open(file_path, 'r', encoding=encoding) as file: | ||
content = file.read() | ||
except UnicodeDecodeError: | ||
print(f"Ошибка при чтении файла {file_path}. Попытка чтения в UTF-8.") | ||
try: | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
content = file.read() | ||
except UnicodeDecodeError: | ||
print(f"Не удалось прочитать файл {file_path}. Пропускаем.") | ||
return {} | ||
|
||
ent_blocks = {} | ||
current_ent = None | ||
current_block = [] | ||
|
||
for line in content.split('\n'): | ||
if line.startswith('ent-'): | ||
if current_ent: | ||
ent_blocks[current_ent] = '\n'.join(current_block) | ||
current_ent = line.split('=')[0].strip() | ||
current_block = [line] | ||
elif current_ent and (line.strip().startswith('.desc') or line.strip().startswith('.suffix')): | ||
current_block.append(line) | ||
elif line.strip() == '': | ||
if current_ent: | ||
ent_blocks[current_ent] = '\n'.join(current_block) | ||
current_ent = None | ||
current_block = [] | ||
else: | ||
if current_ent: | ||
ent_blocks[current_ent] = '\n'.join(current_block) | ||
current_ent = None | ||
current_block = [] | ||
|
||
if current_ent: | ||
ent_blocks[current_ent] = '\n'.join(current_block) | ||
|
||
return ent_blocks | ||
|
||
def remove_duplicates(root_dir): | ||
ftl_files = find_ftl_files(root_dir) | ||
all_ents = {} | ||
removed_duplicates = [] | ||
|
||
for file_path in ftl_files: | ||
ent_blocks = parse_ent_blocks(file_path) | ||
for ent, block in ent_blocks.items(): | ||
if ent not in all_ents: | ||
all_ents[ent] = (file_path, block) | ||
|
||
for file_path in ftl_files: | ||
try: | ||
encoding = detect_encoding(file_path) | ||
with open(file_path, 'r', encoding=encoding) as file: | ||
content = file.read() | ||
|
||
ent_blocks = parse_ent_blocks(file_path) | ||
for ent, block in ent_blocks.items(): | ||
if all_ents[ent][0] != file_path: | ||
content = content.replace(block, '') | ||
removed_duplicates.append((ent, file_path, block)) | ||
|
||
content = re.sub(r'\n{3,}', '\n\n', content) | ||
|
||
with open(file_path, 'w', encoding=encoding) as file: | ||
file.write(content) | ||
except Exception as e: | ||
print(f"Ошибка при обработке файла {file_path}: {str(e)}") | ||
|
||
# Сохранение лога удаленных дубликатов | ||
log_filename = f"removed_duplicates_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log" | ||
with open(log_filename, 'w', encoding='utf-8') as log_file: | ||
for ent, file_path, block in removed_duplicates: | ||
log_file.write(f"Удален дубликат: {ent}\n") | ||
log_file.write(f"Файл: {file_path}\n") | ||
log_file.write("Содержимое:\n") | ||
log_file.write(block) | ||
log_file.write("\n\n") | ||
|
||
print(f"Обработка завершена. Проверено файлов: {len(ftl_files)}") | ||
print(f"Лог удаленных дубликатов сохранен в файл: {log_filename}") | ||
|
||
if __name__ == "__main__": | ||
script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
main_folder = find_top_level_dir(script_dir) | ||
root_dir = os.path.join(main_folder, "Resources\\Locale\\ru-RU") | ||
remove_duplicates(root_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import os | ||
import logging | ||
from datetime import datetime | ||
|
||
def find_top_level_dir(start_dir): | ||
marker_file = 'SpaceStation14.sln' | ||
current_dir = start_dir | ||
while True: | ||
if marker_file in os.listdir(current_dir): | ||
return current_dir | ||
parent_dir = os.path.dirname(current_dir) | ||
if parent_dir == current_dir: | ||
print(f"Не удалось найти {marker_file} начиная с {start_dir}") | ||
exit(-1) | ||
current_dir = parent_dir | ||
def setup_logging(): | ||
log_filename = f"cleanup_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log" | ||
logging.basicConfig(filename=log_filename, level=logging.INFO, | ||
format='%(asctime)s - %(levelname)s - %(message)s') | ||
console = logging.StreamHandler() | ||
console.setLevel(logging.INFO) | ||
logging.getLogger('').addHandler(console) | ||
return log_filename | ||
|
||
def remove_empty_files_and_folders(path): | ||
removed_files = 0 | ||
removed_folders = 0 | ||
|
||
for root, dirs, files in os.walk(path, topdown=False): | ||
# Удаление пустых файлов | ||
for file in files: | ||
file_path = os.path.join(root, file) | ||
if os.path.getsize(file_path) == 0: | ||
try: | ||
os.remove(file_path) | ||
logging.info(f"Удален пустой файл: {file_path}") | ||
removed_files += 1 | ||
except Exception as e: | ||
logging.error(f"Ошибка при удалении файла {file_path}: {str(e)}") | ||
|
||
# Удаление пустых папок | ||
if not os.listdir(root): | ||
try: | ||
os.rmdir(root) | ||
logging.info(f"Удалена пустая папка: {root}") | ||
removed_folders += 1 | ||
except Exception as e: | ||
logging.error(f"Ошибка при удалении папки {root}: {str(e)}") | ||
|
||
return removed_files, removed_folders | ||
|
||
if __name__ == "__main__": | ||
script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
main_folder = find_top_level_dir(script_dir) | ||
root_dir = os.path.join(main_folder, "Resources\\Locale") | ||
log_file = setup_logging() | ||
|
||
logging.info(f"Начало очистки в директории: {root_dir}") | ||
files_removed, folders_removed = remove_empty_files_and_folders(root_dir) | ||
logging.info(f"Очистка завершена. Удалено файлов: {files_removed}, удалено папок: {folders_removed}") | ||
print(f"Лог операций сохранен в файл: {log_file}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from fluent.syntax import ast | ||
from fluent.syntax import ast | ||
from fluentast import FluentAstAbstract | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import typing | ||
import typing | ||
import logging | ||
|
||
from pydash import py_ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import lokalise | ||
import lokalise | ||
import typing | ||
from lokalisemodels import LokaliseKey | ||
from pydash import py_ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import typing | ||
import typing | ||
import os | ||
from pydash import py_ | ||
from project import Project | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import pathlib | ||
import pathlib | ||
import os | ||
import glob | ||
from file import FluentFile | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@echo off | ||
|
||
call pip install -r requirements.txt | ||
call python ./yamlextractor.py | ||
call python ./keyfinder.py | ||
call python ./clean_duplicates.py | ||
call python ./clean_empty.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env sh | ||
|
||
# make sure to start from script dir | ||
if [ "$(dirname $0)" != "." ]; then | ||
cd "$(dirname $0)" | ||
fi | ||
|
||
pip install -r requirements.txt | ||
python3 ./yamlextractor.py | ||
python3 ./keyfinder.py | ||
python3 ./clean_duplicates.py | ||
python3 ./clean_empty.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import logging | ||
import logging | ||
import typing | ||
|
||
from fluent.syntax import FluentParser, FluentSerializer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
пояснение - это говно срёт ВСЕГДА независимо было ли добавлено или нет.