In Python, the characters %
, {
, and [
have special meanings when used within a string, and can lead to errors or unintended behavior if not used properly. If a user wants to write these characters as literal characters within a string, they should use a backslash \
to escape them.
For example, let’s say a user wants to include the literal character %
in a string. Without escaping it, Python would interpret %
as a special character used for string formatting. To include the literal %
character in the string, the user can add a backslash before it, like so: my_string = "50\%"
. This will tell Python to treat the %
character as a regular character, rather than a formatting placeholder.
![](https://dreamsavior.net/wp-content/uploads/2023/02/image-3-1024x677.png)
%
spccial characterSimilarly, if a user wants to include the literal characters {
or [
in a string, they should add a backslash before them. For example: my_string = "The item costs \[5\] dollars."
.
By using the backslash to escape these characters, users can ensure that they are being interpreted as literal characters within the string, rather than as special characters with additional functionality. It’s important to note that the backslash itself needs to be escaped if the user wants to include it as a literal character, by adding an additional backslash before it: my_string = "This is a backslash: \\\\"
.
In summary, to write literal %
, {
, or [
characters within a Python string, users should add a backslash before them to escape them. This ensures that the characters are treated as literal characters, rather than special characters with special functionality.
List of non interpolated special characters
Normally Translator++ will interpolate the text into what you will see on the game as close as possible. Generally this will help translator to focus on translating and not coding.
For example, translators does not need to write \n
for line break. And no need to escape quotes with backslash: \"
.
Non interpolated special characters are characters that will be kept as is by Translator++. Therefore, translators need to determine for themselves whether these characters will be treated as literal or as Renpy’s Command.
Non interpolated chars | Example |
---|---|
Square brackets[ and ] | As literal square bracket:\[ and \] As formatting placeholder: [ and ] |
Curly brackets{ and } | As literal curly bracket:\{ and \} As formatting placeholder: { and } |
Percent% | As literal percent:\% As formatting placeholder: % |
Example
Text in rpy files | Text in Translator++ | Info |
---|---|---|
Translator++ is a \" CAT\" (Computer Aided Translation)\n or computer-aided human translation (CAHT) software for games. | Translator++ is a “CAT” (Computer Aided Translation) or computer-aided human translation (CAHT) software for games. | Quote and new line character (\n ) will be interpolated. |
My name is { fname} , I’m { age} | My name is { fname} , I’m { age | |
My name is \{ John\} , I’m \{ 20\} | My name is \{ John\} , I’m \{ 20\} | |
%s and %s living together | %s and %s living together | |
You get 20\% discount. | You get 20\% discount. | |
Error log [ someVars] | Error log [ someVars] | |
Error log \[ C_LOG_2445] | Error log \[ C_LOG_2445] | |
Error log [[ C_LOG_2445] | Error log [[ C_LOG_2445] | In Ren’Py you can escape square bracket with double opening square bracket. |
Stand alone backslash will be interpolated: \\ \\\\ \\\\\\ \\\\\\\\ | Stand alone backslash will be interpolated: \ \\ \\\ \\\\ | Stand alone backslashes will be displayed as you will see in game. |
my name is \\{ john} | my name is \\{ john} | Any number of backslashes in front of non interpolated special chars will be left as is. |
my name is \\\{ john} | my name is \\\{ john} | Any number of backslashes in front of non interpolated special chars will be left as is. |
You got 100\\\\\\\\% discount! | You got 100\\\\\\\\% discount! | Any number of backslashes in front of non interpolated special chars will be left as is. |
You got 100\\\\\\\\ % discount! | You got 100\\\\ % discount! | Even though % is a non interpolated character, but backslashes and % are separated by a space. Thus backslashes are stand alone and will be interpolated. |
Howdy \( data) | Howdy ( data) | Bracket “( ” is not non-interpolated special chars. So Translator++ will interpolate the text as what you will see in-game. |
Howdy \\( data) | Howdy \( data) | Bracket “( ” is not non-interpolated special chars. So Translator++ will interpolate the text as what you will see in-game. |
Finding potential problem
You can use regular expression in search tool to find all unescaped special characters:
/[^\\]%|[^\\]\{|[^\\]\[/g
![](https://dreamsavior.net/wp-content/uploads/2023/02/2023-02-26-22_23_26-Find-and-replace-Translator.png)