Skip to main content

Django module for multi languages management

Project description

django-text-manager - no more problems with texts for bots, websites, etc.

v0.1.1 - Basic functionality with api

v0.1.5 - Fixes of some bugs, new variable TEXT_MANAGER_DEFAULT_API_LANGUAGE in settings

Documentation

settings.py

INSTALLED_APPS = [
    ...
    "textmanager",
    ...
]

TEXT_MANAGER_EXTRA_LANGUAGES = ['uk'] # Optional, default languages when u add new text
TEXT_MANAGER_AVAILABLE_LANGUAGES = ['ru', 'uk', 'en'] # Optional, list of availbale languages in project 
TEXT_MANAGER_DEFAULT_API_LANGUAGE = 'en' # Optional, default language for api, fr. en to render english text if 'language' row in empty
TEXT_MANAGER_PERMISSION_CLASSES = ['rest_framework.permissions.IsAuthenticated',] # Optional, permission classes for api

How to add languages? (load in database 107 different languages)

python3 manage.py migrate
python3 manage.py loadlanguages

Usage

from textmanager.models import Text

text = Text.objects.get(unique_id='test').render(language="en", params={
    "var1": "friend"
})
print(text)

# >>> Hello, friend! - text in db: Hello, {{ var1 }}!

API

urls.py

from django.urls import path, include

urlpatterns = [
    path("textmanager/", include("textmanager.urls")),
]

how to send request?

import requests
import json
resp = requests.post(url="http://0.0.0.0:1234/textmanager/text/", json={
    "id": 5, # id or unique_id is required
    # or
    "unique_id": "test",

    "language": "en", # optional, default=None
    "render_with_jinja": False, # optional, default=true
    "params": {} # optional, default={}
}, headers={"Authorization": "Token ****"})
data = json.loads(resp.text)
print(data)

# >>> {'text': 'Hello, {{ var1 }}!'} # if language specified
# >>> {
#    'texts': [
#        {
#            'language': {
#                'alpha2': 'en', 
#                'alpha3_b': 'eng', 
#                'english_name': 'English', 
#                'language_name': 'English', 
#                'flag': '🇬🇧'
#            }, 
#            'text': 'Hello, {{ var1 }}!'
#        }, ...
#    ]
# }# if language is not specified

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_text_manager-0.1.7.tar.gz (15.4 kB view details)

Uploaded Source

File details

Details for the file django_text_manager-0.1.7.tar.gz.

File metadata

  • Download URL: django_text_manager-0.1.7.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for django_text_manager-0.1.7.tar.gz
Algorithm Hash digest
SHA256 83cc7c9c8ed009266d0a63d5167e7a76a2fca38c4fe5aab42dca4efa65b9c4bf
MD5 ca11cf8418bb6b77f4250865b6d9161d
BLAKE2b-256 9d08b79012ab8ce0a46f8db702471b65e8302e588dded7743f1bd354bf7fc8d0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page