コード例 #1
0
 def test_main(self):
     """
     Runs generate.main() which should merge source files,
     then compile all sources in all configured languages.
     Validates output by checking all .mo files in all configured languages.
     .mo files should exist, and be recently created (modified
     after start of test suite)
     """
     generate.main(verbose=0, strict=False)
     for locale in CONFIGURATION.translated_locales:
         for (filename, num_headers) in zip(('django', 'djangojs'), (6, 4)):
             mofile = filename + '.mo'
             file_path = os.path.join(
                 CONFIGURATION.get_messages_dir(locale), mofile)
             exists = os.path.exists(file_path)
             self.assertTrue(exists,
                             msg='Missing file in locale %s: %s' %
                             (locale, mofile))
             self.assertTrue(datetime.fromtimestamp(
                 os.path.getmtime(file_path), UTC) >= self.start_time,
                             msg='File not recently modified: %s' %
                             file_path)
         # Assert merge headers look right
         file_path = os.path.join(CONFIGURATION.get_messages_dir(locale),
                                  filename + '.po')
         self.assert_merge_headers(file_path, num_headers)
コード例 #2
0
ファイル: transifex.py プロジェクト: WEForum/edx-platform
def clean_locale(locale):
    """
    Strips out the warning from all of a locale's translated po files
    about being an English source file.
    Iterates over machine-generated files.
    """
    dirname = CONFIGURATION.get_messages_dir(locale)
    for filename in ('django-partial.po', 'djangojs-partial.po', 'mako.po'):
        clean_file(dirname.joinpath(filename))
コード例 #3
0
def clean_locale(locale):
    """
    Strips out the warning from all of a locale's translated po files
    about being an English source file.
    Iterates over machine-generated files.
    """
    dirname = CONFIGURATION.get_messages_dir(locale)
    for filename in ('django-partial.po', 'djangojs-partial.po', 'mako.po'):
        clean_file(dirname.joinpath(filename))
コード例 #4
0
def clean_conf_folder(locale):
    """Remove the configuration directory for `locale`"""
    dirname = CONFIGURATION.get_messages_dir(locale)
    command = "rm -rf {}".format(dirname)
    print(command)
    try:
        execute(command)
    except Exception as exc:
        print("Encountered error {}; continuing...".format(exc))
        return
コード例 #5
0
ファイル: segment.py プロジェクト: ybergner/edx-platform
def segment_pofiles(locale):
    """Segment all the pofiles for `locale`.

    Returns a set of filenames, all the segment files written.

    """
    files_written = set()
    for filename, segments in CONFIGURATION.segment.items():
        filename = CONFIGURATION.get_messages_dir(locale) / filename
        files_written.update(segment_pofile(filename, segments))
    return files_written
コード例 #6
0
ファイル: test_generate.py プロジェクト: baxeico/i18n-tools
 def test_main(self):
     """
     Runs generate.main() which should merge source files,
     then compile all sources in all configured languages.
     Validates output by checking all .mo files in all configured languages.
     .mo files should exist, and be recently created (modified
     after start of test suite)
     """
     generate.main(verbose=0, strict=False)
     for locale in CONFIGURATION.translated_locales:
         for (filename, num_headers) in zip(('django', 'djangojs'), (6, 4)):
             mofile = filename + '.mo'
             file_path = os.path.join(CONFIGURATION.get_messages_dir(locale), mofile)
             exists = os.path.exists(file_path)
             self.assertTrue(exists, msg='Missing file in locale %s: %s' % (locale, mofile))
             self.assertTrue(
                 datetime.fromtimestamp(os.path.getmtime(file_path), UTC) >= self.start_time,
                 msg='File not recently modified: %s' % file_path
             )
         # Assert merge headers look right
         file_path = os.path.join(CONFIGURATION.get_messages_dir(locale), filename + '.po')
         self.assert_merge_headers(file_path, num_headers)
