-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added the `id` and `method` arguments from the `read` method of the `DirecrusResponse` class to the cache key - Changed the translation related methods and the `parse_translations` function - Added translation examples and documentation - Minor code changes
- Loading branch information
1 parent
8f2891b
commit 1885c91
Showing
8 changed files
with
195 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Custom Translations | ||
|
||
We provide the `get_translations` and `create_translations` methods of the `Directus` class client | ||
for you to retrieve and create new translation records on the `Directus` backend. | ||
|
||
## Retrieve Translations | ||
|
||
Retrieving translation records | ||
|
||
```python | ||
... | ||
# A list of translation records in dictionary format | ||
translations = await directus.get_translations() | ||
|
||
# A dictionary of translation records grouped by the `key` field | ||
# { | ||
# "<key>": { | ||
# "<language>": "<value>" | ||
# } | ||
# } | ||
translations = await directus.get_translations(clean=True) | ||
... | ||
``` | ||
|
||
> Note: The automatic retrieval of all Directus translation records is supported by the `async_init` function | ||
> when the `load_translations` argument is set to `True`. | ||
> You can access the translations from the `pydirectus.translations` global. The global is in `clean` format. | ||
## Create Translations | ||
|
||
Creating a new translation record | ||
|
||
```python | ||
... | ||
# Register a translation record for the given values (language: 'en-GB') | ||
directus_response = await directus.create_translations("some") | ||
|
||
# Register a translation record for the given values with specific language | ||
directus_response = await directus.create_translations(tuple(["some", "el-GR"])) | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import asyncio | ||
|
||
from dotenv import dotenv_values | ||
|
||
from py_directus import DirectusUser, Directus | ||
|
||
|
||
config = dotenv_values(".env") | ||
|
||
|
||
async def main(): | ||
# directus = await Directus.create(config["DIRECTUS_URL"], email=config["DIRECTUS_EMAIL"], password=config["DIRECTUS_PASSWORD"]) | ||
directus = await Directus(config["DIRECTUS_URL"], email=config["DIRECTUS_EMAIL"], password=config["DIRECTUS_PASSWORD"]) | ||
|
||
# Retrieving translation records | ||
translations = await directus.get_translations() | ||
print(f"TRANSLATIONS: {translations}") | ||
|
||
# Creating a new translation record | ||
directus_response = await directus.create_translations(tuple(["some", "el-GR"])) | ||
print(f"DIRECTUS RESPONSE: {directus_response}") | ||
|
||
# Retrieving translation records again | ||
translations = await directus.get_translations() | ||
print(f"TRANSLATIONS (AGAIN): {translations}") | ||
|
||
# Logout | ||
await directus.logout() | ||
|
||
# Manually close connection | ||
await directus.close_connection() | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.