Index: cms/sources.py
===================================================================
--- a/cms/sources.py
+++ b/cms/sources.py
@@ -142,34 +142,33 @@
def read_static(self, filename):
return self.read_file(self.static_filename(filename), binary=True)[0]
#
# Locale helpers
#
- @classmethod
- def locale_filename(cls, locale, page):
- return cls.localizable_file_filename(locale, page + '.json')
+ def locale_filename(self, locale, page):
+ config = self.read_config()
+ try:
+ page = config.get('locale_overrides', page)
+ except ConfigParser.Error:
+ pass
+ return self.localizable_file_filename(locale, page + '.json')
def list_locales(self):
result = set()
for filename in self.list_files('locales'):
if '/' in filename:
locale, path = filename.split('/', 1)
result.add(locale)
return result
def has_locale(self, locale, page):
- config = self.read_config()
- try:
- page = config.get('locale_overrides', page)
- except ConfigParser.Error:
- pass
return self.has_file(self.locale_filename(locale, page))
def read_locale(self, locale, page):
default_locale = self.read_config().get('general', 'defaultlocale')
result = collections.OrderedDict()
if locale != default_locale:
result.update(self.read_locale(default_locale, page))
Index: tests/expected_output/de/translate
===================================================================
--- a/tests/expected_output/de/translate
+++ b/tests/expected_output/de/translate
@@ -1,1 +1,8 @@
-
Übersetzen
\ No newline at end of file
+Simple TS with default: Übersetzen.
+Same TS with no default: Übersetzen.
+TS with fixed text: Fester text.
+Nested translation: Bar und Baz.
+Link resolving: Diese Seite.
+Link to a non-translatable page: Seitenverzeichnis.
+Entity escaping: Draggen&droppen.
+Entity escaping in links: Bar.
Index: tests/expected_output/de/translate-html
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/expected_output/de/translate-html
@@ -0,0 +1,19 @@
+
+
+Simple TS with default: Übersetzen.
+
+Same TS with no default: Übersetzen.
+
+TS with fixed text: Fester text.
+
+Nested translation: Bar und Baz.
+
+Link resolving: Diese Seite.
+
+Link to a non-translatable page: Seitenverzeichnis.
+
+Entity escaping: Draggen&droppen.
+
+Entity escaping in links: Bar.
+
+
Index: tests/expected_output/de/translate-include
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/expected_output/de/translate-include
@@ -0,0 +1,16 @@
+Translations from an include fragment
+Simple TS with default: Übersetzen.
+
+Same TS with no default: Übersetzen.
+
+TS with fixed text: Fester text.
+
+Nested translation: Bar und Baz.
+
+Link resolving: Diese Seite.
+
+Link to a non-translatable page: Seitenverzeichnis.
+
+Entity escaping: Draggen&droppen.
+
+Entity escaping in links: Bar.
Index: tests/expected_output/de/translate-not-enough@dynamic
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/expected_output/de/translate-not-enough@dynamic
@@ -0,0 +1,8 @@
+This page doesn't have enough translation in German so it shouldn't be generated.
+
+- Übersetzen - this one has translation to German, others don't.
+- TS2.
+- TS3.
+- TS4.
+
+
Index: tests/expected_output/de/translate-not-enough@static
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/expected_output/de/translate-not-enough@static
@@ -0,0 +1,1 @@
+## MISSING
Index: tests/expected_output/de/translate-partial
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/expected_output/de/translate-partial
@@ -0,0 +1,5 @@
+This page only has half of translation in German, but enough to be generated.
+
Index: tests/expected_output/de/translate-template
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/expected_output/de/translate-template
@@ -0,0 +1,15 @@
+Translation strings are all in the template
+
+Simple TS with default: Übersetzen.
+
+Same TS with no default: doesn't work in templates.
+
+TS with fixed text: Fester text.
+
+Nested translation: Bar und Baz.
+
+Link resolving: Diese Seite.
+
+Entity escaping: Draggen&droppen.
+
+Entity escaping in links: Bar.
Index: tests/expected_output/de/translate-tmpl
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/expected_output/de/translate-tmpl
@@ -0,0 +1,17 @@
+
+
+Simple TS with default: Übersetzen.
+
+Same TS with no default: Übersetzen.
+
+TS with fixed text: Fester text.
+
+Nested translation: Bar und Baz.
+
+Link resolving: Diese Seite.
+
+Entity escaping: Draggen&droppen.
+
+Entity escaping in links: Bar.
+
+
Index: tests/expected_output/en/sitemap
===================================================================
--- a/tests/expected_output/en/sitemap
+++ b/tests/expected_output/en/sitemap
@@ -1,14 +1,26 @@
Unfiltered
-- title : filter
- title : get_page_url
- title : global
- title : includer
- title : translate
- title : sitemap
+
+ - title : filter
+ - title : get_page_url
+ - title : global
+ - title : includer
+ - title : translate
+ - title : translate-html
+ - title : translate-include
+ - title : translate-not-enough
+ - title : translate-partial
+ - title : translate-template
+ - title : translate-tmpl
+ - title : sitemap
Filtered
String Filter For Listy Option
- title : sitemap
Index: tests/expected_output/en/translate
===================================================================
--- a/tests/expected_output/en/translate
+++ b/tests/expected_output/en/translate
@@ -1,1 +1,8 @@
-Translate
\ No newline at end of file
+Simple TS with default: Translate.
+Same TS with no default: Translate.
+TS with fixed text: Fixed text.
+Nested translation: Foo and Baz.
+Link resolving: This page.
+Link to a non-translatable page: Site map.
+Entity escaping: Drag&drop.
+Entity escaping in links: Foo.
Index: tests/expected_output/en/translate-html
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/expected_output/en/translate-html
@@ -0,0 +1,19 @@
+
+
+Simple TS with default: Translate.
+
+Same TS with no default: Translate.
+
+TS with fixed text: Fixed text.
+
+Nested translation: Foo and Baz.
+
+Link resolving: This page.
+
+Link to a non-translatable page: Site map.
+
+Entity escaping: Drag&drop.
+
+Entity escaping in links: Foo.
+
+
Index: tests/expected_output/en/translate-include
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/expected_output/en/translate-include
@@ -0,0 +1,16 @@
+Translations from an include fragment
+Simple TS with default: Translate.
+
+Same TS with no default: Translate.
+
+TS with fixed text: Fixed text.
+
+Nested translation: Foo and Baz.
+
+Link resolving: This page.
+
+Link to a non-translatable page: Site map.
+
+Entity escaping: Drag&drop.
+
+Entity escaping in links: Foo.
Index: tests/expected_output/en/translate-template
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/expected_output/en/translate-template
@@ -0,0 +1,15 @@
+Translation strings are all in the template
+
+Simple TS with default: Translate.
+
+Same TS with no default: doesn't work in templates.
+
+TS with fixed text: Fixed text.
+
+Nested translation: Foo and Baz.
+
+Link resolving: This page.
+
+Entity escaping: Drag&drop.
+
+Entity escaping in links: Foo.
Index: tests/expected_output/en/translate-tmpl
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/expected_output/en/translate-tmpl
@@ -0,0 +1,17 @@
+
+
+Simple TS with default: Translate.
+
+Same TS with no default: Translate.
+
+TS with fixed text: Fixed text.
+
+Nested translation: Foo and Baz.
+
+Link resolving: This page.
+
+Entity escaping: Drag&drop.
+
+Entity escaping in links: Foo.
+
+
Index: tests/test_page_outputs.py
===================================================================
--- a/tests/test_page_outputs.py
+++ b/tests/test_page_outputs.py
@@ -50,22 +50,25 @@
@pytest.fixture(scope='session')
def output_pages(static_output):
return get_dir_contents(static_output)
@pytest.mark.parametrize('filename,expected_output', static_expected_outputs)
def test_static(output_pages, filename, expected_output):
- assert output_pages[filename] == expected_output
+ if expected_output.startswith('## MISSING'):
+ assert filename not in output_pages
+ else:
+ assert expected_output == output_pages[filename]
@pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs)
def test_dynamic(dynamic_server, filename, expected_output):
response = urllib2.urlopen(dynamic_server + filename)
- assert response.read().strip() == expected_output
+ assert expected_output == response.read().strip()
def test_revision_arg(revision, output_pages):
if revision is None:
assert 'en/bar' in output_pages
else:
assert 'en/bar' not in output_pages
Index: tests/test_site/includes/included-translations.html
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/test_site/includes/included-translations.html
@@ -0,0 +1,15 @@
+Simple TS with default: {{ simple[desc] Translate }}.
+
+Same TS with no default: {{ simple }}.
+
+TS with fixed text: {{fix-ts[fix] Fixed text}}.
+
+Nested translation: {{nested-ts Foo and Baz}}.
+
+Link resolving: {{linked-ts This page}}.
+
+Link to a non-translatable page: {{linked-ts2 Site map}}.
+
+Entity escaping: {{entity-ts Drag&drop}}.
+
+Entity escaping in links: {{entity-lnk Foo}}.
Index: tests/test_site/locales/de/translate-not-enough.json
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/test_site/locales/de/translate-not-enough.json
@@ -0,0 +1,7 @@
+{
+ "simple": {
+ "description": "test",
+ "message": "Übersetzen"
+ }
+}
+
Index: tests/test_site/locales/de/translate.json
===================================================================
--- a/tests/test_site/locales/de/translate.json
+++ b/tests/test_site/locales/de/translate.json
@@ -1,6 +1,31 @@
{
- "test_sample": {
+ "simple": {
"description": "test",
"message": "Übersetzen"
+ },
+ "fix-ts": {
+ "description": "fix",
+ "message": "Fester {1}"
+ },
+ "nested-ts": {
+ "message": "Bar und Baz"
+ },
+ "nested-link": {
+ "message": "http://bar.de/"
+ },
+ "nested-link2": {
+ "message": "http://baz.de/"
+ },
+ "linked-ts": {
+ "message": "Diese Seite"
+ },
+ "linked-ts2": {
+ "message": "Seitenverzeichnis"
+ },
+ "entity-ts": {
+ "message": "Draggen&droppen"
+ },
+ "entity-lnk": {
+ "message": "Bar"
}
}
Index: tests/test_site/locales/en/translate.json
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/test_site/locales/en/translate.json
@@ -0,0 +1,6 @@
+{
+ "simple": {
+ "description": "test",
+ "message": "Translate"
+ }
+}
Index: tests/test_site/pages/sitemap.tmpl
===================================================================
--- a/tests/test_site/pages/sitemap.tmpl
+++ b/tests/test_site/pages/sitemap.tmpl
@@ -1,16 +1,16 @@
template = empty
product = foo
title = test_metadata
tags = [popular, bar]
Unfiltered
- {%- for unfiltered_page in get_pages_metadata()|sort -%}
- - title : {{ unfiltered_page['page']}}
+{%- for unfiltered_page in get_pages_metadata()|sort %}
+ - title : {{ unfiltered_page['page']}}
{%- endfor %}
Filtered
{%- for filtered_page in get_pages_metadata({'tags': ['popular', 'bar']})|sort -%}
- title : {{ filtered_page['page'] }}
{%- endfor %}
Index: tests/test_site/pages/translate-html.html
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/test_site/pages/translate-html.html
@@ -0,0 +1,21 @@
+template = empty
+
+
+
+Simple TS with default: {{ simple[desc] Translate }}.
+
+Same TS with no default: {{ simple }}.
+
+TS with fixed text: {{fix-ts[fix] Fixed text}}.
+
+Nested translation: {{nested-ts Foo and Baz}}.
+
+Link resolving: {{linked-ts This page}}.
+
+Link to a non-translatable page: {{linked-ts2 Site map}}.
+
+Entity escaping: {{entity-ts Drag&drop}}.
+
+Entity escaping in links: {{entity-lnk Foo}}.
+
+
Index: tests/test_site/pages/translate-include.md
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/test_site/pages/translate-include.md
@@ -0,0 +1,5 @@
+template = empty
+
+# Translations from an include fragment
+
+ include included-translations ?>
Index: tests/test_site/pages/translate-not-enough.md
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/test_site/pages/translate-not-enough.md
@@ -0,0 +1,8 @@
+template = empty
+
+This page doesn't have enough translation in German so it shouldn't be generated.
+
+- {{ simple TS1 }} - this one has translation to German, others don't.
+- {{ ts2 TS2 }}.
+- {{ ts3 TS3 }}.
+- {{ ts4 TS4 }}.
Index: tests/test_site/pages/translate-partial.md
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/test_site/pages/translate-partial.md
@@ -0,0 +1,6 @@
+template = empty
+
+This page only has half of translation in German, but enough to be generated.
+
+- {{ simple TS1 }}.
+- {{ ts2 TS2 }}.
Index: tests/test_site/pages/translate-template.md
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/test_site/pages/translate-template.md
@@ -0,0 +1,3 @@
+template = translatable-template
+
+# Translation strings are all in the template
Index: tests/test_site/pages/translate-tmpl.tmpl
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/test_site/pages/translate-tmpl.tmpl
@@ -0,0 +1,19 @@
+template = empty
+
+
+
+Simple TS with default: {{ 'Translate' | translate('simple') }}.
+
+Same TS with no default: {{ get_string('simple') }}.
+
+TS with fixed text: {{ 'Fixed text' | translate('fix-ts') }}.
+
+Nested translation: {{ 'Foo and Baz' | translate('nested-ts') }}.
+
+Link resolving: {{ 'This page' | translate('linked-ts') }}.
+
+Entity escaping: {{ 'Drag&drop' | translate('entity-ts') }}.
+
+Entity escaping in links: {{ 'Foo' | translate('entity-lnk') }}.
+
+
Index: tests/test_site/pages/translate.md
===================================================================
--- a/tests/test_site/pages/translate.md
+++ b/tests/test_site/pages/translate.md
@@ -1,3 +1,17 @@
template = empty
-{{ test_sample[desc] Translate }}
+Simple TS with default: {{ simple[desc] Translate }}.
+
+Same TS with no default: {{ simple }}.
+
+TS with fixed text: {{fix-ts[fix] Fixed text}}.
+
+Nested translation: {{nested-ts Foo and Baz}}.
+
+Link resolving: {{linked-ts This page}}.
+
+Link to a non-translatable page: {{linked-ts2 Site map}}.
+
+Entity escaping: {{entity-ts Drag&drop}}.
+
+Entity escaping in links: {{entity-lnk Foo}}.
Index: tests/test_site/settings.ini
===================================================================
--- a/tests/test_site/settings.ini
+++ b/tests/test_site/settings.ini
@@ -1,9 +1,15 @@
[general]
defaultlocale = en
defaultpage = filter
crowdin-project-name = test
siteurl = https://acme.com/
[langnames]
de = Deutsch
-en = English
+
+[locale_overrides]
+translate-html = translate
+translate-tmpl = translate
+translate-include = translate
+translate-template = translate
+translate-partial = translate
Index: tests/test_site/templates/translatable-template.tmpl
===================================================================
new file mode 100644
--- /dev/null
+++ b/tests/test_site/templates/translatable-template.tmpl
@@ -0,0 +1,15 @@
+{{ body|safe }}
+
+Simple TS with default: {{ 'Translate' | translate('simple') }}.
+
+Same TS with no default: doesn't work in templates.
+
+TS with fixed text: {{ 'Fixed text' | translate('fix-ts') }}.
+
+Nested translation: {{ 'Foo and Baz' | translate('nested-ts') }}.
+
+Link resolving: {{ 'This page' | translate('linked-ts') }}.
+
+Entity escaping: {{ 'Drag&drop' | translate('entity-ts') }}.
+
+Entity escaping in links: {{ 'Foo' | translate('entity-lnk') }}.
Index: tests/test_translations.py
===================================================================
--- a/tests/test_translations.py
+++ b/tests/test_translations.py
@@ -10,17 +10,17 @@
@pytest.fixture(scope='module')
def expect_requests():
return [
('info?key=test_key&json=1', ''),
('supported-languages?key=test_key&json=1', ''),
('add-file?key=test_key&json=1', 'translate.json'),
- ('upload-translation?key=test_key&json=1', 'test_sample'),
+ ('upload-translation?key=test_key&json=1', 'simple'),
('delete-file?key=test_key&json=1', 'translate.json'),
('delete-file?key=test_key&json=1', 'translate.json'),
('delete-directory?key=test_key&json=1', ''),
('delete-directory?key=test_key&json=1', ''),
('export?key=test_key&json=1', ''),
('download/all.zip?key=test_key', ''),
]