Commit f90e28df authored by Michal Čihař's avatar Michal Čihař

Improved support for translating PHP files

Issue #965
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent fce20aca
...@@ -41,6 +41,7 @@ Released on ? 2015. ...@@ -41,6 +41,7 @@ Released on ? 2015.
* Added configurable dashboard views. * Added configurable dashboard views.
* Improved notifications on parse erorrs. * Improved notifications on parse erorrs.
* Added option to import components with duplicate name to import_project. * Added option to import components with duplicate name to import_project.
* Improved support for translating PHP files
weblate 2.4 weblate 2.4
----------- -----------
......
...@@ -403,6 +403,26 @@ class RESXUnit(FileUnit): ...@@ -403,6 +403,26 @@ class RESXUnit(FileUnit):
return get_string(self.template.target) return get_string(self.template.target)
class PHPUnit(FileUnit):
def get_locations(self):
return ''
def get_context(self):
if self.template is not None:
return self.template.getsource()
return ''
def get_source(self):
if self.template is not None:
return self.template.getsource()
return self.unit.getsource()
def get_target(self):
if self.unit is None:
return ''
return self.unit.gettarget()
class FileFormat(object): class FileFormat(object):
''' '''
Generic object defining file format loader. Generic object defining file format loader.
...@@ -1071,6 +1091,7 @@ class PhpFormat(FileFormat): ...@@ -1071,6 +1091,7 @@ class PhpFormat(FileFormat):
loader = ('php', 'phpfile') loader = ('php', 'phpfile')
new_translation = '<?php\n' new_translation = '<?php\n'
autoload = ('.php',) autoload = ('.php',)
unit_class = PHPUnit
@property @property
def mimetype(self): def mimetype(self):
......
...@@ -282,6 +282,13 @@ class RepoTestCase(TestCase): ...@@ -282,6 +282,13 @@ class RepoTestCase(TestCase):
'csv-mono/en.csv', 'csv-mono/en.csv',
) )
def create_php_mono(self):
return self._create_subproject(
'php',
'php-mono/*.php',
'php-mono/en.php',
)
def create_java(self): def create_java(self):
return self._create_subproject( return self._create_subproject(
'properties', 'properties',
......
...@@ -185,6 +185,10 @@ class SubProjectTest(RepoTestCase): ...@@ -185,6 +185,10 @@ class SubProjectTest(RepoTestCase):
project = self.create_csv_mono() project = self.create_csv_mono()
self.verify_subproject(project, 2, 'cs', 4) self.verify_subproject(project, 2, 'cs', 4)
def test_create_php_mono(self):
project = self.create_php_mono()
self.verify_subproject(project, 2, 'cs', 4)
def test_create_tsv(self): def test_create_tsv(self):
project = self.create_tsv() project = self.create_tsv()
self.verify_subproject(project, 1, 'cs', 4, 'Hello, world!') self.verify_subproject(project, 1, 'cs', 4, 'Hello, world!')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment