Skip to content

Commit

Permalink
Turn in context translation into a plugin.
Browse files Browse the repository at this point in the history
Make it unsafe-inline compliant.
  • Loading branch information
rtibbles committed Nov 15, 2024
1 parent 3596a71 commit 0644b18
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 26 deletions.
1 change: 1 addition & 0 deletions kolibri/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
INTERNAL_PLUGINS = [
"kolibri.plugins.app",
"kolibri.plugins.coach",
"kolibri.plugins.context_translation",
"kolibri.plugins.default_theme",
"kolibri.plugins.demo_server",
"kolibri.plugins.device",
Expand Down
7 changes: 0 additions & 7 deletions kolibri/core/templates/kolibri/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
<meta name="google" content="notranslate">
{% theme_favicon %}
<title>{% site_title %}</title>
{% if LANGUAGE_CODE == "ach-ug" %}
<script type="text/javascript">
var _jipt = [];
_jipt.push(['project', 'kolibri']);
</script>
<script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>
{% endif %}
{% frontend_base_head_markup %}
</head>
<body>
Expand Down
19 changes: 0 additions & 19 deletions kolibri/deployment/default/settings/translation.py

This file was deleted.

Empty file.
31 changes: 31 additions & 0 deletions kolibri/plugins/context_translation/kolibri_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.templatetags.static import static
from django.utils.safestring import mark_safe

from kolibri.core.hooks import FrontEndBaseHeadHook
from kolibri.plugins import KolibriPluginBase
from kolibri.plugins.hooks import register_hook


class ContextTranslationPlugin(KolibriPluginBase):
"""
A plugin to enable support for translating the user interface of Kolibri
using Crowdin's in-context translation feature.
"""

kolibri_option_defaults = "option_defaults"
django_settings = "settings"


@register_hook
class JIPTHeadHook(FrontEndBaseHeadHook):
@property
def head_html(self):
js_url = static("assets/context_translation/jipt.js")
return mark_safe(
"\n".join(
[
f"""<script type="text/javascript" src="{js_url}"></script>""",
"""<script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>""",
]
)
)
5 changes: 5 additions & 0 deletions kolibri/plugins/context_translation/option_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
option_defaults = {
"Deployment": {
"LANGUAGES": "ach-ug",
}
}
12 changes: 12 additions & 0 deletions kolibri/plugins/context_translation/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.conf import locale

ACH_LANG_INFO = {
"ach-ug": {
"bidi": False,
"code": "ach-ug",
"name": "In-context translation",
"name_local": "Language Name",
}
}

locale.LANG_INFO.update(ACH_LANG_INFO)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var _jipt = [];
_jipt.push(['project', 'kolibri']);

0 comments on commit 0644b18

Please sign in to comment.