37
37
from edmc_data import companion_category_map as category_map
38
38
from EDMCLogging import get_main_logger
39
39
from monitor import monitor
40
+ from l10n import translations as tr
40
41
41
42
logger = get_main_logger ()
42
43
43
44
if TYPE_CHECKING :
44
- def _ (x : str ): return x
45
-
46
45
UserDict = collections .UserDict [str , Any ] # indicate to our type checkers what this generic class holds normally
47
46
else :
48
47
UserDict = collections .UserDict # Otherwise simply use the actual class
@@ -224,7 +223,7 @@ def __init__(self, *args) -> None:
224
223
self .args = args
225
224
if not args :
226
225
# LANG: Frontier CAPI didn't respond
227
- self .args = (_ ("Error: Frontier CAPI didn't respond" ),)
226
+ self .args = (tr . tl ("Error: Frontier CAPI didn't respond" ),)
228
227
229
228
230
229
class ServerConnectionError (ServerError ):
@@ -243,7 +242,7 @@ def __init__(self, *args) -> None:
243
242
self .args = args
244
243
if not args :
245
244
# LANG: Frontier CAPI data doesn't agree with latest Journal game location
246
- self .args = (_ ('Error: Frontier server is lagging' ),)
245
+ self .args = (tr . tl ('Error: Frontier server is lagging' ),)
247
246
248
247
249
248
class NoMonitorStation (Exception ):
@@ -259,7 +258,7 @@ def __init__(self, *args) -> None:
259
258
self .args = args
260
259
if not args :
261
260
# LANG: Commander is docked at an EDO settlement, got out and back in, we forgot the station
262
- self .args = (_ ("Docked but unknown station: EDO Settlement?" ),)
261
+ self .args = (tr . tl ("Docked but unknown station: EDO Settlement?" ),)
263
262
264
263
265
264
class CredentialsError (Exception ):
@@ -269,7 +268,7 @@ def __init__(self, *args) -> None:
269
268
self .args = args
270
269
if not args :
271
270
# LANG: Generic "something went wrong with Frontier Auth" error
272
- self .args = (_ ('Error: Invalid Credentials' ),)
271
+ self .args = (tr . tl ('Error: Invalid Credentials' ),)
273
272
274
273
275
274
class CredentialsRequireRefresh (Exception ):
@@ -294,7 +293,7 @@ def __init__(self, *args) -> None:
294
293
self .args = args
295
294
if not args :
296
295
# LANG: Frontier CAPI authorisation not for currently game-active commander
297
- self .args = (_ ('Error: Wrong Cmdr' ),)
296
+ self .args = (tr . tl ('Error: Wrong Cmdr' ),)
298
297
299
298
300
299
class Auth :
@@ -429,7 +428,7 @@ def authorize(self, payload: str) -> str: # noqa: CCR001
429
428
'<unknown error>'
430
429
)
431
430
# LANG: Generic error prefix - following text is from Frontier auth service
432
- raise CredentialsError (f'{ _ ("Error" )} : { error !r} ' )
431
+ raise CredentialsError (f'{ tr . tl ("Error" )} : { error !r} ' )
433
432
434
433
r = None
435
434
try :
@@ -472,18 +471,18 @@ def authorize(self, payload: str) -> str: # noqa: CCR001
472
471
if (usr := data_decode .get ('usr' )) is None :
473
472
logger .error ('No "usr" in /decode data' )
474
473
# LANG: Frontier auth, no 'usr' section in returned data
475
- raise CredentialsError (_ ("Error: Couldn't check token customer_id" ))
474
+ raise CredentialsError (tr . tl ("Error: Couldn't check token customer_id" ))
476
475
477
476
if (customer_id := usr .get ('customer_id' )) is None :
478
477
logger .error ('No "usr"->"customer_id" in /decode data' )
479
478
# LANG: Frontier auth, no 'customer_id' in 'usr' section in returned data
480
- raise CredentialsError (_ ("Error: Couldn't check token customer_id" ))
479
+ raise CredentialsError (tr . tl ("Error: Couldn't check token customer_id" ))
481
480
482
481
# All 'FID' seen in Journals so far have been 'F<id>'
483
482
# Frontier, Steam and Epic
484
483
if f'F{ customer_id } ' != monitor .state .get ('FID' ):
485
484
# LANG: Frontier auth customer_id doesn't match game session FID
486
- raise CredentialsError (_ ("Error: customer_id doesn't match!" ))
485
+ raise CredentialsError (tr . tl ("Error: customer_id doesn't match!" ))
487
486
488
487
logger .info (f'Frontier CAPI Auth: New token for \" { self .cmdr } \" ' )
489
488
cmdrs = config .get_list ('cmdrs' , default = [])
@@ -505,7 +504,7 @@ def authorize(self, payload: str) -> str: # noqa: CCR001
505
504
self .dump (r )
506
505
507
506
# LANG: Failed to get Access Token from Frontier Auth service
508
- raise CredentialsError (_ ('Error: unable to get token' )) from e
507
+ raise CredentialsError (tr . tl ('Error: unable to get token' )) from e
509
508
510
509
logger .error (f"Frontier CAPI Auth: Can't get token for \" { self .cmdr } \" " )
511
510
self .dump (r )
@@ -514,7 +513,7 @@ def authorize(self, payload: str) -> str: # noqa: CCR001
514
513
'<unknown error>'
515
514
)
516
515
# LANG: Generic error prefix - following text is from Frontier auth service
517
- raise CredentialsError (f'{ _ ("Error" )} : { error !r} ' )
516
+ raise CredentialsError (f'{ tr . tl ("Error" )} : { error !r} ' )
518
517
519
518
@staticmethod
520
519
def invalidate (cmdr : str | None ) -> None :
@@ -841,7 +840,7 @@ def capi_single_query(
841
840
except Exception as e :
842
841
logger .debug ('Attempting GET' , exc_info = e )
843
842
# LANG: Frontier CAPI data retrieval failed
844
- raise ServerError (f'{ _ ("Frontier CAPI query failure" )} : { capi_endpoint } ' ) from e
843
+ raise ServerError (f'{ tr . tl ("Frontier CAPI query failure" )} : { capi_endpoint } ' ) from e
845
844
846
845
if capi_endpoint == self .FRONTIER_CAPI_PATH_PROFILE and 'commander' not in capi_data :
847
846
logger .error ('No commander in returned data' )
@@ -874,7 +873,7 @@ def handle_http_error(response: requests.Response, endpoint: str):
874
873
if response .status_code == 418 :
875
874
# "I'm a teapot" - used to signal maintenance
876
875
# LANG: Frontier CAPI returned 418, meaning down for maintenance
877
- raise ServerError (_ ("Frontier CAPI down for maintenance" ))
876
+ raise ServerError (tr . tl ("Frontier CAPI down for maintenance" ))
878
877
879
878
logger .exception ('Frontier CAPI: Misc. Error' )
880
879
raise ServerError ('Frontier CAPI: Misc. Error' )
0 commit comments