Skip to content

Commit

Permalink
Merge pull request #43 from COEXCZ/fixes_upgrades
Browse files Browse the repository at this point in the history
Fixes upgrades
  • Loading branch information
Krakenus authored Feb 21, 2022
2 parents 4af5336 + 9a7f3ba commit eea73a3
Show file tree
Hide file tree
Showing 14 changed files with 390 additions and 259 deletions.
50 changes: 42 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,36 @@ README
:target: http://django-translation-manager.readthedocs.org/en/master/
:alt: Read the docs

Django app for managing translations from admin.

Using this django app you can easily manage and publish translations from django admin without editing .po files manually.

Install package
===============

* use pip to get the package
::
pip install django-translation-manager

::

pip install django-translation-manager

* add 'translation_manager' to settings.py: INSTALLED_APPS

* add variables from Translation Manager's defaults.py to your settings.py

* add post_save signal to restart webserver:
::
from translation_manager.signals import post_save as translation_post_save
* add post_publish signal to restart webserver:

::

from translation_manager.signals import post_publish as translation_post_publish
translation_post_save.connect(restart_server, sender=None)
translation_post_publish.connect(restart_server, sender=None)


Supported versions of django
============================

We support all django versions greater or equal 2.0.2.
We support all django versions greater or equal 2.2.20.


Using with django-rq
Expand All @@ -49,15 +57,21 @@ Using with django-rq
We support asynchronous translation processing by django-rq.

Set translation processing method in settings.py

::

TRANSLATIONS_PROCESSING_METHOD = 'async_django_rq'

Inslall django-rq

::

pip install django_rq

Install django-redis-cache

::

pip install django-redis-cache

We tested it with django-rq 2.1.0 and django-redis-cache 2.1.0
Expand All @@ -70,31 +84,43 @@ Using with Angularjs
We support translation for Angularjs client-site app via REST api

Enable api communication in settings

::

TRANSLATIONS_ENABLE_API_COMMUNICATION = True

Enable searching for translation strings in Angularjs source codes

::

TRANSLATIONS_ENABLE_API_ANGULAR_JS = True

Set path to Anguraljs source code files.

The important thing is that it must be in the same file system.

Configuration example:

::

TRANSLATIONS_API_CLIENT_APP_SRC_PATH = '/var/srv/front/src'
Add regex for matching translation strings in client app src files:

::
TRANSLATIONS_API_TRANSLATION_STRINGS_REGEX = r''

TRANSLATIONS_API_TRANSLATION_STRINGS_REGEX = r''

Inslall django REST framewrok

::

pip install djangorestframework

Add translation manager urls in your url patterns

::

from translation_manager import urls as translation_urls

urlpatterns.append(url(r'^translations/', include(translation_urls)))
Expand All @@ -104,18 +130,24 @@ We tested it with django-rest-framework 3.4.6
SyncDB
======
use syncdb

::

./manage.py syncdb

or migrate:

::

./manage.py migrate


Load strings from po files
==========================
via python shell

::

./manage.py shell
from translation_manager.manager import Manager
Expand All @@ -128,7 +160,9 @@ Add link to translation admin
=============================

this is optional in case you need it

::

{% url admin:translation_manager_translationentry_changelist %}


Expand Down
8 changes: 4 additions & 4 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ Configuratuion
TRANSLATIONS_HINT_LANGUAGE = ''
3) add post_save signal to restart the server:
3) add post_publish signal to restart the server:

.. code-block:: python
from translation_manager.signals import post_save as translation_post_save
from translation_manager.signals import post_publish as translation_post_publish
translation_post_save.connect(restart_server, sender=None)
translation_post_publish.connect(restart_server, sender=None)
4) use syncdb or migrate
Expand Down Expand Up @@ -92,4 +92,4 @@ Configuratuion
{% url admin:translation_manager_translationentry_changelist %}
You should now have your Django Translation Manager up and running
You should now have your Django Translation Manager up and running
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ django>=2.2.20
djangorestframework>=3.7.1
requests>=2.18.4
django-rq==2.4.1
django-redis-cache==3.0.0
2 changes: 1 addition & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
'PORT': '',
}
}
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
PACKAGE = "translation_manager"
NAME = "django-translation-manager"
DESCRIPTION = "Django app for managing translations from admin"
AUTHOR = "Pavel Císař, Martin Kubát, Mikuláš Mrva, Jakub Ladra, Michal Kašpar, Jan Češpivo - COEX s.r.o (http://www.coex.cz)"
AUTHOR = "Pavel Císař, Martin Kubát, Mikuláš Mrva, Jakub Ladra, Michal Kašpar, Jan Češpivo, Milan Vlasák - COEX s.r.o (http://www.coex.cz)"
AUTHOR_EMAIL = "[email protected]"
URL = "https://github.com/COEXCZ/django-translation-manager"
VERSION = '1.1.1'
LICENSE = "Mozilla Public License 2.0 (MPL 2.0)"

with open('README.rst') as readme:
LONG_DESCRIPTION = readme.read()

setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
long_description_content_type='text/x-rst',
author=AUTHOR,
author_email=AUTHOR_EMAIL,
license=LICENSE,
Expand Down
22 changes: 0 additions & 22 deletions tests/api_tests.py

This file was deleted.

24 changes: 24 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.test import override_settings
from rest_framework.test import APITestCase

from translation_manager.models import TranslationEntry
from translation_manager import defaults


@override_settings(TRANSLATIONS_ENABLE_API_COMMUNICATION=True)
class TranslationTests(APITestCase):

def setUp(self):
TranslationEntry.objects.create(language='cs', original='admin-test', translation='test in admin',
is_published=True)
TranslationEntry.objects.create(language='cs', original='test', translation='other test', is_published=True)

def test_get_translations(self):
defaults.TRANSLATIONS_API_QUERYSET_FORCE_FILTERS = []
response = self.client.get('/translations/cs/')
self.assertTrue(len(response.data) == 2)

def test_force_filter(self):
defaults.TRANSLATIONS_API_QUERYSET_FORCE_FILTERS = ['admin-']
response = self.client.get('/translations/cs/')
self.assertTrue(len(response.data) == 1)
1 change: 1 addition & 0 deletions translation_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'translation_manager.apps.TranslationManagerConfig'
4 changes: 3 additions & 1 deletion translation_manager/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from .manager import Manager
from .models import TranslationEntry, TranslationBackup, RemoteTranslationEntry, ProxyTranslationEntry
from .signals import post_save
from .signals import post_save, post_publish
from .widgets import add_styles
from .utils import filter_queryset
from .settings import get_settings
Expand Down Expand Up @@ -147,6 +147,8 @@ def compile_translations_view(self, request):
manager = Manager()
for language, language_name in settings.LANGUAGES:
manager.update_po_from_db(lang=language)
post_publish.send(sender=None, request=request)
# DEPRECATED
post_save.send(sender=None, request=request)

self.message_user(request, _("admin-translation_manager-translations_compiled"))
Expand Down
13 changes: 13 additions & 0 deletions translation_manager/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os

from django.apps import AppConfig
from django.conf import settings


class TranslationManagerConfig(AppConfig):
name = 'translation_manager'
default_auto_field = "django.db.models.BigAutoField"

def ready(self):
for path in settings.LOCALE_PATHS:
os.makedirs(path, exist_ok=True)
Loading

0 comments on commit eea73a3

Please sign in to comment.