• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / z3c.recipe.i18n / 10028167343

18 Jul 2024 06:36AM UTC coverage: 20.177% (-0.07%) from 20.246%
10028167343

push

github

web-flow
- Add support for Python 3.12.  - Drop support for Python 3.7. (#11)

27 of 187 branches covered (14.44%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

87 of 378 relevant lines covered (23.02%)

0.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/z3c/recipe/i18n/i18nmergeall.py
1
#!/usr/bin/env python
2
##############################################################################
3
#
4
# Copyright (c) 2008 Zope Foundation and Contributors.
5
# All Rights Reserved.
6
#
7
# This software is subject to the provisions of the Zope Public License,
8
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
9
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
10
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
11
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
12
# FOR A PARTICULAR PURPOSE.
13
#
14
##############################################################################
15

16

17
"""Merge a POT file with all languages
18

19
This utility requires the GNU gettext package to be installed. The command
20
'msgmerge' will be executed for each language.
21

22
Usage: i18nmergeall.py [options]
23
Options:
24

25
    -h / --help
26
        Print this message and exit.
27

28
    -l / --locales-dir
29
        Specify the 'locales' directory for which to generate the statistics.
30

31
"""
32
import getopt
×
33
import os
×
34
import shutil
×
35
import subprocess
×
36
import sys
×
37

38

39
def usage(code, msg=""):
×
40
    """Display help."""
41
    print("\n".join(__doc__.split("\n")[:-2]), file=sys.stderr)
×
42
    if msg:
×
43
        print("** Error: " + str(msg) + " **", file=sys.stderr)
×
44
    sys.exit(code)
×
45

46

47
def merge(path):
×
48
    for pot_name in os.listdir(path):
×
49
        if pot_name.endswith(".pot"):
×
50
            break
×
51
    domain = pot_name[:-4]
×
52
    potPath = os.path.join(path, domain + ".pot")
×
53

54
    failed = []
×
55
    for language in sorted(os.listdir(path)):
×
56
        lc_messages_path = os.path.join(path, language, "LC_MESSAGES")
×
57

58
        # Make sure we got a language directory
59
        if not os.path.isdir(lc_messages_path):
×
60
            continue
×
61

62
        poPath = os.path.join(lc_messages_path, domain + ".po")
×
63
        if not os.path.exists(poPath):
×
64
            shutil.copyfile(potPath, poPath)
×
65

NEW
66
        print(f'Merging language "{language}", domain "{domain}"')
×
67
        rc = subprocess.call(["msgmerge", "-U", poPath, potPath])
×
68
        if rc != 0:
×
69
            failed.append(language)
×
70

71
    if failed:
×
72
        sys.exit("msgmerge failed for %s" % ", ".join(failed))
×
73

74

75
def main(argv=sys.argv):
×
76
    try:
×
77
        opts, args = getopt.getopt(argv[1:], "l:h", ["help", "locals-dir="])
×
78
    except getopt.error as msg:
×
79
        usage(1, msg)
×
80

81
    path = None
×
82
    for opt, arg in opts:
×
83
        if opt in ("-h", "--help"):
×
84
            usage(0)
×
85
        elif opt in ("-l", "--locales-dir"):
×
86
            cwd = os.getcwd()
×
87
            # This is for symlinks. Thanks to Fred for this trick.
88
            if "PWD" in os.environ:
×
89
                cwd = os.environ["PWD"]
×
90
            path = os.path.normpath(os.path.join(cwd, arg))
×
91

92
    if path is None:
×
93
        usage(1, "You must specify the path to the locales directory.")
×
94
    merge(path)
×
95

96

97
if __name__ == "__main__":
×
98
    main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc