Commit 26387b4c authored by Michal Čihař's avatar Michal Čihař

Improve support for PHP files

- correct mime type and extension
- support for adding new (empty) translations
- add testcase for this format
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent d849955d
......@@ -6,6 +6,8 @@ weblate 2.4
Released on ? 2015.
* Improved support for PHP files.
weblate 2.3
-----------
......
......@@ -247,9 +247,6 @@ PHP strings
.. index::
pair: PHP strings; file format
PHP strings can be processed directly, though currently Translate-toolkit has
some problems writing them properly, so please double check that your files
won't get corrupted.
PHP translations are usually monolingual, so it is recommended to specify base
file with English strings.
......@@ -264,7 +261,10 @@ Sample file which should work:
.. note::
This file format does not supporting automatically adding new translations.
Translate-toolkit currently has some limitations in processing PHP files,
so please double check that your files won't get corrupted before using
Weblate in production setup.
.. seealso::
......@@ -285,7 +285,7 @@ JSON translations are usually monolingual, so it is recommended to specify base
file with English strings.
.. note::
Weblate currently supports only simple JSON files with key value mappings,
more complex formats like the ones used by Chrome extensions are currently
not supported by translate-toolkit and will produce invalid results.
......
......@@ -852,6 +852,21 @@ class PhpFormat(FileFormat):
name = _('PHP strings')
format_id = 'php'
loader = ('php', 'phpfile')
new_translation = '<?php\n'
@property
def mimetype(self):
'''
Returns most common mime type for format.
'''
return 'text/x-php'
@property
def extension(self):
'''
Returns most common file extension for format.
'''
return 'php'
@register_fileformat
......
<?php
$LANG['foo'] = 'bar';
$LANG['foo1'] = 'foo bar';
$LANG['foo2'] = 'foo bar baz';
$LANG['foo3'] = 'foo bar baz bag';
......@@ -24,13 +24,14 @@ import tempfile
from unittest import TestCase
from weblate.trans.formats import (
AutoFormat, PoFormat, AndroidFormat, PropertiesFormat,
JSONFormat, RESXFormat,
JSONFormat, RESXFormat, PhpFormat,
FILE_FORMATS,
)
from weblate.trans.tests.utils import get_test_file
TEST_PO = get_test_file('cs.po')
TEST_JSON = get_test_file('cs.json')
TEST_PHP = get_test_file('cs.php')
TEST_PROPERTIES = get_test_file('swing.properties')
TEST_ANDROID = get_test_file('strings.xml')
TEST_POT = get_test_file('hello.pot')
......@@ -112,6 +113,19 @@ class JSONFormatTest(AutoFormatTest):
BASE = ''
class PhpFormatTest(AutoFormatTest):
FORMAT = PhpFormat
FILE = TEST_PHP
MIME = 'text/x-php'
COUNT = 4
EXT = 'php'
MASK = 'php/*/admin.php'
EXPECTED_PATH = 'php/cs_CZ/admin.php'
MATCH = '<?php\n'
FIND = '$LANG[\'foo\']'
FIND_MATCH = 'bar'
class AndroidFormatTest(AutoFormatTest):
FORMAT = AndroidFormat
FILE = TEST_ANDROID
......
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