You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+96-77
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Lisan - ልሳን
2
2
3
-
**means**: A language
3
+
**means**: A language in Amharic (Ethiopian Language)
4
4
5
5
**Lisan** is a Django package that simplifies the process of adding translation support to model fields in Django projects. With `Lisan`, you can easily manage multilingual content within your Django models, API, and admin interface.
6
6
@@ -10,6 +10,27 @@
10
10
-**Admin Integration:** Seamlessly manage translations through the Django admin interface.
11
11
-**Fallback Mechanism:** Fallback to the default language if a translation is not available.
12
12
-**Dynamic Getter Methods:** Automatically generate methods to access translated fields.
13
+
-**Pluggable Translation Services:** Support for external services like Google Translate to automatically translate content.
14
+
-**Customizable Admin Display:** Configure how translations are displayed in the Django admin interface.
15
+
-**Flexible Field Types:** Add translation support for various field types like `CharField`, `TextField`, and `JSONField`.
16
+
17
+
## Table of Contents
18
+
19
+
-[Installation](#installation)
20
+
-[Lisan Settings](#lisan-settings)
21
+
-[Usage](#usage)
22
+
-[Adding Translation Support to Models](#1-adding-translation-support-to-models)
23
+
-[Managing Translations in Django Admin](#2-managing-translations-in-django-admin)
24
+
-[Accessing Translations in Code](#3-accessing-translations-in-code)
25
+
-[API Usage](#api-usage)
26
+
-[Creating a Snippet with Translations](#1-creating-a-snippet-with-translations)
27
+
-[Retrieving a Snippet with a Specific Translation](#2-retrieving-a-snippet-with-a-specific-translation)
28
+
-[Handling User Preferences for Translations](#handling-user-preferences-for-translations)
#### Getting a Translation with Fallback and Auto-Translate
117
130
118
-
You can retrieve translations with a fallback mechanism. For example, if a translation in Amharic is not available, it will default to the base language (e.g., English).
131
+
You can retrieve translations with a fallback mechanism or even auto-translate content using an external service.
### 2. Retrieving a Snippet with a Specific Translation
175
166
176
-
To retrieve a snippet in a specific language, send a `GET` request with the appropriate `Accept-Language` header to specify the desired language (e.g., `am` for Amharic, `or` for Oromo).
167
+
To retrieve a snippet in a specific language, send a `GET` request with the appropriate `Accept-Language` header to specify the desired language (e.g., `am` for Amharic).
177
168
178
169
**Request Example**:
179
170
@@ -190,57 +181,85 @@ The response will return the snippet information in the requested language if av
The `Lisan` package supports pluggable translation services, allowing you to integrate with third-party APIs like Google Translate for automatic translations. You can configure this via the `LISAN_DEFAULT_TRANSLATION_SERVICE` setting.
209
+
210
+
### Creating Custom Translation Services
216
211
217
-
Define your `SnippetViewSet` and make sure to pass the request to the serializer context for handling language-specific responses.
212
+
You can create custom translation services by implementing the `BaseTranslationService` class.
213
+
214
+
Example using Google Translate:
218
215
219
216
```python
220
-
from rest_framework import viewsets
221
-
from .models import Snippet
222
-
from .serializers import SnippetSerializer
223
-
224
-
classSnippetViewSet(viewsets.ModelViewSet):
225
-
queryset = Snippet.objects.all()
226
-
serializer_class = SnippetSerializer
227
-
228
-
defget_serializer_context(self):
229
-
"""
230
-
Adds custom context to the serializer.
231
-
"""
232
-
context =super().get_serializer_context()
233
-
context['request'] =self.request # Pass request context for translation handling
234
-
return context
217
+
# google_translate_service.py
218
+
from googletrans import Translator
219
+
from lisan.translation_services import BaseTranslationService
This `README.md` provides a comprehensive overview of the `lisan` package, including settings, installation, configuration, and usage instructions. It covers how to create and retrieve translations for Django models and includes API examples for managing translated content.
258
+
This testing structure ensures that your translations work as expected, using both direct translations and fallback mechanisms when translations are unavailable.
240
259
241
260
## Contributing
242
261
243
-
If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request on GitHub.
262
+
If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request on GitHub. Contributions are always welcome.
0 commit comments