コード例 #7
0
 def test_main(self):
     """
     Runs generate.main() which should merge source files,
     then compile all sources in all configured languages.
     Validates output by checking all .mo files in all configured languages.
     .mo files should exist, and be recently created (modified
     after start of test suite)
     """
     generate.main()
     for locale in CONFIGURATION.translated_locales:
         for filename in ('django', 'djangojs'):
             mofile = filename+'.mo'
             path = os.path.join(CONFIGURATION.get_messages_dir(locale), mofile)
             exists = os.path.exists(path)
             self.assertTrue(exists, msg='Missing file in locale %s: %s' % (locale, mofile))
             self.assertTrue(datetime.fromtimestamp(os.path.getmtime(path), UTC) >= self.start_time,
                             msg='File not recently modified: %s' % path)
コード例 #8
0
 def test_main(self):
     """
     Runs generate.main() which should merge source files,
     then compile all sources in all configured languages.
     Validates output by checking all .mo files in all configured languages.
     .mo files should exist, and be recently created (modified
     after start of test suite)
     """
     generate.main()
     for locale in CONFIGURATION.locales:
         for filename in ('django', 'djangojs'):
             mofile = filename+'.mo'
             path = os.path.join(CONFIGURATION.get_messages_dir(locale), mofile)
             exists = os.path.exists(path)
             self.assertTrue(exists, msg='Missing file in locale %s: %s' % (locale, mofile))
             self.assertTrue(datetime.fromtimestamp(os.path.getmtime(path), UTC) >= self.start_time,
                             msg='File not recently modified: %s' % path)
コード例 #9
0
    def assert_merge_headers(self, locale):
        """
        This is invoked by test_main to ensure that it runs after
        calling generate.main().

        There should be exactly three merge comment headers
        in our merged .po file. This counts them to be sure.
        A merge comment looks like this:
        # #-#-#-#-#  django-partial.po (0.1a)  #-#-#-#-#

        """
        path = os.path.join(CONFIGURATION.get_messages_dir(locale), "django.po")
        po = pofile(path)
        pattern = re.compile("^#-#-#-#-#", re.M)
        match = pattern.findall(po.header)
        self.assertEqual(
            len(match), 3, msg="Found %s (should be 3) merge comments in the header for %s" % (len(match), path)
        )
コード例 #10
0
    def assert_merge_headers(self, locale):
        """
        This is invoked by test_main to ensure that it runs after
        calling generate.main().

        There should be exactly three merge comment headers
        in our merged .po file. This counts them to be sure.
        A merge comment looks like this:
        # #-#-#-#-#  django-partial.po (0.1a)  #-#-#-#-#

        """
        path = os.path.join(CONFIGURATION.get_messages_dir(locale), 'django.po')
        po = pofile(path)
        pattern = re.compile('^#-#-#-#-#', re.M)
        match = pattern.findall(po.header)
        self.assertEqual(len(match), 3,
                         msg="Found %s (should be 3) merge comments in the header for %s" % \
                         (len(match), path))
コード例 #11
0
ファイル: generate.py プロジェクト: 1amongus/edx-platform
def merge(locale, target='django.po', sources=('django-partial.po',), fail_if_missing=True):
    """
    For the given locale, merge the `sources` files to become the `target`
    file.  Note that the target file might also be one of the sources.

    If fail_if_missing is true, and the files to be merged are missing,
    throw an Exception, otherwise return silently.

    If fail_if_missing is false, and the files to be merged are missing,
    just return silently.

    """
    LOG.info('Merging {target} for locale {locale}'.format(target=target, locale=locale))
    locale_directory = CONFIGURATION.get_messages_dir(locale)
    try:
        validate_files(locale_directory, sources)
    except Exception, e:
        if not fail_if_missing:
            return
        raise
コード例 #12
0
 def test_main(self):
     """
     Runs generate.main() which should merge source files,
     then compile all sources in all configured languages.
     Validates output by checking all .mo files in all configured languages.
     .mo files should exist, and be recently created (modified
     after start of test suite)
     """
     generate.main(verbosity=0, strict=False)
     for locale in CONFIGURATION.translated_locales:
         for filename in ("django", "djangojs"):
             mofile = filename + ".mo"
             path = os.path.join(CONFIGURATION.get_messages_dir(locale), mofile)
             exists = os.path.exists(path)
             self.assertTrue(exists, msg="Missing file in locale %s: %s" % (locale, mofile))
             self.assertGreaterEqual(
                 datetime.fromtimestamp(os.path.getmtime(path), UTC),
                 self.start_time,
                 msg="File not recently modified: %s" % path,
             )
