mirror of
https://github.com/akuker/RASCSI.git
synced 2024-11-26 13:49:21 +00:00
Hardcoded locale fallback to English (#582)
* Hardcoded locale fallback to English * Fallbacks for locale in proto requests in case the locale fallback fails
This commit is contained in:
parent
2c60a848a8
commit
338b6af92c
@ -66,7 +66,7 @@ def list_images():
|
|||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.operation = proto.PbOperation.DEFAULT_IMAGE_FILES_INFO
|
command.operation = proto.PbOperation.DEFAULT_IMAGE_FILES_INFO
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
@ -123,7 +123,7 @@ def create_new_image(file_name, file_type, size):
|
|||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.operation = proto.PbOperation.CREATE_IMAGE
|
command.operation = proto.PbOperation.CREATE_IMAGE
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
command.params["file"] = file_name + "." + file_type
|
command.params["file"] = file_name + "." + file_type
|
||||||
command.params["size"] = str(size)
|
command.params["size"] = str(size)
|
||||||
@ -144,7 +144,7 @@ def delete_image(file_name):
|
|||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.operation = proto.PbOperation.DELETE_IMAGE
|
command.operation = proto.PbOperation.DELETE_IMAGE
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
command.params["file"] = file_name
|
command.params["file"] = file_name
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ def rename_image(file_name, new_file_name):
|
|||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.operation = proto.PbOperation.RENAME_IMAGE
|
command.operation = proto.PbOperation.RENAME_IMAGE
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
command.params["from"] = file_name
|
command.params["from"] = file_name
|
||||||
command.params["to"] = new_file_name
|
command.params["to"] = new_file_name
|
||||||
|
@ -25,7 +25,7 @@ def get_server_info():
|
|||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.operation = proto.PbOperation.SERVER_INFO
|
command.operation = proto.PbOperation.SERVER_INFO
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
@ -84,7 +84,7 @@ def get_reserved_ids():
|
|||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.operation = proto.PbOperation.RESERVED_IDS_INFO
|
command.operation = proto.PbOperation.RESERVED_IDS_INFO
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
@ -106,7 +106,7 @@ def get_network_info():
|
|||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.operation = proto.PbOperation.NETWORK_INTERFACES_INFO
|
command.operation = proto.PbOperation.NETWORK_INTERFACES_INFO
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
@ -125,7 +125,7 @@ def get_device_types():
|
|||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.operation = proto.PbOperation.DEVICE_TYPES_INFO
|
command.operation = proto.PbOperation.DEVICE_TYPES_INFO
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
@ -148,7 +148,7 @@ def get_image_files_info():
|
|||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.operation = proto.PbOperation.DEFAULT_IMAGE_FILES_INFO
|
command.operation = proto.PbOperation.DEFAULT_IMAGE_FILES_INFO
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
@ -177,7 +177,7 @@ def attach_image(scsi_id, **kwargs):
|
|||||||
"""
|
"""
|
||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
devices = proto.PbDeviceDefinition()
|
devices = proto.PbDeviceDefinition()
|
||||||
devices.id = int(scsi_id)
|
devices.id = int(scsi_id)
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ def detach_by_id(scsi_id, unit=None):
|
|||||||
command.operation = proto.PbOperation.DETACH
|
command.operation = proto.PbOperation.DETACH
|
||||||
command.devices.append(devices)
|
command.devices.append(devices)
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
@ -269,7 +269,7 @@ def detach_all():
|
|||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.operation = proto.PbOperation.DETACH_ALL
|
command.operation = proto.PbOperation.DETACH_ALL
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
@ -292,7 +292,7 @@ def eject_by_id(scsi_id, unit=None):
|
|||||||
command.operation = proto.PbOperation.EJECT
|
command.operation = proto.PbOperation.EJECT
|
||||||
command.devices.append(devices)
|
command.devices.append(devices)
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
@ -312,7 +312,7 @@ def list_devices(scsi_id=None, unit=None):
|
|||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.operation = proto.PbOperation.DEVICES_INFO
|
command.operation = proto.PbOperation.DEVICES_INFO
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
# If method is called with scsi_id parameter, return the info on those devices
|
# If method is called with scsi_id parameter, return the info on those devices
|
||||||
# Otherwise, return the info on all attached devices
|
# Otherwise, return the info on all attached devices
|
||||||
@ -390,7 +390,7 @@ def reserve_scsi_ids(reserved_scsi_ids):
|
|||||||
command.operation = proto.PbOperation.RESERVE_IDS
|
command.operation = proto.PbOperation.RESERVE_IDS
|
||||||
command.params["ids"] = ",".join(reserved_scsi_ids)
|
command.params["ids"] = ",".join(reserved_scsi_ids)
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
@ -408,7 +408,7 @@ def set_log_level(log_level):
|
|||||||
command.operation = proto.PbOperation.LOG_LEVEL
|
command.operation = proto.PbOperation.LOG_LEVEL
|
||||||
command.params["level"] = str(log_level)
|
command.params["level"] = str(log_level)
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
@ -426,7 +426,7 @@ def shutdown_pi(mode):
|
|||||||
command.operation = proto.PbOperation.SHUT_DOWN
|
command.operation = proto.PbOperation.SHUT_DOWN
|
||||||
command.params["mode"] = str(mode)
|
command.params["mode"] = str(mode)
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
@ -443,7 +443,7 @@ def is_token_auth():
|
|||||||
command = proto.PbCommand()
|
command = proto.PbCommand()
|
||||||
command.operation = proto.PbOperation.CHECK_AUTHENTICATION
|
command.operation = proto.PbOperation.CHECK_AUTHENTICATION
|
||||||
command.params["token"] = current_app.config["TOKEN"]
|
command.params["token"] = current_app.config["TOKEN"]
|
||||||
command.params["locale"] = session["language"]
|
command.params["locale"] = session["language"] or "en"
|
||||||
|
|
||||||
data = send_pb_command(command.SerializeToString())
|
data = send_pb_command(command.SerializeToString())
|
||||||
result = proto.PbResult()
|
result = proto.PbResult()
|
||||||
|
@ -92,10 +92,13 @@ def get_locale():
|
|||||||
try:
|
try:
|
||||||
language = session["language"]
|
language = session["language"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
language = None
|
language = ""
|
||||||
if language is not None:
|
logging.warning("The default locale could not be detected. Falling back to English.")
|
||||||
|
if language:
|
||||||
|
return language
|
||||||
|
# Hardcoded fallback to "en" when the user agent does not send an accept-language header
|
||||||
|
language = request.accept_languages.best_match(LANGUAGES) or "en"
|
||||||
return language
|
return language
|
||||||
return request.accept_languages.best_match(LANGUAGES)
|
|
||||||
|
|
||||||
|
|
||||||
def get_supported_locales():
|
def get_supported_locales():
|
||||||
|
Loading…
Reference in New Issue
Block a user