Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you change language of javascript error event messages?

Tags:

javascript

In our webapp we log messages to the server via window.onerror

However, if the client (the web browser) is using a non english language the message will be in whatever language the user has their web browser set to.

Is there any way to change this somehow?

Currently it is very unhelpful to get messages in multiple languages, hard to search for similar errors when they are in 12 different languages, also tricky for developers that need to translate to english all the time to figure out what went wrong.

[Edit] Adding an example here

window.onerror = function (message, url, lineNumber, columnNumber) {
    // log error here to server
}

In this example, the message will be in english most of the time, but sometimes it turns up in for example danish or swedish depending on the client (webbrowser).

like image 460
TomHells Avatar asked Apr 01 '15 12:04

TomHells


People also ask

Should error messages be translated?

Depends on the app. A highly technical application that will be used by people that understand English and the target language, you might be OK with English error messages. If it's a message that will be seen by the end user, it should be translated.

What is error message JS?

In JavaScript error message property is used to set or return the error message. Syntax: errorObj.message. Return Value: It returns a string, representing the details of the error.

What causes JavaScript error?

Grammatical mistakes, such as missing parentheses or unmatched brackets, are the major causes of syntax errors in JavaScript. For example, when you must use conditional statements to address multiple conditions, you may miss providing the parentheses as required, leading to syntax flaws.


1 Answers

Short answer: you cannot change it. The message is a descriptive message because of an error code. Your web app should take into consideration only the state (code) of the error, not the message.

These messages are part of your browser settings, which you will not have rights to change (some of them are read-only, but all are write-protected). This could mean I can render a user's browser useless by changing the program settings from javascript (for example, changing the language to Japanese for an english-only user :).

like image 181
Alex Avatar answered Nov 08 '22 14:11

Alex