mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-02-15 04:30:57 +01:00
Co-authored-by: mhamster <81412348+mhamsterr@users.noreply.github.com> Co-authored-by: Morb0 <14136326+Morb0@users.noreply.github.com>
38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
|
|
# Форматтер, приводящий fluent-файлы (.ftl) в соответствие стайлгайду
|
|
# path - путь к папке, содержащий форматируемые файлы. Для форматирования всего проекта, необходимо заменить значение на root_dir_path
|
|
import typing
|
|
|
|
from file import FluentFile
|
|
from project import Project
|
|
from fluent.syntax import ast, FluentParser, FluentSerializer
|
|
|
|
|
|
######################################### Class defifitions ############################################################
|
|
|
|
class FluentFormatter:
|
|
@classmethod
|
|
def format(cls, fluent_files: typing.List[FluentFile]):
|
|
for file in fluent_files:
|
|
file_data = file.read_data()
|
|
parsed_file_data = file.parse_data(file_data)
|
|
serialized_file_data = file.serialize_data(parsed_file_data)
|
|
file.save_data(serialized_file_data)
|
|
|
|
@classmethod
|
|
def format_serialized_file_data(cls, file_data: typing.AnyStr):
|
|
parsed_data = FluentParser().parse(file_data)
|
|
|
|
return FluentSerializer(with_junk=True).serialize(parsed_data)
|
|
|
|
|
|
|
|
######################################## Var definitions ###############################################################
|
|
project = Project()
|
|
fluent_files = project.get_fluent_files_by_dir(project.ru_locale_dir_path)
|
|
|
|
########################################################################################################################
|
|
|
|
FluentFormatter.format(fluent_files)
|