Skip to content

Commit

Permalink
Version 2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bodrovis committed May 15, 2024
1 parent 7102863 commit 32dc941
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 138 deletions.
16 changes: 16 additions & 0 deletions docs/additional_info/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
Changelog
=========

2.3.0 (15-May-2024)
-------------------

* Add support for `cursor pagination <https://python-lokalise-api.readthedocs.io/en/latest/api/getting-started#cursor-pagination>`_ for List keys and List translation endpoints:

.. code-block:: python
keys = client.keys(YOUR_PROJECT_ID, {
"limit": 2, # The number of items to fetch. Optional, default is 100
"pagination": "cursor",
"cursor": "eyIxIjo0NDU5NjA2MX0=" # The starting cursor. Optional, string
})
keys.has_next_cursor() # => True or False
keys.next_cursor # => String or None
2.2.0 (17-Apr-2024)
-------------------

Expand Down
21 changes: 21 additions & 0 deletions docs/api/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@ For example:
projects.has_next_page() # => False, no more pages available
projects.has_prev_page() # => True, there is a previous page available
Cursor pagination
-----------------

The `List Keys <https://developers.lokalise.com/reference/list-all-keys>`_ and `List Translations <https://developers.lokalise.com/reference/list-all-translations>`_ endpoints support cursor pagination, which is recommended for its faster performance compared to traditional "offset" pagination. By default, "offset" pagination is used, so you must explicitly set `pagination` to `"cursor"` to use cursor pagination.

.. code-block:: python
keys = client.keys(YOUR_PROJECT_ID, {
"limit": 2, # The number of items to fetch. Optional, default is 100
"pagination": "cursor",
"cursor": "eyIxIjo0NDU5NjA2MX0=" # The starting cursor. Optional, string
})
After retrieving data from the Lokalise API, you can check for the availability of the next cursor and proceed accordingly:

.. code-block:: python
keys.has_next_cursor() # => True or False
keys.next_cursor # => String or None
Branching
---------

Expand Down
9 changes: 3 additions & 6 deletions docs/api/keys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ Fetch all keys
:param dict params: Request parameters
:return: Collection of keys

Please note that this endpoint should not be treated as a content delivery network
for your language files. It means that you should not perform a new request to this endpoint
with every website/app visitor. Instead, fetch this endpoint from time to time,
store the result locally and serve your visitors with static files/your database content.
Alternatively, you may use our Amazon S3/Google CloudStorage integrations in
automatically upload your language files to a bucket of your choice.
This endpoint also supports cursor pagination which is now a recommended approach, especially for fetching large amounts of data. Please `learn more in the docs <https://python-lokalise-api.readthedocs.io/en/latest/api/getting-started#cursor-pagination>`_.

Please note that this endpoint should not be treated as a content delivery network for your language files. It means that you should not perform a new request to this endpoint with every website/app visitor. Instead, fetch this endpoint from time to time, store the result locally and serve your visitors with static files/your database content. Alternatively, you may use our Amazon S3/Google CloudStorage integrations in automatically upload your language files to a bucket of your choice.

Example:

Expand Down
2 changes: 2 additions & 0 deletions docs/api/translations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Example:
})
translations.items[0].translation_id # => 220681321
This endpoint also supports cursor pagination which is now a recommended approach, especially for fetching large amounts of data. Please `learn more in the docs <https://python-lokalise-api.readthedocs.io/en/latest/api/getting-started#cursor-pagination>`_.

Fetch a translation
-------------------

Expand Down
8 changes: 8 additions & 0 deletions lokalise/collections/base_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self, raw_data: Dict[str, Any]) -> None:
self.page_count = int(pagination.get("x-pagination-page-count", 0))
self.limit = int(pagination.get("x-pagination-limit", 0))
self.current_page = int(pagination.get("x-pagination-page", 0))
self.next_cursor = pagination.get("x-pagination-next-cursor", None)

def is_last_page(self) -> bool:
"""Checks whether the current collection set is the last page.
Expand Down Expand Up @@ -85,6 +86,13 @@ def has_prev_page(self) -> bool:
"""
return self.current_page > 1

def has_next_cursor(self) -> bool:
"""Checks whether the current collection set has the next cursor.
:rtype: bool
"""
return self.next_cursor is not None

def __extract_common_attrs(self, raw_data: Dict) -> None:
"""Fetches common data from the response and sets the
corresponding attributes.
Expand Down
3 changes: 2 additions & 1 deletion lokalise/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"x-pagination-total-count",
"x-pagination-page-count",
"x-pagination-limit",
"x-pagination-page"
"x-pagination-page",
"x-pagination-next-cursor"
]


Expand Down
Loading

0 comments on commit 32dc941

Please sign in to comment.