@@ -36,32 +36,40 @@ def _empty_branch_object():
36
36
37
37
class TransifexHelper :
38
38
def __init__ (self , dryrun : bool = True , logger : logging .Logger = None ):
39
+ transifex = settings .TRANSIFEX
39
40
self .dryrun = dryrun
40
41
self .nop = "<NOP> " if dryrun else ""
41
42
self .log = logger if logger else logging .getLogger ()
42
43
43
- self .organization_slug = settings .TRANSIFEX ["ORGANIZATION_SLUG" ]
44
- self .project_slug = settings .TRANSIFEX ["PROJECT_SLUG" ]
45
- self .team_id = settings .TRANSIFEX ["TEAM_ID" ]
46
- self .project_id = f"o:{ self .organization_slug } :p:{ self .project_slug } "
44
+ self .organization_slug = transifex ["ORGANIZATION_SLUG" ]
45
+
46
+ self .deeds_ux_project_slug = transifex ["DEEDS_UX_PROJECT_SLUG" ]
47
+ self .deeds_ux_team_slug = transifex ["DEEDS_UX_TEAM_SLUG" ]
48
+ self .deeds_ux_resource_slug = transifex ["DEEDS_UX_RESOURCE_SLUG" ]
49
+
50
+ self .legal_code_project_slug = transifex ["LEGAL_CODE_PROJECT_SLUG" ]
51
+ self .legal_code_team_slug = transifex ["LEGAL_CODE_TEAM_SLUG" ]
47
52
48
53
self .api = transifex_api
49
- self .api .setup (auth = settings . TRANSIFEX ["API_TOKEN" ])
54
+ self .api .setup (auth = transifex ["API_TOKEN" ])
50
55
self .api_organization = self .api .Organization .get (
51
56
slug = self .organization_slug
52
57
)
58
+
53
59
# The Transifex API requires project slugs to be lowercase
54
60
# (^[a-z0-9._-]+$'), but the web interfaces does not (did not?). Our
55
- # project slug is uppercase.
61
+ # Deeds & UX project slug is uppercase.
56
62
# https://transifex.github.io/openapi/#tag/Projects
57
63
for project in self .api_organization .fetch (
58
64
"projects"
59
65
): # pragma: no cover
60
66
# TODO: remove coveragepy exclusion after upgrade to Python 3.10
61
67
# https://github.com/nedbat/coveragepy/issues/198
62
- if project .attributes ["slug" ] == self .project_slug :
63
- self .api_project = project
64
- break
68
+ if project .attributes ["slug" ] == self .deeds_ux_project_slug :
69
+ self .api_deeds_ux_project = project
70
+ elif project .attributes ["slug" ] == self .legal_code_project_slug :
71
+ self .api_legal_code_project = project
72
+
65
73
for i18n_format in self .api .I18nFormat .filter (
66
74
organization = self .api_organization
67
75
): # pragma: no cover
@@ -82,16 +90,26 @@ def get_transifex_resource_stats(self):
82
90
Uses Transifex API 3.0: Resources
83
91
https://transifex.github.io/openapi/#tag/Resources
84
92
"""
85
- self .api_project .reload ()
93
+ self .api_deeds_ux_project .reload ()
94
+ self .api_legal_code_project .reload ()
86
95
stats = {}
96
+
97
+ # Deeds & UX
98
+ print (self .deeds_ux_resource_slug )
99
+ resource = self .api_deeds_ux_project .fetch ("resources" ).get (
100
+ slug = self .deeds_ux_resource_slug
101
+ )
102
+ stats [self .deeds_ux_resource_slug ] = resource .attributes
103
+
104
+ # Legal Code
87
105
resources = sorted (
88
- self .api_project .fetch ("resources" ).all (), key = lambda x : x .id
106
+ self .api_legal_code_project .fetch ("resources" ).all (),
107
+ key = lambda x : x .id
89
108
)
90
109
for resource in resources :
91
110
resource_slug = resource .attributes ["slug" ]
92
- if resource_slug in ["cc-search" , "deeds-choosers" ]:
93
- continue
94
111
stats [resource_slug ] = resource .attributes
112
+
95
113
return stats
96
114
97
115
def get_transifex_translation_stats (self ):
@@ -105,22 +123,43 @@ def get_transifex_translation_stats(self):
105
123
Uses Transifex API 3.0: Statistics
106
124
https://transifex.github.io/openapi/#tag/Statistics
107
125
"""
108
- self .api_project .reload ()
126
+ self .api_deeds_ux_project .reload ()
127
+ self .api_legal_code_project .reload ()
109
128
stats = {}
129
+
130
+ # Deeds & UX
131
+ languages_stats = sorted (
132
+ self .api .ResourceLanguageStats .filter (
133
+ project = self .api_deeds_ux_project ,
134
+ resource = (
135
+ f"o:{ self .organization_slug } :"
136
+ f"p:{ self .deeds_ux_project_slug } :"
137
+ f"r:{ self .deeds_ux_resource_slug } "
138
+ )
139
+ ).all (),
140
+ key = lambda x : x .id ,
141
+ )
142
+ for l_stats in languages_stats :
143
+ resource_slug = l_stats .related ["resource" ].id .split (":" )[- 1 ]
144
+ transifex_code = l_stats .related ["language" ].id .split (":" )[- 1 ]
145
+ if resource_slug not in stats :
146
+ stats [resource_slug ] = {}
147
+ stats [resource_slug ][transifex_code ] = l_stats .attributes
148
+
149
+ # Legal Code
110
150
languages_stats = sorted (
111
151
self .api .ResourceLanguageStats .filter (
112
- project = self .api_project
152
+ project = self .api_legal_code_project ,
113
153
).all (),
114
154
key = lambda x : x .id ,
115
155
)
116
156
for l_stats in languages_stats :
117
157
resource_slug = l_stats .related ["resource" ].id .split (":" )[- 1 ]
118
158
transifex_code = l_stats .related ["language" ].id .split (":" )[- 1 ]
119
- if resource_slug in ["cc-search" , "deeds-choosers" ]:
120
- continue
121
159
if resource_slug not in stats :
122
160
stats [resource_slug ] = {}
123
161
stats [resource_slug ][transifex_code ] = l_stats .attributes
162
+
124
163
return stats
125
164
126
165
@property
0 commit comments