Files
crystall-punk-14/Tools/_CP14/LocalizationHelper/ftl_parser/ftl_parser.py
comasqw fa86f705aa Localization Helper (#275)
* Localization Helper

* Update main.py

* Update main.py

* adding comments to code and translating exceptions into English

* cringe fix

* Update yml_parser.py

* tweak

* Update main.py
2024-06-25 18:02:02 +03:00

24 lines
642 B
Python

from fluent import ftl_reader
import os
def ftl_parser(path: str) -> dict:
"""
The function gets the path, then with the help of the os library
goes through each file,checks that the file extension is "ftl",
then reads it through the "ftl_reader" module of the "fluent" package.
"""
prototypes = {}
for dirpath, _, filenames in os.walk(path):
for filename in filenames:
path = f"{dirpath}\\{filename}"
if not filename.endswith(".ftl"):
continue
file = ftl_reader.read_ftl(path)
prototypes.update(file)
return prototypes