Make authorisation error messages translatable

Because they weren't. Foreigners might not understand them.
This commit is contained in:
Ghostkeeper 2019-02-08 11:19:22 +01:00
parent 12b2154a96
commit 1b29ff2b8a
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276
2 changed files with 12 additions and 10 deletions

View file

@ -1,18 +1,19 @@
# Copyright (c) 2019 Ultimaker B.V. # Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from base64 import b64encode
from hashlib import sha512
import json import json
import random import random
from hashlib import sha512
from base64 import b64encode
from typing import Dict, Optional
import requests import requests
from typing import Optional
from UM.i18n import i18nCatalog
from UM.Logger import Logger from UM.Logger import Logger
from cura.OAuth2.Models import AuthenticationResponse, UserProfile, OAuth2Settings from cura.OAuth2.Models import AuthenticationResponse, UserProfile, OAuth2Settings
catalog = i18nCatalog("cura")
## Class containing several helpers to deal with the authorization flow. ## Class containing several helpers to deal with the authorization flow.
class AuthorizationHelpers: class AuthorizationHelpers:
def __init__(self, settings: "OAuth2Settings") -> None: def __init__(self, settings: "OAuth2Settings") -> None:
@ -66,7 +67,7 @@ class AuthorizationHelpers:
Logger.log("w", "Could not parse token response data: %s", token_response.text) Logger.log("w", "Could not parse token response data: %s", token_response.text)
if not token_data: if not token_data:
return AuthenticationResponse(success = False, err_message = "Could not read response.") return AuthenticationResponse(success = False, err_message = catalog.i18nc("@message", "Could not read response."))
if token_response.status_code not in (200, 201): if token_response.status_code not in (200, 201):
return AuthenticationResponse(success = False, err_message = token_data["error_description"]) return AuthenticationResponse(success = False, err_message = token_data["error_description"])

View file

@ -1,17 +1,18 @@
# Copyright (c) 2019 Ultimaker B.V. # Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from typing import Optional, Callable, Tuple, Dict, Any, List, TYPE_CHECKING
from http.server import BaseHTTPRequestHandler from http.server import BaseHTTPRequestHandler
from typing import Optional, Callable, Tuple, Dict, Any, List, TYPE_CHECKING
from urllib.parse import parse_qs, urlparse from urllib.parse import parse_qs, urlparse
from cura.OAuth2.Models import AuthenticationResponse, ResponseData, HTTP_STATUS from cura.OAuth2.Models import AuthenticationResponse, ResponseData, HTTP_STATUS
from UM.i18n import i18nCatalog
if TYPE_CHECKING: if TYPE_CHECKING:
from cura.OAuth2.Models import ResponseStatus from cura.OAuth2.Models import ResponseStatus
from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers
catalog = i18nCatalog("cura")
## This handler handles all HTTP requests on the local web server. ## This handler handles all HTTP requests on the local web server.
# It also requests the access token for the 2nd stage of the OAuth flow. # It also requests the access token for the 2nd stage of the OAuth flow.
@ -62,14 +63,14 @@ class AuthorizationRequestHandler(BaseHTTPRequestHandler):
# Otherwise we show an error message (probably the user clicked "Deny" in the auth dialog). # Otherwise we show an error message (probably the user clicked "Deny" in the auth dialog).
token_response = AuthenticationResponse( token_response = AuthenticationResponse(
success = False, success = False,
err_message = "Please give the required permissions when authorizing this application." err_message = catalog.i18nc("@message", "Please give the required permissions when authorizing this application.")
) )
else: else:
# We don't know what went wrong here, so instruct the user to check the logs. # We don't know what went wrong here, so instruct the user to check the logs.
token_response = AuthenticationResponse( token_response = AuthenticationResponse(
success = False, success = False,
error_message = "Something unexpected happened when trying to log in, please try again." error_message = catalog.i18nc("@message", "Something unexpected happened when trying to log in, please try again.")
) )
if self.authorization_helpers is None: if self.authorization_helpers is None:
return ResponseData(), token_response return ResponseData(), token_response