def upload(spreadsheet, sources_directory, languages=None,
           additional_languages=None, filter_translated=True,
           output=sys.stdout):
    """Upload the translations into the configured spreadsheet in a
    new worksheet.
    """
    include_languages = (languages or []) + (additional_languages or [])
    if len(include_languages) == 0:
        include_languages = None

    with capture_streams(stdout=output or StringIO()):
        print 'Loading translations'
        catalog = load_translation_catalog(sources_directory)

        data = catalog.get_message_dicts(include_languages)
        if filter_translated:
            data = filter(translated_languages_filterer(languages or None),
                          data)

        data.sort(key=lambda item: (item.get('package'),
                                    item.get('domain'),
                                    item.get('msgid')))

        worksheet_title = spreadsheet.upload(data)
        print 'Uploaded into worksheet "%s"' % worksheet_title
Esempio n. 2
0
def upload(spreadsheet,
           sources_directory,
           languages=None,
           additional_languages=None,
           filter_translated=True,
           output=sys.stdout):
    """Upload the translations into the configured spreadsheet in a
    new worksheet.
    """
    include_languages = (languages or []) + (additional_languages or [])
    if len(include_languages) == 0:
        include_languages = None

    with capture_streams(stdout=output or StringIO()):
        print 'Loading translations'
        catalog = load_translation_catalog(sources_directory)

        data = catalog.get_message_dicts(include_languages)
        if filter_translated:
            data = filter(translated_languages_filterer(languages or None),
                          data)

        data.sort(key=lambda item:
                  (item.get('package'), item.get('domain'), item.get('msgid')))

        worksheet_title = spreadsheet.upload(data)
        print 'Uploaded into worksheet "%s"' % worksheet_title
 def test_captures_all_streams_parallel(self):
     stdout = StringIO()
     stderr = StringIO()
     with utils.capture_streams(stdout=stdout, stderr=stderr):
         print 'Foo'
         print >> sys.stderr, 'Bar'
     self.assertEquals('Foo\n', stdout.getvalue())
     self.assertEquals('Bar\n', stderr.getvalue())
Esempio n. 4
0
def synchronize(sources_directory, languages=None, output=sys.stdout):
    """Rebuilds .pot-files of the default domain of each package in the
    source directory and syncs all .po-files with the .pot-files of all
    domains in each package.
    """
    with capture_streams(stdout=output or StringIO()):
        rebuild_primary_domain_group_potfiles(sources_directory)
        sync_pofiles(sources_directory, languages)
Esempio n. 5
0
def synchronize(sources_directory, languages=None, output=sys.stdout):
    """Rebuilds .pot-files of the default domain of each package in the
    source directory and syncs all .po-files with the .pot-files of all
    domains in each package.
    """
    with capture_streams(stdout=output or StringIO()):
        rebuild_primary_domain_group_potfiles(sources_directory)
        sync_pofiles(sources_directory, languages)
Esempio n. 6
0
def build_translations(package_dir,
                       package_root,
                       i18n_domain,
                       new_languages=None,
                       output=sys.stdout):
    with capture_streams(stdout=output or StringIO()):
        rebuild_inflator(package_dir, i18n_domain)
        rebuild_package_potfiles(package_root, package_dir, i18n_domain)
        sync_package_pofiles(package_dir, new_languages)
 def test_i18ndude_SystemExit_is_handled(self):
     # This is quite a "stupid" test:
     # Rebuilding a domain without having any translations makes the internal
     # i18ndude command to perform a system exit.
     # This is really bad, since we are possibly building multiple pot-files
     # and are doing more stuff and should be in control of such things.
     fshelpers.create_structure(self.tempdir, {"foo/locales/foo.pot": fshelpers.asset("empty.pot")})
     try:
         with capture_streams(stderr=StringIO()):
             rebuild_package_potfiles(self.tempdir, self.tempdir, "foo")
     except SystemExit:
         assert False, "SystemExit leaked from i18ndude while rebuilding pot-files!"
Esempio n. 8
0
 def test_i18ndude_SystemExit_is_handled(self):
     # This is quite a "stupid" test:
     # Rebuilding a domain without having any translations makes the internal
     # i18ndude command to perform a system exit.
     # This is really bad, since we are possibly building multiple pot-files
     # and are doing more stuff and should be in control of such things.
     fshelpers.create_structure(
         self.tempdir,
         {'foo/locales/foo.pot': fshelpers.asset('empty.pot')})
     try:
         with capture_streams(stderr=StringIO()):
             rebuild_package_potfiles(self.tempdir, self.tempdir, 'foo')
     except SystemExit:
         assert False, 'SystemExit leaked from i18ndude while rebuilding pot-files!'
 def test_captures_stderr(self):
     stderr = StringIO()
     with utils.capture_streams(stderr=stderr):
         print >> sys.stderr, 'Error'
     self.assertEquals('Error\n', stderr.getvalue())
Esempio n. 10
0
 def test_captures_stdout(self):
     stdout = StringIO()
     with utils.capture_streams(stdout=stdout):
         print 'Foo'
     self.assertEquals('Foo\n', stdout.getvalue())
Esempio n. 11
0
def build_translations(package_dir, package_root, i18n_domain,
                       new_languages=None, output=sys.stdout):
    with capture_streams(stdout=output or StringIO()):
        rebuild_inflator(package_dir, i18n_domain)
        rebuild_package_potfiles(package_root, package_dir, i18n_domain)
        sync_package_pofiles(package_dir, new_languages)