https://github.com/audreyteles/django-lexpy
Organize your texts and languages in a simple way with short keys.
https://github.com/audreyteles/django-lexpy
Last synced: about 1 month ago
JSON representation
Organize your texts and languages in a simple way with short keys.
- Host: GitHub
- URL: https://github.com/audreyteles/django-lexpy
- Owner: audreyteles
- License: mit
- Created: 2024-10-06T14:14:45.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-11-23T13:36:29.000Z (7 months ago)
- Last Synced: 2025-05-07T16:09:05.951Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 32.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Django Lexpy - v0.1.2-beta

[](https://djangopackages.org/packages/p/django-lexpy/)
This is a package that helps you organize your texts in several languages in a simple way.
## Install
```bash
pip install django-lexpy
```## Configure
### settings.py
```python
INSTALLED_APPS = [
'django_lexpy'
]
```
Check that the desired language is correct:
```python
LANGUAGE_CODE = 'en-us'
```Run your project:
```bash
python manage.py runserver
```---
So a folder with your desired language was created:
```bash
lang
└── en_us
├── __init__.py
└── main.py
```The `main.py` looks like:
```python
messages = {
"message.test": "This is a test message.",
}
```## Load lexpy
Load lexpy in your template and use the tag:
```html
{% load lexpy %}
Title{% lexpy 'message.test' %}
```
The tag consists of the prefix “message.” followed by the short key of the message that has been defined in your message file:
```python
{% lexpy 'message.welcome' %}
```## Organazing
you no longer have to go through your entire project to find your “messages”/texts, centralize them in one place:
```python
# yourproject/lang/en_us/main.pymessages = {
"message.test": "This is a test message.",
"message.welcome": "Welcome to my website.",
"message.help": "Do you need some help?",
}
```## Internationalization and localization
In addition to organizing your texts, you can simplify the translations without 'strings as keys' in `.po` file:
```python
# path/to/python/file.py:123
msgid "Welcome to my site."
msgstr "Bem-vindo ao meu site"
```Now you have short keys:
```python
# yourproject/lang/en_us/main.pymessages = {
"message.test": "This is a test message.",
"message.welcome": "Welcome to my website.",
}
```
---
Another language:```python
# yourproject/lang/pt_BR/main.pymessages = {
"message.test": "Isso é uma mensagem de teste.",
"message.welcome": "Bem-vindo ao meu site.",
}
```## Replacing Fields in Messages
You can also define fields in your message and replace them with dynamic values.
```python
# yourproject/lang/en_us/main.py
messages = {
"message.welcome": "Hi {name}, welcome to my website.",
}
```
And in your template you can:```html
{% load lexpy %}
...
{% lexpy 'message.welcome' name="Foobar" %}
...
```Then you can see it on your website:
```
Hi Foobar, welcome to my website.
```> **Unnamed fields are also supported**
>
> ```python
> #yourproject/lang/en_us/main.py
> messages = {
> "message.welcome": "Hi {}, welcome to my website.",
> }
> ```
> ```html
> {% load lexpy %}
> ...
> {% lexpy 'message.welcome' "Foobar" %}
> ...
> ```