2020-09-29 10:49:38 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# Copyright © 2012 - 2020 Michal Čihař <michal@cihar.com>
|
|
|
|
#
|
2020-09-29 11:30:09 +02:00
|
|
|
# This file is part of Weblate Client <https://github.com/WeblateOrg/language-data>
|
2020-09-29 10:49:38 +02:00
|
|
|
#
|
2020-09-29 12:59:03 +02:00
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
2020-09-29 10:49:38 +02:00
|
|
|
#
|
2020-09-29 12:59:03 +02:00
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
2020-09-29 10:49:38 +02:00
|
|
|
#
|
2020-09-29 12:59:03 +02:00
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
2020-09-29 10:49:38 +02:00
|
|
|
#
|
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
|
|
|
|
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 = []
|
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
self.build_base = None
|
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
self.set_undefined_options("build", ("build_base", "build_base"))
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
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):
|
|
|
|
continue
|
|
|
|
print(f"compiling {name} -> {output}")
|
|
|
|
with open(name) as pofile, open(output, "wb") as mofile:
|
|
|
|
convertmo(pofile, mofile, None)
|
|
|
|
|
|
|
|
|
|
|
|
class WeblateBuild(build):
|
|
|
|
"""Override the default build with new subcommands."""
|
|
|
|
|
|
|
|
# The build_mo has to be before build_data
|
|
|
|
sub_commands = [("build_mo", lambda self: True)] + build.sub_commands
|
|
|
|
|
|
|
|
|
|
|
|
setup(
|
|
|
|
cmdclass={"build_mo": BuildMo, "build": WeblateBuild},
|
|
|
|
)
|