コード例 #13
0
ファイル: test_generate.py プロジェクト: baxeico/i18n-tools
    def test_resolve_merge_conflicts(self, mock_log):
        django_po_path = os.path.join(CONFIGURATION.get_messages_dir('fake2'), 'django.po')
        # File ought to have been generated in test_main
        # if not os.path.exists(django_po_path):
        generate.main(verbose=0, strict=False)

        with open(django_po_path, 'r') as django_po_file:
            po_lines = django_po_file.read()

        # check that there are no merge conflicts present
        # "#-#-#-#-#  django-partial.po (edx-platform)  #-#-#-#-#\n"
        pattern = re.compile('\"#-#-#-#-#.*#-#-#-#-#', re.M)
        match = pattern.findall(po_lines)
        self.assertEqual(len(match), 0, msg="Error, found merge conflicts in django.po: %s" % match)
        # Validate that the appropriate log warnings were shown
        self.assertTrue(mock_log.warn.called)
        self.assertIn(
            " %s duplicates in %s, details in .dup file",
            # the first item of call_args is the call arguments themselves as a tuple
            mock_log.warn.call_args[0]
        )
コード例 #14
0
ファイル: generate.py プロジェクト: vicjwang/edx-platform
def merge(locale, target="django.po", fail_if_missing=True):
    """
    For the given locale, merge django-partial.po, messages.po, mako.po -> django.po
    target is the resulting filename

    If fail_if_missing is true, and the files to be merged are missing,
    throw an Exception, otherwise return silently.

    If fail_if_missing is false, and the files to be merged are missing,
    just return silently.

    """
    LOG.info("Merging locale={0}".format(locale))
    locale_directory = CONFIGURATION.get_messages_dir(locale)
    files_to_merge = ("django-partial.po", "messages.po", "mako.po")
    try:
        validate_files(locale_directory, files_to_merge)
    except Exception, e:
        if not fail_if_missing:
            return
        raise e
コード例 #15
0
def merge(locale,
          target='django.po',
          sources=('django-partial.po', ),
          fail_if_missing=True):
    """
    For the given locale, merge the `sources` files to become the `target`
    file.  Note that the target file might also be one of the sources.

    If fail_if_missing is true, and the files to be merged are missing,
    throw an Exception, otherwise return silently.

    If fail_if_missing is false, and the files to be merged are missing,
    just return silently.

    """
    LOG.info('Merging {target} for locale {locale}'.format(target=target,
                                                           locale=locale))
    locale_directory = CONFIGURATION.get_messages_dir(locale)
    try:
        validate_files(locale_directory, sources)
    except Exception, e:
        if not fail_if_missing:
            return
        raise e
コード例 #16
0
    def test_resolve_merge_conflicts(self, mock_log):
        django_po_path = os.path.join(CONFIGURATION.get_messages_dir('fake2'),
                                      'django.po')
        # File ought to have been generated in test_main
        # if not os.path.exists(django_po_path):
        generate.main(verbose=0, strict=False)

        with open(django_po_path, 'r') as django_po_file:
            po_lines = django_po_file.read()

        # check that there are no merge conflicts present
        # "#-#-#-#-#  django-partial.po (edx-platform)  #-#-#-#-#\n"
        pattern = re.compile('\"#-#-#-#-#.*#-#-#-#-#', re.M)
        match = pattern.findall(po_lines)
        self.assertEqual(len(match),
                         0,
                         msg="Error, found merge conflicts in django.po: %s" %
                         match)
        # Validate that the appropriate log warnings were shown
        self.assertTrue(mock_log.warning.called)
        self.assertIn(
            " %s duplicates in %s, details in .dup file",
            # the first item of call_args is the call arguments themselves as a tuple
            mock_log.warning.call_args[0])