language-data/setup.py

55 lines
1.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2023-01-13 09:57:01 +01:00
2023-01-10 09:51:06 +01:00
# Copyright © Michal Čihař <michal@weblate.org>
#
2023-01-13 09:57:01 +01:00
# SPDX-License-Identifier: MIT
2020-09-29 11:30:09 +02:00
import os
from distutils.command.build import build
from distutils.core import Command
from distutils.dep_util import newer
2020-09-29 11:30:09 +02:00
from glob import glob
from itertools import chain
from setuptools import setup
2020-09-29 11:30:09 +02:00
from translate.tools.pocompile import convertmo
LOCALE_MASKS = [
"weblate_language_data/locale/*/LC_MESSAGES/*.po",
]
2020-09-29 11:30:09 +02:00
class BuildMo(Command):
description = "update MO files to match PO"
user_options = []
2025-02-05 14:40:41 +01:00
def initialize_options(self) -> None:
2020-09-29 11:30:09 +02:00
self.build_base = None
2025-02-05 14:40:41 +01:00
def finalize_options(self) -> None:
2020-09-29 11:30:09 +02:00
self.set_undefined_options("build", ("build_base", "build_base"))
2025-02-05 14:40:41 +01:00
def run(self) -> None:
2020-09-29 11:30:09 +02:00
for name in chain.from_iterable(glob(mask) for mask in LOCALE_MASKS):
output = os.path.splitext(name)[0] + ".mo"
if not newer(name, output):
2020-09-29 11:30:09 +02:00
continue
print(f"compiling {name} -> {output}")
with open(name, "rb") as pofile, open(output, "wb") as mofile:
2020-09-29 11:30:09 +02:00
convertmo(pofile, mofile, None)
class WeblateBuild(build):
"""Override the default build with new subcommands."""
# The build_mo has to be before build_data
2025-02-05 14:40:41 +01:00
sub_commands = [
("build_mo", lambda self: True), # noqa: ARG005
*build.sub_commands,
]
2020-09-29 11:30:09 +02:00
setup(
cmdclass={"build_mo": BuildMo, "build": WeblateBuild},
)