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.po', 'mako.po'): clean_file(dirname.joinpath(filename))
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))
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)) >= self.start_time, msg='File not recently modified: %s' % path) self.assert_merge_headers(locale)
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. 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
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. 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
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))
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)) >= self.start_time, msg='File not recently modified: %s' % path) self.assert_merge_headers(locale)