<commit_before>import os
import sys
from subprocess import Popen
from tempfile import TemporaryFile

from django.core.management.base import BaseCommand

from manage import settings

try:
    domains = [settings.TEXT_DOMAIN] + settings.STANDALONE_DOMAINS
except AttributeError:
    domains = [settings.TEXT_DOMAIN, 'javascript']

class Command(BaseCommand):
    help = """
    This will update all locales' PO files by merging them with the POT files.

    The command looks for POT files in locale/templates/LC_MESSAGES, which is
    where software like Verbatim looks for them as well. Tower's `verbatimize`
    command can be used prior to running `merge` to copy the POT files to
    `locale/templates/LC_MESSAGES` if they were extracted to a different place.
    
    For a given POT file, if a corresponding PO file doesn't exist for a 
    locale, the command will initialize it with `msginit`. This guarantees 
    that the newly created PO file has proper gettext metadata headers.

    During merging (or initializing), the command will also look in 
    `locale/compendia` for a locale-specific compendium of translations
    (serving as a translation memory of sorts). The compendium file must
    be called `${locale}.compendium`, e.g. `es-ES.compendium` for Spanish.
    The translations in the compendium will be used by gettext for fuzzy 
    matching. 
    
    """

    def handle(self, *args, **options):

        locale_dir = os.path.join(settings.ROOT, 'locale')

        for domain in domains:

            print "Merging %s strings to each locale..." % domain
            domain_pot = os.path.join(locale_dir, 'templates', 'LC_MESSAGES',
                                      '%s.pot' % domain)
            if not os.path.isfile(domain_pot):
                sys.exit("Can't find %s.pot" % domain)

            for locale in os.listdir(locale_dir):
                if (not os.path.isdir(os.path.join(locale_dir, locale)) or
                    locale.startswith('.') or 
                    locale == 'templates' or
                    locale == 'compendia'):
                            continue

                compendium = os.path.join(locale_dir, 'compendia', 
                                          '%s.compendium' % locale)
                domain_po = os.path.join(locale_dir, locale, 'LC_MESSAGES',
                                         '%s.po' % domain)

                if not os.path.isfile(domain_po):
                    print " Can't find (%s).  Creating..." % (domain_po)<commit_msg>Compendia files need to be using the gettext-style locale codes in their names<commit_after>import os
import sys
from subprocess import Popen
from tempfile import TemporaryFile

from django.core.management.base import BaseCommand

from manage import settings

try:
    domains = [settings.TEXT_DOMAIN] + settings.STANDALONE_DOMAINS
except AttributeError:
    domains = [settings.TEXT_DOMAIN, 'javascript']

class Command(BaseCommand):
    help = """
    This will update all locales' PO files by merging them with the POT files.

    The command looks for POT files in locale/templates/LC_MESSAGES, which is
    where software like Verbatim looks for them as well. Tower's `verbatimize`
    command can be used prior to running `merge` to copy the POT files to
    `locale/templates/LC_MESSAGES` if they were extracted to a different place.
    
    For a given POT file, if a corresponding PO file doesn't exist for a 
    locale, the command will initialize it with `msginit`. This guarantees 
    that the newly created PO file has proper gettext metadata headers.

    During merging (or initializing), the command will also look in 
    `locale/compendia` for a locale-specific compendium of translations
    (serving as a translation memory of sorts). The compendium file must
    be called `${locale}.compendium`, e.g. `es_ES.compendium` for Spanish.
    The translations in the compendium will be used by gettext for fuzzy 
    matching. 
    
    """

    def handle(self, *args, **options):

        locale_dir = os.path.join(settings.ROOT, 'locale')

        for domain in domains:

            print "Merging %s strings to each locale..." % domain
            domain_pot = os.path.join(locale_dir, 'templates', 'LC_MESSAGES',
                                      '%s.pot' % domain)
            if not os.path.isfile(domain_pot):
                sys.exit("Can't find %s.pot" % domain)

            for locale in os.listdir(locale_dir):
                if (not os.path.isdir(os.path.join(locale_dir, locale)) or
                    locale.startswith('.') or 
                    locale == 'templates' or
                    locale == 'compendia'):
                            continue

                compendium = os.path.join(locale_dir, 'compendia', 
                                          '%s.compendium' % locale)
                domain_po = os.path.join(locale_dir, locale, 'LC_MESSAGES',
                                         '%s.po' % domain)

                if not os.path.isfile(domain_po):
                    print " Can't find (%s).  Creating..." % (domain_po)
{'fraction_non_alphanumeric': 0.08286105139730311, 'fraction_numerical': 0.0, 'mean_word_length': 2.1848164281269447, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5305979', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1332, 'n_words': 495}