JavaScript Translate Api/back end error message to display it for user

I'm working on a form which has both live and front end (javaScript) validation that displays quite nicely. But I also want to display the back end error message to the user for the rare cases the front end validation lets a request pass.

My backend error message is in english atm and I would like some suggestion on how to translate them. I don't want to translate it in the back end.

Example:

Back end response:

{   "errors": [ {"code": 409, "message" : "An Application has already been created. "}] }

Take the "message" and translate the string so I can print it in an element on the page.

How I'm doing right now:

var ErrorStatusHandler;

ErrorStatusHandler = (function() {
  function ErrorStatusHandler() {}

  ErrorStatusHandler.prototype.errorMessage = function(e) {
    var responseText, translatedResponseText;
    responseText = e.slice(12, -2);
    if (responseText === "An Application has already been created.") {
      translatedResponseText = responseText.replace("An Application has already been created.", "En ansökan med detta personnummer existerar redan.");
    } else {
//* some other error
      translatedResponseText = responseText;
    }
    return translatedResponseText;
  };

  return ErrorStatusHandler;

})();

But I'm sure that there is a better way to do this, I just cant seem to find one. P.S I rather not use a plugin, but if there isn't any good solutions I might have to.

Answer:1

I am repeating a OBJECT to render UI. Each row has a ItemName and a checkbox. Onclick of checkbox I should get the ID of that row. When I Run the page I am getting this error msg => Cannot read ...

I am repeating a OBJECT to render UI. Each row has a ItemName and a checkbox. Onclick of checkbox I should get the ID of that row. When I Run the page I am getting this error msg => Cannot read ...

  1. javascript function not called onchange

Step by step i did these Create a new Facebook App (App ID: 544557495732050) Create a new Facebook Page (https://www.facebook.com/Pasha-electronic-502844156580479/) In App which created by step 1 ...

Step by step i did these Create a new Facebook App (App ID: 544557495732050) Create a new Facebook Page (https://www.facebook.com/Pasha-electronic-502844156580479/) In App which created by step 1 ...

  1. facebook comments mirroring
  2. facebook comment mirroring deprecated

For example, I want to write something like: const initial = [1, 2, 3, 4]; const indexIWantToChange = 2; const obj = { prop: () => { const newArr = [...initial]; newArr[...

For example, I want to write something like: const initial = [1, 2, 3, 4]; const indexIWantToChange = 2; const obj = { prop: () => { const newArr = [...initial]; newArr[...

  1. change element array javascript
  2. change element array python
  3. change element array numpy
  4. change array element position javascript
  5. change array element value javascript
  6. change array element java
  7. change array element
  8. change array element position php
  9. change array element php
  10. change array element value php
  11. change array element matlab
  12. change array element name unity
  13. change array element c
  14. change array element typescript
  15. change array element bash
  16. change array element swift
  17. change array element position js
  18. change array element value
  19. change array element key php
  20. change array element position lodash

I try to pass a variable from Javascript (when choosing some option in a form) to a PHP file which calls a SQL query. The SQL query (a string) should be handed over to a Javascript function and the ...

I try to pass a variable from Javascript (when choosing some option in a form) to a PHP file which calls a SQL query. The SQL query (a string) should be handed over to a Javascript function and the ...

  1. pass variable javascript to php
  2. pass variable javascript
  3. pass variable javascript to html
  4. pass variable javascript function
  5. pass variable javascript to java
  6. pass variable javascript to c#
  7. pass variable javascript function onclick event
  8. pass variable javascript to php ajax
  9. pass javascript variable to php function
  10. pass javascript variable to c# razor
  11. pass javascript variable to html input value
  12. pass javascript variable to php without ajax
  13. pass javascript variable to php function in same page
  14. pass javascript variable to razor
  15. pass javascript variable to django template
  16. pass javascript variable to python script
  17. pass javascript variable to php ajax jquery
  18. pass javascript variable to laravel route
  19. pass javascript variable to django
  20. pass javascript variable to php same page ajax