Skip to content

Commit

Permalink
Provide localised message for HTTP code fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
e-marchand committed Feb 4, 2024
1 parent 09a8e25 commit 9dfcaf1
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 76 deletions.
152 changes: 76 additions & 76 deletions qmobileapi/src/main/java/com/qmobile/qmobileapi/utils/HttpCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package com.qmobile.qmobileapi.utils

import com.qmobile.qmobileapi.R

object HttpCode {

// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
Expand Down Expand Up @@ -78,90 +80,88 @@ object HttpCode {
private const val networkAuthenticationRequired = 511

@Suppress("LongMethod")
fun message(code: Int): String =
fun message(code: Int): Int? =
when (code) {
continue_key -> "Continue"
switchingProtocols -> "Switching Protocols"
processing -> "Processing"
continue_key -> R.string.continue_key
switchingProtocols -> R.string.switching_protocols
processing -> R.string.processing

ok -> "OK"
created -> "Created"
accepted -> "Accepted"
nonAuthoritativeInformation -> "Non Authoritative Information"
noContent -> "No Content"
resetContent -> "Reset Content"
partialContent -> "Partial Content"
ok -> R.string.ok
created -> R.string.created
accepted -> R.string.accepted
nonAuthoritativeInformation -> R.string.non_authoritative_information
noContent -> R.string.no_content
resetContent -> R.string.reset_content
partialContent -> R.string.partial_content

multipleChoices -> "Multiple Choices"
movedPermanently -> "Moved Permanently"
found -> "Found"
seeOther -> "See Other"
notModified -> "Not Modified"
useProxy -> "Use Proxy"
switchProxy -> "Switch Proxy"
temporaryRedirect -> "Temporary Redirect"
permanentRedirect -> "Permanent Redirect"
multipleChoices -> R.string.multiple_choices
movedPermanently -> R.string.moved_permanently
found -> R.string.found
seeOther -> R.string.see_other
notModified -> R.string.not_modified
useProxy -> R.string.use_proxy
switchProxy -> R.string.switch_proxy
temporaryRedirect -> R.string.temporary_redirect
permanentRedirect -> R.string.permanent_redirect

badRequest -> "Bad Request"
unauthorized -> "Unauthorized"
paymentRequired -> "Payment Required"
forbidden -> "Forbidden"
notFound -> "Not Found"
methodNotAllowed -> "Method Not Allowed"
notAcceptable -> "Not Acceptable"
proxyAuthenticationRequired -> "Proxy Authentication Required"
requestTimeout -> "Request Timeout"
conflict -> "Conflict"
gone -> "Gone"
lengthRequired -> "Length Required"
preconditionFailed -> "Precondition Failed"
requestEntityTooLarge -> "Request Entity Too Large"
requestURITooLong -> "Request URI Too Long"
unsupportedMediaType -> "Unsupported Media Type"
requestedRangeNotSatisfiable -> "Requested Range Not Satisfiable"
expectationFailed -> "Expectation Failed"
imATeapot -> "I'm A Teapot"
authenticationTimeout -> "Authentication Timeout"
enhanceYourCalm -> "Enhance Your Calm"
unprocessableEntity -> "Unprocessable Entity"
locked -> "Locked"
failedDependency -> "Failed Dependency"
preconditionRequired -> "Precondition Required"
tooManyRequests -> "Too Many Requests"
requestHeaderFieldsTooLarge -> "Request Header Fields Too Large"
badRequest -> R.string.bad_request
unauthorized -> R.string.unauthorized
paymentRequired -> R.string.payment_required
forbidden -> R.string.forbidden
notFound -> R.string.not_found
methodNotAllowed -> R.string.method_not_allowed
notAcceptable -> R.string.not_acceptable
proxyAuthenticationRequired -> R.string.proxy_authentication_required
requestTimeout -> R.string.request_timeout
conflict -> R.string.conflict
gone -> R.string.gone
lengthRequired -> R.string.length_required
preconditionFailed -> R.string.precondition_failed
requestEntityTooLarge -> R.string.request_entity_too_large
requestURITooLong -> R.string.request_uri_too_long
unsupportedMediaType -> R.string.unsupported_media_type
requestedRangeNotSatisfiable -> R.string.requested_range_not_satisfiable
expectationFailed -> R.string.expectation_failed
imATeapot -> R.string.im_a_teapot
authenticationTimeout -> R.string.authentication_timeout
enhanceYourCalm -> R.string.enhance_your_calm
unprocessableEntity -> R.string.unprocessable_entity
locked -> R.string.locked
failedDependency -> R.string.failed_dependency
preconditionRequired -> R.string.precondition_required
tooManyRequests -> R.string.too_many_requests
requestHeaderFieldsTooLarge -> R.string.request_header_fields_too_large

internalServerError -> "Internal Server Error"
notImplemented -> "Not Implemented"
badGateway -> "Bad Gateway"
serviceUnavailable -> "Service Unavailable"
gatewayTimeout -> "Gateway Timeout"
httpVersionNotSupported -> "HTTP Version Not Supported"
variantAlsoNegotiates -> "Variant Also Negotiates"
insufficientStorage -> "Insufficient Storage"
loopDetected -> "Loop Detected"
notExtended -> "Not Extended"
networkAuthenticationRequired -> "Network Authentication Required"
else -> ""
internalServerError -> R.string.internal_server_error
notImplemented -> R.string.not_implemented
badGateway -> R.string.bad_gateway
serviceUnavailable -> R.string.service_unavailable
gatewayTimeout -> R.string.gateway_timeout
httpVersionNotSupported -> R.string.http_version_not_supported
variantAlsoNegotiates -> R.string.variant_also_negotiates
insufficientStorage -> R.string.insufficient_storage
loopDetected -> R.string.loop_detected
notExtended -> R.string.not_extended
networkAuthenticationRequired -> R.string.network_authentication_required
else -> null
}

fun reason(code: Int): String? =
fun reason(code: Int): Int? =
when (code) {
tooManyRequests -> "Too many requests send to the application server."
serviceUnavailable -> "Service is unavailable currently."
movedPermanently -> "Resource is moved permanently."
unauthorized -> "You are no more authenticated. Please log in."
forbidden -> "You are no more allowed to access the resource or make this action."
notFound -> "Some information is missing on application server."
methodNotAllowed -> "You are not a allowed to make this request."
notAcceptable -> "The request is not acceptable."
requestTimeout -> "The server make too much time to respond."
authenticationTimeout -> "Your session has expired, please re-login."
locked -> "The resource is locked."
notImplemented -> "Request are not available."
gatewayTimeout -> "Gateway timeout."
in 500..600 ->
"The server encountered an error and was unable to complete your " +
"request. Please contact the server administrator."
tooManyRequests -> R.string.reason_too_many_requests
serviceUnavailable -> R.string.reason_service_unavailable
movedPermanently -> R.string.reason_moved_permanently
unauthorized -> R.string.reason_unauthorized
forbidden -> R.string.reason_forbidden
notFound -> R.string.reason_not_found
methodNotAllowed -> R.string.reason_method_not_allowed
notAcceptable -> R.string.reason_not_acceptable
requestTimeout -> R.string.reason_request_timeout
authenticationTimeout -> R.string.reason_authentication_timeout
locked -> R.string.reason_locked
notImplemented -> R.string.reason_not_implemented
gatewayTimeout -> R.string.reason_gateway_timeout
in 500..600 -> R.string.reason_internal_error
else -> null
}
}
81 changes: 81 additions & 0 deletions qmobileapi/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- HTTP code messages -->
<string name="continue_key">Continuer</string>
<string name="switching_protocols">Changement de protocole</string>
<string name="processing">Traitement en cours</string>

<string name="ok">OK</string>
<string name="created">Créé</string>
<string name="accepted">Accepté</string>
<string name="non_authoritative_information">Information non autorisée</string>
<string name="no_content">Pas de contenu</string>
<string name="reset_content">Réinitialiser le contenu</string>
<string name="partial_content">Contenu partiel</string>

<string name="multiple_choices">Choix multiples</string>
<string name="moved_permanently">Déplacé définitivement</string>
<string name="found">Trouvé</string>
<string name="see_other">Voir autre</string>
<string name="not_modified">Non modifié</string>
<string name="use_proxy">Utiliser un proxy</string>
<string name="switch_proxy">Changer de proxy</string>
<string name="temporary_redirect">Redirection temporaire</string>
<string name="permanent_redirect">Redirection permanente</string>

<string name="bad_request">Requête incorrecte</string>
<string name="unauthorized">Non autorisé</string>
<string name="payment_required">Paiement requis</string>
<string name="forbidden">Interdit</string>
<string name="not_found">Non trouvé</string>
<string name="method_not_allowed">Méthode non autorisée</string>
<string name="not_acceptable">Non acceptable</string>
<string name="proxy_authentication_required">Authentification proxy requise</string>
<string name="request_timeout">Délai de la requête dépassé</string>
<string name="conflict">Conflit</string>
<string name="gone">Parti</string>
<string name="length_required">Longueur requise</string>
<string name="precondition_failed">Échec de la précondition</string>
<string name="request_entity_too_large">Entité de la requête trop grande</string>
<string name="request_uri_too_long">URI de la requête trop long</string>
<string name="unsupported_media_type">Type de média non pris en charge</string>
<string name="requested_range_not_satisfiable">Plage demandée non satisfaisable</string>
<string name="expectation_failed">Échec de l\'attente</string>
<string name="im_a_teapot">Je suis une théière</string>
<string name="authentication_timeout">Délai d\'authentification dépassé</string>
<string name="enhance_your_calm">Améliorez votre calme</string>
<string name="unprocessable_entity">Entité non traitable</string>
<string name="locked">Verrouillé</string>
<string name="failed_dependency">Échec de la dépendance</string>
<string name="precondition_required">Précondition requise</string>
<string name="too_many_requests">Trop de requêtes</string>
<string name="request_header_fields_too_large">Champs d\'en-tête de requête trop grands</string>

<string name="internal_server_error">Erreur interne du serveur</string>
<string name="not_implemented">Non implémenté</string>
<string name="bad_gateway">Passerelle incorrecte</string>
<string name="service_unavailable">Service indisponible</string>
<string name="gateway_timeout">Délai de la passerelle dépassé</string>
<string name="http_version_not_supported">Version HTTP non prise en charge</string>
<string name="variant_also_negotiates">Variante négocie également</string>
<string name="insufficient_storage">Stockage insuffisant</string>
<string name="loop_detected">Détection de boucle</string>
<string name="not_extended">Non étendu</string>
<string name="network_authentication_required">Authentification réseau requise</string>

<!-- HTTP code reasons -->
<string name="reason_too_many_requests">Trop de requêtes envoyées au serveur d\'application.</string>
<string name="reason_service_unavailable">Le service est actuellement indisponible.</string>
<string name="reason_moved_permanently">La ressource a été déplacée de manière permanente.</string>
<string name="reason_unauthorized">Vous n\'êtes plus authentifié. Veuillez vous connecter.</string>
<string name="reason_forbidden">Vous n\'êtes plus autorisé à accéder à la ressource ou à effectuer cette action.</string>
<string name="reason_not_found">Certaines informations manquent sur le serveur d\'application.</string>
<string name="reason_method_not_allowed">Vous n\'êtes pas autorisé à effectuer cette requête.</string>
<string name="reason_not_acceptable">La requête n\'est pas acceptable.</string>
<string name="reason_request_timeout">Le serveur met trop de temps à répondre.</string>
<string name="reason_authentication_timeout">Votre session a expiré, veuillez vous reconnecter.</string>
<string name="reason_locked">La ressource est verrouillée.</string>
<string name="reason_not_implemented">Les requêtes ne sont pas disponibles.</string>
<string name="reason_gateway_timeout">Délai de la passerelle dépassé.</string>
<string name="reason_internal_error">Le serveur a rencontré une erreur et n\'a pas pu terminer votre demande. Veuillez contacter l'administrateur du serveur.</string>
</resources>
81 changes: 81 additions & 0 deletions qmobileapi/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- HTTP code messages -->
<string name="continue_key">Continue</string>
<string name="switching_protocols">Switching Protocols</string>
<string name="processing">Processing</string>

<string name="ok">OK</string>
<string name="created">Created</string>
<string name="accepted">Accepted</string>
<string name="non_authoritative_information">Non Authoritative Information</string>
<string name="no_content">No Content</string>
<string name="reset_content">Reset Content</string>
<string name="partial_content">Partial Content</string>

<string name="multiple_choices">Multiple Choices</string>
<string name="moved_permanently">Moved Permanently</string>
<string name="found">Found</string>
<string name="see_other">See Other</string>
<string name="not_modified">Not Modified</string>
<string name="use_proxy">Use Proxy</string>
<string name="switch_proxy">Switch Proxy</string>
<string name="temporary_redirect">Temporary Redirect</string>
<string name="permanent_redirect">Permanent Redirect</string>

<string name="bad_request">Bad Request</string>
<string name="unauthorized">Unauthorized</string>
<string name="payment_required">Payment Required</string>
<string name="forbidden">Forbidden</string>
<string name="not_found">Not Found</string>
<string name="method_not_allowed">Method Not Allowed</string>
<string name="not_acceptable">Not Acceptable</string>
<string name="proxy_authentication_required">Proxy Authentication Required</string>
<string name="request_timeout">Request Timeout</string>
<string name="conflict">Conflict</string>
<string name="gone">Gone</string>
<string name="length_required">Length Required</string>
<string name="precondition_failed">Precondition Failed</string>
<string name="request_entity_too_large">Request Entity Too Large</string>
<string name="request_uri_too_long">Request URI Too Long</string>
<string name="unsupported_media_type">Unsupported Media Type</string>
<string name="requested_range_not_satisfiable">Requested Range Not Satisfiable</string>
<string name="expectation_failed">Expectation Failed</string>
<string name="im_a_teapot">I\'m A Teapot</string>
<string name="authentication_timeout">Authentication Timeout</string>
<string name="enhance_your_calm">Enhance Your Calm</string>
<string name="unprocessable_entity">Unprocessable Entity</string>
<string name="locked">Locked</string>
<string name="failed_dependency">Failed Dependency</string>
<string name="precondition_required">Precondition Required</string>
<string name="too_many_requests">Too Many Requests</string>
<string name="request_header_fields_too_large">Request Header Fields Too Large</string>

<string name="internal_server_error">Internal Server Error</string>
<string name="not_implemented">Not Implemented</string>
<string name="bad_gateway">Bad Gateway</string>
<string name="service_unavailable">Service Unavailable</string>
<string name="gateway_timeout">Gateway Timeout</string>
<string name="http_version_not_supported">HTTP Version Not Supported</string>
<string name="variant_also_negotiates">Variant Also Negotiates</string>
<string name="insufficient_storage">Insufficient Storage</string>
<string name="loop_detected">Loop Detected</string>
<string name="not_extended">Not Extended</string>
<string name="network_authentication_required">Network Authentication Required</string>

<!-- HTTP code reasons -->
<string name="reason_too_many_requests">Too many requests send to the application server.</string>
<string name="reason_service_unavailable">Service is unavailable currently.</string>
<string name="reason_moved_permanently">Resource is moved permanently.</string>
<string name="reason_unauthorized">You are no more authenticated. Please log in.</string>
<string name="reason_forbidden">You are no more allowed to access the resource or make this action.</string>
<string name="reason_not_found">Some information is missing on application server.</string>
<string name="reason_method_not_allowed">You are not a allowed to make this request.</string>
<string name="reason_not_acceptable">The request is not acceptable.</string>
<string name="reason_request_timeout">The server make too much time to respond.</string>
<string name="reason_authentication_timeout">Your session has expired, please re-login.</string>
<string name="reason_locked">The resource is locked.</string>
<string name="reason_not_implemented">Request are not available.</string>
<string name="reason_gateway_timeout">Gateway timeout.</string>
<string name="reason_internal_error">"The server encountered an error and was unable to complete your request. Please contact the server administrator</string>
</resources>

0 comments on commit 9dfcaf1

Please sign in to comment.