コード例 #1
0
ファイル: test_po2php.py プロジェクト: anderson916/translate
 def merge2php(self, phpsource, posource):
     """helper that merges po translations to .php source without requiring files"""
     inputfile = wStringIO.StringIO(posource)
     inputpo = po.pofile(inputfile)
     templatefile = wStringIO.StringIO(phpsource)
     #templatephp = php.phpfile(templatefile)
     convertor = po2php.rephp(templatefile, inputpo)
     outputphp = convertor.convertstore()
     print(outputphp)
     return outputphp
コード例 #2
0
 def merge2php(self, phpsource, posource):
     """helper that merges po translations to .php source without requiring files"""
     inputfile = BytesIO(posource.encode())
     inputpo = po.pofile(inputfile)
     templatefile = BytesIO(phpsource.encode())
     #templatephp = php.phpfile(templatefile)
     convertor = po2php.rephp(templatefile, inputpo)
     outputphp = [line.decode('utf-8') for line in convertor.convertstore()]
     print(outputphp)
     return outputphp
コード例 #3
0
ファイル: test_po2php.py プロジェクト: mozilla/markup-lib
 def merge2php(self, phpsource, posource):
     """helper that merges po translations to .php source without requiring files"""
     inputfile = wStringIO.StringIO(posource)
     inputpo = po.pofile(inputfile)
     templatefile = wStringIO.StringIO(phpsource)
     #templatephp = php.phpfile(templatefile)
     convertor = po2php.rephp(templatefile)
     outputphp = convertor.convertstore(inputpo)
     print outputphp
     return outputphp
コード例 #4
0
    def save(self):
        """Save underlaying store to disk.

        This is workaround for .save() not working as intended in
        translate-toolkit.
        """
        with open(self.store.filename, 'rb') as handle:
            convertor = po2php.rephp(handle, self.store)

            outputphplines = convertor.convertstore(False)

        with open(self.store.filename, 'wb') as handle:
            handle.writelines(outputphplines)
コード例 #5
0
    def save(self):
        """Save underlaying store to disk.

        This is workaround for .save() not working as intended in
        translate-toolkit.
        """
        if self.using_phplexer:
            # New phply based storage handles save just fine
            # see https://github.com/translate/translate/pull/3697
            super(PhpFormat, self).save()
        else:
            with open(self.store.filename, 'rb') as handle:
                convertor = po2php.rephp(handle, self.store)

                outputphplines = convertor.convertstore(False)

            with open(self.store.filename, 'wb') as handle:
                handle.writelines(outputphplines)
コード例 #6
0
    def save(self):
        """Save underlaying store to disk.

        This is workaround for .save() not working as intended in
        translate-toolkit.
        """
        try:
            # New phply based storage handles save just fine
            # see https://github.com/translate/translate/pull/3697
            # pylint: disable=W0612
            from translate.storage.php import PHPLexer  # noqa
            super(PhpFormat, self).save()
        except ImportError:
            with open(self.store.filename, 'rb') as handle:
                convertor = po2php.rephp(handle, self.store)

                outputphplines = convertor.convertstore(False)

            with open(self.store.filename, 'wb') as handle:
                handle.writelines(outputphplines)