-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathclient.py
More file actions
57 lines (46 loc) · 1.65 KB
/
Copy pathclient.py
File metadata and controls
57 lines (46 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from transifex.api import transifex_api
from .config import PROJECT, LANGUAGE, ORGANISATION
_api_cache = {}
def _fetch_from_api(cache_key, api_call_func, *args, **kwargs):
if cache_key not in _api_cache:
_api_cache[cache_key] = api_call_func(*args, **kwargs)
return _api_cache[cache_key]
def get_all_resources():
"""Fetches all resources for the configured project, with caching."""
cache_key = "all_resources"
return _fetch_from_api(
cache_key, transifex_api.Resource.filter, project=PROJECT
).all()
def get_resource_language_stats():
"""Fetches language statistics for all resources, with caching."""
cache_key = "resource_language_stats"
return _fetch_from_api(
cache_key,
transifex_api.ResourceLanguageStats.filter,
project=PROJECT,
language=LANGUAGE,
).all()
def get_team_members():
"""Fetches all team members, with caching."""
cache_key = "team_members"
# Fetching with 'user' include to get user details like username
return (
_fetch_from_api(
cache_key,
transifex_api.TeamMembership.filter,
organization=ORGANISATION,
language=LANGUAGE,
)
.include("user")
.all()
)
def get_resource_translations(resource):
"""Fetches translations for a given resource, with caching per resource."""
resource_id = resource.id if hasattr(resource, "id") else str(resource)
cache_key = f"resource_translations_{resource_id}"
return _fetch_from_api(
cache_key,
transifex_api.ResourceTranslation.filter,
resource=resource,
language=LANGUAGE,
).all()