Hidden pitfall: Identifiers have special meaning in the context of a translation
Hidden pitfall: Strings might be split and merged depending on the context
Hidden pitfall: There are special characters used for code snippets
Tip: 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 that it executes as expected. However, you need to ensure that you run your translated code, not the source code. Otherwise, all identifiers will be replaced with the source code’s literal values, and you won’t see your translation results. 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 to Spanish and name your translation file es.js, you can add the following code before running your code to select the correct translation.
Although automated translation tools can usually be helpful for specific content areas, this doesn’t mean you can entirely rely on them for code translation. Code is generally written in a way that makes it difficult for translation tools to understand. Therefore, code translation must be done manually by a technical translator who understands the code. It’s best to use automated translation tools as guidance rather than as a final result. Use them to give you a general idea of the content, and then do a manual review to clean up the text. This way, you can ensure that the code is translated accurately.
Tip: 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. Therefore, these strings should never be marked as translatable or included in your translation file. Instead, it would be best to write them in English so translators can find them during the initial review.