Commit f02f470e authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents 3be192b7 223d6d87
...@@ -27,6 +27,7 @@ from translate.storage.properties import propunit, propfile ...@@ -27,6 +27,7 @@ from translate.storage.properties import propunit, propfile
from translate.storage.xliff import xliffunit, xlifffile, ID_SEPARATOR from translate.storage.xliff import xliffunit, xlifffile, ID_SEPARATOR
from translate.storage.po import pounit, pofile from translate.storage.po import pounit, pofile
from translate.storage.poheader import default_header
from translate.storage.php import phpunit from translate.storage.php import phpunit
from translate.storage.ts2 import tsunit, tsfile from translate.storage.ts2 import tsunit, tsfile
from translate.storage import mo from translate.storage import mo
...@@ -729,7 +730,7 @@ class FileFormat(object): ...@@ -729,7 +730,7 @@ class FileFormat(object):
with open(filename, 'w') as output: with open(filename, 'w') as output:
output.write(cls.new_translation) output.write(cls.new_translation)
def iterate_merge(self, fuzzy, header=False): def iterate_merge(self, fuzzy):
"""Iterates over units for merging. """Iterates over units for merging.
Note: This can change fuzzy state of units! Note: This can change fuzzy state of units!
...@@ -737,8 +738,6 @@ class FileFormat(object): ...@@ -737,8 +738,6 @@ class FileFormat(object):
for unit in self.all_units(): for unit in self.all_units():
# Handle header # Handle header
if unit.unit and unit.unit.isheader(): if unit.unit and unit.unit.isheader():
if header:
yield False, unit
continue continue
# Skip fuzzy (if asked for that) # Skip fuzzy (if asked for that)
...@@ -757,6 +756,11 @@ class FileFormat(object): ...@@ -757,6 +756,11 @@ class FileFormat(object):
yield set_fuzzy, unit yield set_fuzzy, unit
def merge_header(self, otherstore):
"""Tries to merge headers"""
raise Exception('x')
return
@register_fileformat @register_fileformat
class AutoFormat(FileFormat): class AutoFormat(FileFormat):
...@@ -769,7 +773,10 @@ class AutoFormat(FileFormat): ...@@ -769,7 +773,10 @@ class AutoFormat(FileFormat):
First attempt own autodetection, then fallback to ttkit. First attempt own autodetection, then fallback to ttkit.
""" """
filename = getattr(storefile, 'name', None) if hasattr(storefile, 'read'):
filename = getattr(storefile, 'name', None)
else:
filename = storefile
if filename is not None: if filename is not None:
name = os.path.basename(filename) name = os.path.basename(filename)
for autoload, storeclass in FILE_DETECT: for autoload, storeclass in FILE_DETECT:
...@@ -893,6 +900,34 @@ class PoFormat(FileFormat): ...@@ -893,6 +900,34 @@ class PoFormat(FileFormat):
if retcode: if retcode:
raise ValueError(output_err if output_err else output) raise ValueError(output_err if output_err else output)
def merge_header(self, otherstore):
"""Tries to merge headers"""
values = otherstore.store.parseheader()
skip_list = (
'Plural-Forms',
'Content-Type',
'Content-Transfer-Encoding',
'MIME-Version',
'Language',
)
update = {}
for key in values:
if key in skip_list:
continue
if values[key] == default_header.get(key, None):
continue
update[key] = values[key]
self.store.updateheader(**update)
header = self.store.header()
newheader = otherstore.store.header()
if not header or not newheader:
return
header.removenotes()
header.addnote(newheader.getnotes())
@register_fileformat @register_fileformat
class PoMonoFormat(PoFormat): class PoMonoFormat(PoFormat):
......
...@@ -1092,12 +1092,10 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -1092,12 +1092,10 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
store1 = self.store.store store1 = self.store.store
store1.require_index() store1.require_index()
for set_fuzzy, unit2 in store2.iterate_merge(fuzzy, merge_header): if merge_header:
# Optionally merge header self.store.merge_header(store2)
if unit2.unit.isheader():
if isinstance(store1, poheader.poheader): for set_fuzzy, unit2 in store2.iterate_merge(fuzzy):
store1.mergeheaders(store2.store)
continue
# Find unit by ID # Find unit by ID
unit1 = store1.findid(unit2.unit.getid()) unit1 = store1.findid(unit2.unit.getid())
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER # Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package. # This file is distributed under the same license as the PACKAGE package.
# Automatically generated, 2012. # Automatically generated, 2012.
# Testing Weblate, 2015.
# #
msgid "" msgid ""
msgstr "" msgstr ""
...@@ -10,7 +11,7 @@ msgstr "" ...@@ -10,7 +11,7 @@ msgstr ""
"POT-Creation-Date: 2012-03-14 15:54+0100\n" "POT-Creation-Date: 2012-03-14 15:54+0100\n"
"PO-Revision-Date: 2012-03-05 15:55+0100\n" "PO-Revision-Date: 2012-03-05 15:55+0100\n"
"Last-Translator: Automatically generated\n" "Last-Translator: Automatically generated\n"
"Language-Team: none\n" "Language-Team: Test Team <noreply@weblate.org>\n"
"Language: cs\n" "Language: cs\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
......
...@@ -107,6 +107,16 @@ class ImportTest(ImportBaseTest): ...@@ -107,6 +107,16 @@ class ImportTest(ImportBaseTest):
unit = self.get_unit() unit = self.get_unit()
self.assertEqual(unit.target, TRANSLATION_PO) self.assertEqual(unit.target, TRANSLATION_PO)
# Verify header
header = unit.translation.store.store.parseheader()
self.assertEqual(
header['Language-Team'], 'Test Team <noreply@weblate.org>'
)
self.assertIn(
'Testing Weblate, 2015.',
unit.translation.store.store.header().getnotes()
)
def test_import_author(self): def test_import_author(self):
''' '''
Test importing normally. Test importing normally.
......
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