Skip to content

Commit

Permalink
feat(TSE-1350): Add origin field to ICE config (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
lookasc authored Nov 28, 2023
1 parent 9071090 commit fd72858
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "django-phrase"
version = "2.0.0"
version = "2.1.0"
authors = [
{ name="Phrase", email="[email protected]" },
]
Expand Down
31 changes: 17 additions & 14 deletions src/phrase/templatetags/phrase_i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,24 @@ def do_block_translate(parser, token):
def phrase_javascript():
if not phrase_settings.PHRASE_ENABLED:
return ""
html = """<script>
window.PHRASEAPP_CONFIG = {
accountId: '%(account_id)s',
projectId: '%(project_id)s',
datacenter: '%(datacenter)s',
autoLowercase :false,
html = """
<script>
window.PHRASEAPP_CONFIG = {
accountId: '%(account_id)s',
projectId: '%(project_id)s',
datacenter: '%(datacenter)s',
autoLowercase: false,
origin: 'django-phrase'
};
(function() {
var phrasejs = document.createElement('script');
phrasejs.type = 'module';
phrasejs.async = true;
phrasejs.src = 'https://d2bgdldl6xit7z.cloudfront.net/latest/ice/index.js'
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phrasejs, s); \
})();
</script>"""
(function() {
var phrasejs = document.createElement('script');
phrasejs.type = 'module';
phrasejs.async = true;
phrasejs.src = 'https://d2bgdldl6xit7z.cloudfront.net/latest/ice/index.js'
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phrasejs, s);
})();
</script>
"""
formatted_html = html % dict(
project_id=phrase_settings.PHRASE_PROJECT_ID,
account_id=phrase_settings.PHRASE_ACCOUNT_ID,
Expand Down
22 changes: 13 additions & 9 deletions tests/test_template_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ def test_empty_template(self):
def test_phrase_javascript(self):
self.assertHTMLEqual(
render_template("{% phrase_javascript %}"),
"""<script>
"""
<script>
window.PHRASEAPP_CONFIG = {
accountId: '',
projectId: '',
autoLowercase :false,
};
datacenter: '',
autoLowercase: false,
origin: 'django-phrase'
};
(function() {
var phrasejs = document.createElement('script');
phrasejs.type = 'module';
phrasejs.async = true;
phrasejs.src = 'https://d2bgdldl6xit7z.cloudfront.net/latest/ice/index.js'
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phrasejs, s); \
var phrasejs = document.createElement('script');
phrasejs.type = 'module';
phrasejs.async = true;
phrasejs.src = 'https://d2bgdldl6xit7z.cloudfront.net/latest/ice/index.js'
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phrasejs, s);
})();
</script>""",
</script>
""",
)

0 comments on commit fd72858

Please sign in to comment.