Skip to content

Commit

Permalink
internalization issues
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpoi committed Oct 23, 2024
1 parent a60a4e3 commit 5fa07c3
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 9 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ Add `CKEDITOR_UPLOAD_PATH`. This path will be used to store ckeditor uploaded im
CKEDITOR_UPLOAD_PATH = 'ckeditor_uploads'
```

To your main `urls.py` add `ckeditor_uploader` urls:

```python
urlpatterns = [
...,
path('ckeditor/', include('ckeditor_uploader.urls')),
]
```


Add `STATIC_URL` and `STATIC_ROOT`

```python
Expand Down Expand Up @@ -164,6 +174,8 @@ SENDMAIL = {

You can use relative path from your `templates` folder or absolute file path.

- Specify list of translation languages in `settings.LANGUAGES` or disable internalization by setting `settings.USE_I18N` to `False`.

- Open your admin interface and create a new EmailMergeModel instance:
- Enter name. This will be used as identifier for your template and click “Save and continue editing”.
- Select Base File which you have created.
Expand Down
2 changes: 1 addition & 1 deletion demoapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@

TIME_ZONE = "UTC"

USE_I18N = True
USE_I18N = False

USE_L10N = True

Expand Down
70 changes: 70 additions & 0 deletions demoapp/templates/email/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{% load sendmail %}

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<title></title>

<style type="text/css">
</style>
</head>
<body style="margin:0; padding:0; background-color:#F2F2F2;">
<center>
<table width="640" cellpadding="0" cellspacing="0" border="0" class="wrapper" bgcolor="#FFFFFF">
<tr>
<td height="10" style="font-size:10px; line-height:10px;">&nbsp;</td>
</tr>
<tr>
<td align="center" valign="top">

<table width="600" cellpadding="0" cellspacing="0" border="0" class="container" style="background-color: lightblue">
<tr>
<td align="right" valign="top">
<img src="{% inline_image 'images/logo.png' %}" width="100" height="100" />
</td>
<td align="center" valign="top">
{% placeholder 'header' %}
</td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center" valign="top">
<p>Dear
{% with gender=recipient.gender %}
{% if gender == 'male' %}
Mr.
{% elif gender == 'female' %}
Ms.
{% else %}
Human
{% endif %}
{% endwith %}
{% placeholder 'name' %}
</p>
{% placeholder 'main' %}
</td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color: grey">
<tr>
<td align="center" valign="top">
{% placeholder 'footer' %}
</td>
</tr>
</table>


</td>
</tr>
<tr>
<td height="10" style="font-size:10px; line-height:10px;">&nbsp;</td>
</tr>
</table>
</center>
</body>
</html>
2 changes: 1 addition & 1 deletion demoapp/tests/test_01_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def test_internalization(caplog, template):
recipients=[en_recipient, de_recipient, ua_recipient, nullable_recipient],
template=template)

assert 'Language "ua" is not found in LANGUAGES configuration.' in caplog.text
assert 'Language "ua" is not found in LANGUAGES configuration' in caplog.text

assert len(emails) == 4
assert emails[0].language == 'en'
Expand Down
1 change: 1 addition & 0 deletions demoapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

urlpatterns = [
path('admin/', admin.site.urls),
path('ckeditor/', include('ckeditor_uploader.urls')),
]

if settings.DEBUG:
Expand Down
9 changes: 9 additions & 0 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ Add ``CKEDITOR_UPLOAD_PATH``. This path will be used to store ckeditor uploaded
CKEDITOR_UPLOAD_PATH = 'ckeditor_uploads'
To your main ``urls.py`` add ``ckeditor_uploader`` urls.

.. code-block::
urlpatterns = [
...
path('ckeditor/', include('ckeditor_uploader.urls')),
]
Add ``STATIC_URL`` and ``STATIC_ROOT``

.. code-block::
Expand Down
4 changes: 3 additions & 1 deletion docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ If you want to use templates:
</body>
</html>
Register your template in ``settings.py``:
- Register your template in ``settings.py``:

.. code-block:: python
Expand All @@ -48,6 +48,8 @@ Register your template in ``settings.py``:
You can use relative path from your ``templates`` folder or absolute file path.

- Specify list of translation languages in ``settings.LANGUAGES`` or disable internalization by setting ``settings.USE_I18N`` to ``False``.

- Open your admin interface and create a new EmailMergeModel instance:
- Enter name. This will be used as identifier for your template and click "Save and continue editing".
- Select Base File which you have created.
Expand Down
6 changes: 6 additions & 0 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ Multilingual Templates

In sendmail you can create and send templates in multiple languages. For this simply edit your ``settings.py``:

Verify that internalization is enabled:

.. code-block:: python
USE_I18N = True
Default templates language can be changed in ``settings.LANGUAGE_CODE``

.. code-block:: python
Expand Down
2 changes: 1 addition & 1 deletion sendmail/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class EmailTemplateAdmin(admin.ModelAdmin):
(None, {'fields': ('name', 'description', 'base_file', 'extra_recipients')}),
# (_('Default Content'), {'fields': ('subject', 'content')}),
]
inlines = (EmailTemplateInline, EmailContentInline) if settings.USE_I18N else (EmailContentInline,)
inlines = (EmailTemplateInline, EmailContentInline)
formfield_overrides = {models.CharField: {'widget': SubjectField}}

filter_horizontal = ('extra_recipients',)
Expand Down
1 change: 1 addition & 0 deletions sendmail/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ def save(self, *args, **kwargs):
)

placeholder_names = process_template(self.base_file)
print(placeholder_names)

existing_placeholders = set(
self.contents.filter(base_file=self.base_file).values_list('placeholder_name',
Expand Down
7 changes: 5 additions & 2 deletions sendmail/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ def get_config():


def get_languages_list():
lang_conf = getattr(settings, 'LANGUAGES', [])
return [lang[0] for lang in lang_conf]
if settings.USE_I18N:
lang_conf = getattr(settings, 'LANGUAGES', [])
return [lang[0] for lang in lang_conf]
else:
return [get_default_language(),]


def get_default_language():
Expand Down
2 changes: 1 addition & 1 deletion sendmail/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def get_language_from_code(code, log=True) -> str:
else:
if code not in get_languages_list():
if log:
logger.warning(f'Language "{code}" is not found in LANGUAGES configuration.')
logger.warning(f'Language "{code}" is not found in LANGUAGES configuration or I18N is disabled.')
code = get_default_language()

return code
Expand Down
2 changes: 1 addition & 1 deletion sendmail/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4, 0, 2
4, 0, 3
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
zip_safe=False,
include_package_data=True,
package_data={'': ['README.md']},
install_requires=['Django', 'django-ckeditor', 'lxml', 'nh3'],
install_requires=['Django>=4', 'django-ckeditor=>6', 'lxml=>5', 'nh3'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
Expand Down

0 comments on commit 5fa07c3

Please sign in to comment.