2020-09-29 10:49:38 +02:00
|
|
|
#!/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>
|
2020-09-29 10:49:38 +02:00
|
|
|
#
|
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
|
2024-12-16 09:33:18 +01:00
|
|
|
from distutils.dep_util import newer
|
2020-09-29 11:30:09 +02:00
|
|
|
from glob import glob
|
|
|
|
from itertools import chain
|
2020-09-29 10:49:38 +02:00
|
|
|
|
|
|
|
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 10:49:38 +02:00
|
|
|
|
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"
|
2024-12-16 09:33:18 +01:00
|
|
|
if not newer(name, output):
|
2020-09-29 11:30:09 +02:00
|
|
|
continue
|
|
|
|
print(f"compiling {name} -> {output}")
|
2020-10-01 11:07:19 +02:00
|
|
|
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},
|
|
|
|
)
|