Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
i18nbuild: Remove "Domain", "Language-Code" and "Language-Name" headers.
Plone does not need those headers, it takes informations from the path.
The headers are usually not set correctly, so we just remove them.
  • Loading branch information
jone committed Mar 5, 2014
1 parent 3254039 commit a6335f2
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 4 deletions.
5 changes: 4 additions & 1 deletion docs/HISTORY.txt
Expand Up @@ -5,7 +5,10 @@ Changelog
1.1.1 (unreleased)
------------------

- Nothing changed yet.
- i18nbuild: Remove "Domain", "Language-Code" and "Language-Name" headers.
Plone does not need those headers, it takes informations from the path.
The headers are usually not set correctly, so we just remove them.
[jone]


1.1.0 (2014-03-05)
Expand Down
3 changes: 3 additions & 0 deletions ftw/recipe/translations/i18ntools.py
@@ -1,6 +1,7 @@
from ftw.recipe.translations import discovery
from ftw.recipe.translations.discovery import discover_package
from ftw.recipe.translations.utils import chdir
from ftw.recipe.translations.writer import cleanup_pofile
from i18ndude.catalog import MessageCatalog
from i18ndude.catalog import POWriter
from path import path
Expand Down Expand Up @@ -49,6 +50,7 @@ def rebuild_pot(package_root, package_dir, domain, potpath, manual, content):
i18ndude.script.rebuild_pot(arguments)
except SystemExit:
pass
cleanup_pofile(potpath)


def sync_package_pofiles(package_dir, languages):
Expand Down Expand Up @@ -99,6 +101,7 @@ def sync_pofile_group(base_dir, group, languages):
i18ndude.script.sync(arguments)
except SystemExit:
pass
map(cleanup_pofile, pofiles)


def create_new_pofile(path, domain):
Expand Down
9 changes: 6 additions & 3 deletions ftw/recipe/translations/tests/fshelpers.py
Expand Up @@ -4,7 +4,10 @@

def create_structure(*dirs_and_structure):
structure = dirs_and_structure[-1]
basedir = resolve_to_path(dirs_and_structure[:-1])
if len(dirs_and_structure) > 1:
basedir = resolve_to_path(dirs_and_structure[:-1])
else:
basedir = None

for filepath, data in structure.items():
filepath = resolve_to_path((basedir, filepath))
Expand All @@ -15,8 +18,8 @@ def create_structure(*dirs_and_structure):
file_.write(data)


def cat(basedir, relpath):
filepath = os.path.join(basedir, relpath)
def cat(*pathparts):
filepath = resolve_to_path(pathparts)
with open(filepath) as file_:
return file_.read()

Expand Down
8 changes: 8 additions & 0 deletions ftw/recipe/translations/tests/pohelpers.py
@@ -1,6 +1,7 @@
from StringIO import StringIO
from ftw.recipe.translations.tests import fshelpers
from i18ndude.catalog import MessageCatalog
import re


def messages(*pathparts):
Expand All @@ -26,6 +27,13 @@ def message_references(*pathparts):
return messages


def headers(*pathparts):
lines = fshelpers.cat(pathparts).split('\n')
headers = filter(re.compile('".*:.*"').match, lines)
headers = map(lambda line: line.rstrip('"').lstrip('"'), headers)
headers = map(lambda line: map(str.strip, line.split(':', 1)), headers)
return dict(headers)


def makepo(messages):
data = StringIO()
Expand Down
81 changes: 81 additions & 0 deletions ftw/recipe/translations/tests/test_i18nbuild_command.py
Expand Up @@ -144,3 +144,84 @@ def test_path_comments_are_relative_in_pofile(self):
build_translations(self.tempdir, self.tempdir, 'foo', output=None)
self.assertEquals({'Foo': ['./foo/foo/__init__.py:1']},
pohelpers.message_references(*pofile))

def test_synced_files_have_no_Domain_header(self):
package = (self.tempdir, 'foo/foo')
locales = (package, 'locales')
locales_de = (locales, 'de/LC_MESSAGES')
fshelpers.create_structure({
(package, '__init__.py'): '_("Foo")',
(locales, 'foo.pot'): fshelpers.asset('empty.pot'),
(locales_de, 'foo.po'): fshelpers.asset('empty.po')})

build_translations(self.tempdir, self.tempdir, 'foo', output=None)

self.assertNotIn(
'Domain',
pohelpers.headers(locales_de, 'foo.po'),

'The "Domain" header is not necessary for Plone, since the'
' filename contains the domain and it is often not set'
' correctly, therefore we remove it.')

self.assertNotIn(
'Domain',
pohelpers.headers(locales, 'foo.pot'),

'The "Domain" header is not necessary for Plone, since the'
' filename contains the domain and it is often not set'
' correctly, therefore we remove it.')

def test_synced_files_have_no_Language_Code_header(self):
package = (self.tempdir, 'foo/foo')
locales = (package, 'locales')
locales_de = (locales, 'de/LC_MESSAGES')
fshelpers.create_structure({
(package, '__init__.py'): '_("Foo")',
(locales, 'foo.pot'): fshelpers.asset('empty.pot'),
(locales_de, 'foo.po'): fshelpers.asset('empty.po')})

build_translations(self.tempdir, self.tempdir, 'foo', output=None)

self.assertNotIn(
'Language-Code',
pohelpers.headers(locales_de, 'foo.po'),

'The "Language-Code" header is not necessary for Plone, since the'
' filename contains the domain and it is often not set'
' correctly, therefore we remove it.')

self.assertNotIn(
'Language-Code',
pohelpers.headers(locales, 'foo.pot'),

'The "Language-Code" header is not necessary for Plone, since the'
' filename contains the domain and it is often not set'
' correctly, therefore we remove it.')

def test_synced_files_have_no_Language_Name_header(self):
package = (self.tempdir, 'foo/foo')
locales = (package, 'locales')
locales_de = (locales, 'de/LC_MESSAGES')
fshelpers.create_structure({
(package, '__init__.py'): '_("Foo")',
(locales, 'foo.pot'): fshelpers.asset('empty.pot'),
(locales_de, 'foo.po'): fshelpers.asset('empty.po')})

build_translations(self.tempdir, self.tempdir, 'foo', output=None)

self.assertNotIn(
'Language-Name',
pohelpers.headers(locales_de, 'foo.po'),

'The "Language-Code" header is not necessary for Plone, since the'
' filename contains the domain and it is often not set'
' correctly, therefore we remove it.')

self.assertNotIn(
'Language-Name',
pohelpers.headers(locales, 'foo.pot'),

'The "Language-Code" header is not necessary for Plone, since the'
' filename contains the domain and it is often not set'
' correctly, therefore we remove it.')
7 changes: 7 additions & 0 deletions ftw/recipe/translations/tests/test_i18nbuild_integration.py
Expand Up @@ -86,6 +86,13 @@ def test_updating_translations(self):
pohelpers.messages(locales_en, 'plone.po'),
'Existing language was not synced.')

lines = fshelpers.cat(locales_de, 'package.po').split('\n')
self.assertEquals(
[],
filter(lambda line: line.startswith('"Domain'), lines),
'.po-files should not contain Domain-headers, because'
' they are not relevant and often not set correctly.')

# path comments
self.assertDictContainsSubset(
{u'Foo': [u'./the/package/__init__.py:1']},
Expand Down

0 comments on commit a6335f2

Please sign in to comment.