Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2461 from joetsoi/itranslation-interface
add ITranslations interface
- Loading branch information
Showing
17 changed files
with
324 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[extractors] | ||
ckan = ckan.lib.extract:extract_ckan | ||
|
||
[ckan: **/templates/**.html] | ||
encoding = utf-8 |
23 changes: 23 additions & 0 deletions
23
ckanext/example_itranslation/i18n/ckanext-example_itranslation.pot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Translations template for PROJECT. | ||
# Copyright (C) 2015 ORGANIZATION | ||
# This file is distributed under the same license as the PROJECT project. | ||
# FIRST AUTHOR <EMAIL@ADDRESS>, 2015. | ||
# | ||
#, fuzzy | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PROJECT VERSION\n" | ||
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" | ||
"POT-Creation-Date: 2015-06-14 21:14+0100\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <LL@li.org>\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=utf-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Generated-By: Babel 0.9.6\n" | ||
|
||
#: templates/home/index.html:4 | ||
msgid "This is an untranslated string" | ||
msgstr "" | ||
|
Binary file added
BIN
+542 Bytes
ckanext/example_itranslation/i18n/en/LC_MESSAGES/ckanext-example_itranslation.mo
Binary file not shown.
25 changes: 25 additions & 0 deletions
25
ckanext/example_itranslation/i18n/en/LC_MESSAGES/ckanext-example_itranslation.po
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# English translations for PROJECT. | ||
# Copyright (C) 2015 ORGANIZATION | ||
# This file is distributed under the same license as the PROJECT project. | ||
# FIRST AUTHOR <EMAIL@ADDRESS>, 2015. | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PROJECT VERSION\n" | ||
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" | ||
"POT-Creation-Date: 2015-06-14 21:14+0100\n" | ||
"PO-Revision-Date: 2015-06-16 15:57+0100\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: en <LL@li.org>\n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1)\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=utf-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Generated-By: Babel 0.9.6\n" | ||
|
||
#: templates/home/index.html:4 | ||
msgid "This is an untranslated string" | ||
msgstr "" | ||
|
||
msgid "Register" | ||
msgstr "Replaced" |
25 changes: 25 additions & 0 deletions
25
ckanext/example_itranslation/i18n/en/LC_MESSAGES/ckanext-example_translation.po
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# English translations for PROJECT. | ||
# Copyright (C) 2015 ORGANIZATION | ||
# This file is distributed under the same license as the PROJECT project. | ||
# FIRST AUTHOR <EMAIL@ADDRESS>, 2015. | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PROJECT VERSION\n" | ||
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" | ||
"POT-Creation-Date: 2015-06-14 21:14+0100\n" | ||
"PO-Revision-Date: 2015-06-16 15:57+0100\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: en <LL@li.org>\n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1)\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=utf-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Generated-By: Babel 0.9.6\n" | ||
|
||
#: templates/home/index.html:4 | ||
msgid "This is an untranslated string" | ||
msgstr "" | ||
|
||
msgid "Register" | ||
msgstr "Replaced" |
Binary file added
BIN
+559 Bytes
ckanext/example_itranslation/i18n/fr/LC_MESSAGES/ckanext-example_itranslation.mo
Binary file not shown.
21 changes: 21 additions & 0 deletions
21
ckanext/example_itranslation/i18n/fr/LC_MESSAGES/ckanext-example_itranslation.po
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This is an example translations file | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PROJECT VERSION\n" | ||
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" | ||
"POT-Creation-Date: 2015-06-14 21:14+0100\n" | ||
"PO-Revision-Date: 2015-06-14 21:15+0100\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: fr <LL@li.org>\n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1)\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=utf-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Generated-By: Babel 0.9.6\n" | ||
|
||
msgid "This is an untranslated string" | ||
msgstr "This is a itranslated string" | ||
|
||
msgid "Log in" | ||
msgstr "Overwritten string in ckan.mo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from ckan import plugins | ||
from ckan.plugins import toolkit | ||
from ckan.lib.plugins import DefaultTranslation | ||
|
||
|
||
class ExampleITranslationPlugin(plugins.SingletonPlugin, DefaultTranslation): | ||
plugins.implements(plugins.ITranslation) | ||
plugins.implements(plugins.IConfigurer) | ||
|
||
def update_config(self, config): | ||
toolkit.add_template_directory(config, 'templates') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% ckan_extends %} | ||
|
||
{% block primary_content %} | ||
{% trans %}This is an untranslated string{% endtrans %} | ||
{% endblock %} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from ckan import plugins | ||
from ckan.tests import helpers | ||
|
||
from nose.tools import assert_true, assert_false | ||
|
||
|
||
class TestExampleITranslationPlugin(helpers.FunctionalTestBase): | ||
@classmethod | ||
def setup_class(cls): | ||
super(TestExampleITranslationPlugin, cls).setup_class() | ||
plugins.load('example_itranslation') | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
plugins.unload('example_itranslation') | ||
super(TestExampleITranslationPlugin, cls).teardown_class() | ||
|
||
def test_translated_string_in_extensions_templates(self): | ||
app = self._get_test_app() | ||
response = app.get( | ||
url=plugins.toolkit.url_for(controller='home', action='index', | ||
locale='fr'), | ||
) | ||
assert_true('This is a itranslated string' in response.body) | ||
assert_false('This is an untranslated string' in response.body) | ||
|
||
# double check the untranslated strings | ||
response = app.get( | ||
url=plugins.toolkit.url_for(controller='home', action='index'), | ||
) | ||
assert_true('This is an untranslated string' in response.body) | ||
assert_false('This is a itranslated string' in response.body) | ||
|
||
# check that we have only overwritten 'fr' | ||
response = app.get( | ||
url=plugins.toolkit.url_for(controller='home', action='index', | ||
locale='es'), | ||
) | ||
assert_true('This is an untranslated string' in response.body) | ||
assert_false('This is a itranslated string' in response.body) | ||
|
||
def test_translated_string_in_core_templates(self): | ||
app = self._get_test_app() | ||
response = app.get( | ||
url=plugins.toolkit.url_for(controller='home', action='index', | ||
locale='fr'), | ||
) | ||
assert_true('Overwritten string in ckan.mo' in response.body) | ||
assert_false('Connexion' in response.body) | ||
|
||
# double check the untranslated strings | ||
response = app.get( | ||
url=plugins.toolkit.url_for(controller='home', action='index'), | ||
) | ||
assert_true('Log in' in response.body) | ||
assert_false('Overwritten string in ckan.mo' in response.body) | ||
|
||
# check that we have only overwritten 'fr' | ||
response = app.get( | ||
url=plugins.toolkit.url_for(controller='home', action='index', | ||
locale='de'), | ||
) | ||
assert_true('Einloggen' in response.body) | ||
assert_false('Overwritten string in ckan.mo' in response.body) | ||
|
||
def test_english_translation_replaces_default_english_string(self): | ||
app = self._get_test_app() | ||
response = app.get( | ||
url=plugins.toolkit.url_for(controller='home', action='index'), | ||
) | ||
assert_true('Replaced' in response.body) | ||
assert_false('Register' in response.body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.