JavaScript translation: The hidden pitfalls and tips you need to know
JavaScript translation tips: The hidden pitfalls and tips you need to know when translating JavaScript code
Did you know that some JavaScript strings, comments, and identifiers have a special meaning in the context of a translation? Or that a string can be split or merged depending on the context? Or even that there are special characters used for code snippets?
If you are a professional technical translator who frequently deals with source code, you likely have already come across JavaScript at some point. But how comfortable are you with this programming language? Do you know everything there is to know about it from the perspective of a JavaScript translator?
JavaScript is one of the most potent languages for front-end web development. However, when you decide to translate JavaScript code, it’s not always straightforward and difficulties can arise.
There are a lot of potential pitfalls that you need to look out for. This blog will look at some of the hidden pitfalls and tips you need to know when translating JavaScript code.
Hidden pitfalls
Automatic identification of comments and strings in JavaScript
JavaScript has a built-in function that automatically identifies comments and strings that contain a sequence of characters that looks like a comment or a string. This function may cause problems when you try to translate your code. JavaScript recognizes two types of comments: single-line comments that start with // and multiline comments that begin with /* and conclude with */. These comments can be found in many programming languages and they are often used to write notes or instructions for future maintenance. In the context of a translation, they may contain text that should be included in the translation.
The same holds for strings that contain a sequence of characters that looks like a string. The language might have a special syntax for concatenating or embedding strings. However, when JavaScript automatically identifies strings, these special symbols are no longer present in the source code. This means the translation will contain the source code’s literal values and not the intended translation.
Automated translation tools are not always reliable for translating JavaScript code
because they are designed to recognize source code and to store strings, comments, and identifiers as is. Unfortunately, they are totally unaware of the special characters used in JavaScript. This means they will not be able to recognize them as part of the source code. This can lead to technical translations with errors or missing content. Automated translation tools should therefore not be used to translate JavaScript. Instead, the source code should be manually translated. This process gives you complete control over the code and ensures that your translation will be accurate.
Identifiers have a special meaning in the context of a translation
Some identifiers have a specific meaning in a programming language used for differing operations in the code. In other programming languages, identifiers are usually written in lowercase letters and in CamelCase for class and method definitions. However, in JavaScript, identifiers use snake_case. This means that you can write one identifier name in different ways. For example, the identifier for an “if” statement is if, and the identifier for a “for” statement is for. Identifiers can be written in varying ways, and automated translation tools don’t know which one to choose. To ensure that the translator recognizes all the identifiers correctly and opts for the most suitable translation, you must be very careful when writing the source code. Make sure that you follow the writing guidelines below, and don’t forget to use PEP8-style identifiers. This will make your life a lot easier when translating your code.

Photo by Gabriel Heinzer on Unsplash
Strings can be split or merged depending on the context.
There are several circumstances when a string can be split or merged based on the context, such as when you wish to include a string in several parts of the code. Typically, the string will be split at the first occurrence of a special JavaScript character known as a “splitting marker.” For example, the splitting marker for the + operator is an addition sign (+), and the splitting marker for the & operator is an ampersand (&). The string will be split at the first occurrence of the splitting marker, and the remaining parts of the string will be inserted after the location of the splitting marker. For example, consider the following code:
var kim = “Kim” + ” Ritman”
The string “Kim Ritman” is first split at the plus sign, and the remaining parts of the string will be inserted after the Kim variable. The Kim variable will therefore be updated to “Kim Ritman.”
Special characters are used for code snippets
In JavaScript, special characters are used for code snippets. This means that when the code snippet is executed, the special characters used to denote the code snippet will be removed from the source code and won’t be visible in the final product. You shouldn’t worry about this when translating code, but you should ensure that the translator is aware of this. The translator must check that the source code has no special characters that the JavaScript interpreter might remove as a result of the code snippet’s execution. This can lead to translations with mistakes or missing content as the translator might interpret the source code as literal text. The translator could possibly interpret the code snippet as a literal string, in which case the special characters would be removed from the source code as a result.
Tips
Check your translated code by running it in an interpreter or debugger
To ensure that your translated code is correct, you can use various debugging tools to test the code and see whether it executes as expected. However, you need to make certain that you run your translated code, not the source code, otherwise all the identifiers will be replaced with the source code’s literal values, and you won’t see the results of your translation.
There are many tools you can use to debug your translated code. Visual Studio, Eclipse, Sublime Text, and Visual Studio Code are the most popular debuggers. These tools come with integrated debuggers designed especially for debugging translated code.
If you can’t use one of these integrated debuggers, you can still debug translated code and make sure your translated code is correct. You need to rename your translation files to include the language name and ensure your code uses the language variable to select the valid translation file. For example, if you translate your code into Spanish and you name your translation file es.js, you can add the following code before running your code to select the correct translation.
Don’t rely 100% on automated tools when translating JavaScript code. Manual checks are still necessary.
Although automated translation tools are usually helpful for certain content areas, this doesn’t mean you can rely on them entirely in code translation. Code is generally written in a way that is difficult for translation tools to understand. Code translation must therefore be done manually by a technical translator who understands the code. It’s best to use automated translation tools as a guide rather than confiding blindly in them. Use them to gain a general idea of the content, and then carry out manual checks to clean up the text. This way, you can ensure that the code is translated accurately.
Be careful with strings containing function definitions and declarations, as they will be replaced with the final values at runtime.
Function definitions and declarations are unique strings that are inserted in the code. When a program runs, these definitions and declarations are replaced with the real content so the program can execute properly. These strings should therefore never be regarded as translatable or included in your translation file. Instead, it is best to write them in English so translators can find them during the initial review.
Conclusion
There are a lot of potential pitfalls that you need to look out for when translating JavaScript code. Automated translation tools are not always reliable for translating JavaScript code. As a result, you should not rely 100% on them and manual checks should be made. Be careful with strings containing function definitions and declarations, as they will be replaced with the final values at runtime. If you bear these tips in mind, you’ll have a much smoother ride when translating JavaScript code.
Do you need a technical translation in Barcelona?
Do you need a translator specialized in software in Barcelona? Are you looking for an expert translator in computer science? Contact us using the following contact form, and we’ll send you a no obligation quote for a professional translation as promptly as possible.
No Comments