Dynamic translation tutorial [DT] dynamic translation (dyntranslation) Minecraft Game

This tutorial is set by the author to use the CC By-NC-SA protocol.

In the internationalization of MOD, sometimes the hard -coding of part of the text cannot be simply international, which makes it difficult for internationalization to work. Generally, it is necessary to modify the source files.Sexual changes, and repeated work after updating.

The object of this MOD is the MOD Chinese personnel, and the corresponding use of the player is mainly for some of the international imperfect mods. At the same time, if you feel useful and energy to configure, I don't think there is any use of text translations that can be configured with a chat bar.

At the same time, in some entertainment directions, we need to replace the text in the game to achieve some special effects. At this time, we also need to modify the text in the game.

Dyntranslation replacement time node

Dyntranslation can achieve the above effect by runtime by the mapping table file.

To avoid unnecessary problems by introducing the time node, when dynamic translation is replaced, the configuration file position needs to be locked when the forge completes the initialization. Therefore, the configuration file cannot be loaded before the initialization is completed.Because a large number of dynamic numbers are generated at the loading time point, the translation queue is blocked and the CPU resources are consumed too high.

Therefore, before the initialization is completed, the dynamic translation itself cannot replace the text of the loading interface.

Replacement method

Through simple text replacement, the JSON file is used as a carrier here to read the mapping file;

The naming of the mapping file is as follows:

Father folder: Under the config folder of the MOD, the subfaming folder will be created as Dynranslation

Naming subfallets: All submisss must be named by the specifications of dyntranslation_ {name} .json, where {name} is available for all system files.

Replacement content: MAP nested form based on the standard format of JSON.

{{

// The name of the container (GUI), "*" means that it is not in any container (GUI), most of them in Tooltip

"*": {{

"§F Rotten Rotten §R": "§D Rotten Rotten §R",

"Armor": "",

"§7 when wearing on the leg:": "§8 when wearing on the leg"

},

// Here the character is displayed in Guienchantment

"Net.minecraft.client.gui.guienchantment": {{

"Enchanting": "Enchanting"

}

}

Impact

Because it is replaced by each frame, its performance effect is also proportional to the number of frames, and the final impact result is linear.Among them, the IO operation and word splitting operation is placed in other threads. The final performance impact comes from:

MAP's access performance

MAP size

Create destruction time of threads

The queue obstruction caused by the rapid generation of the new vocabulary

The latter two cannot be controlled by manual control. The average impact of the newly added content in the actual measurement is as follows: The following figure is as follows:

The average value is 3099.375, the outline is nanoseconds, and the magnitude of less than milliseconds can be considered to be ignored by the impact under sparse operation.

GUI (MC1.15.2)

GUI settings

As the name suggests ~

In the control, you can modify the key position to open the settings Z, start and stop recording screen character V.

Open and close the chat bar to translate Y.

Command (mc1.12.2)

/translation loadmap reload files;

/Translation StartRecord starts to capture characters. This command will record all the characters appearing in the game after your instruction is accepted, and the upper limit is 1000;/Translation Endrecord <-n> Stop the record and save, this command will stopIn the Dyntranslation of the Config file mentioned before, the file name is like record_ {mill_time} .json. is used to simplify output and delete the formatting character.

/translation enable enabled dynamic translation

/Translation Disable Turn off dynamic translation

/translation spilt enable word

/translation notspilt closed segmentation

The output file generated by Record is shown below:

{{

"*": {{

"§F Rotten Rotten §R": "§F §R",

"Armor": "",

"§7 When wearing on the leg:": "§7",

"When wearing on the leg": ""

},

"Net.minecraft.client.gui.guienchantment": {{

"Enchant": "",,,

"Item Bar": ""

}

}

Among them, § {char} is the format character, and two rows (if there is no conflict) by default. The previous behavior contains the record of the format character, and below is the record pair of the format character.

Because the Tooltip in Minecraft will contain format characters, it does not include format characters when it is displayed below the game interface when it is displayed in the Highlight.Record.For these situations, some processing can be replaced automatically. If you want to modify the original format display, you can modify it here to achieve different display effects.

Segmentation

I do n’t do natural language processing myself. Here I have split wording for English and Chinese. Words and language tests come from com.github.houbbb: segment and com.optimaize.languagedetector. The average speed of the word segmentation (accuracy rate accuracy rate (accuracy rate accuracy rateThe lowest) greedy algorithm, language testing uses 3 languages: Chinese, English, and Japanese, but for Japanese, the dictionary is too large (in fact, it is not great), it will not be added.

Words are mainly used to expand the mapping table to save search time, such as:

{{

"*": {{

"Gold ore": "Gold Flash",

"Grass": "" ",

"Grass": "s"

},

... ...

}

Translate the grass translation, which will also default to replace all "grass" phrases and sentences (provided by general matching).

Raise a chestnut:

If you do not reflect the "grass block" alone in your mapping table, then your "grass" text will be replaced with "艹 squares", as shown in the figure below

How to avoid this?

You can add a full matchmaker to your mapping file@

... ...

{{

"Iron Ore": "Iron Mine",

"@" ":" CAO ",

"@@" ":" @cao "

},

... ...

If you need@如果, you can turn the righteousness through@, as shown in the figure above.

Or you can also turn off the word split function, see the chapter command for details

Rendering position fine -tuning

Sometimes the central character that appears in the GUI, the length of the text after translation/replacement is different from the original text length, resulting in the misalignment of the central calculation in the original MOD.As shown below:

The Tile in the figure is shorter in English, and the Chinese representation may be longer, which causes the starting point to keep the starting point at the beginning of English when the Mod itself is calculated.

In order to solve this problem, the control field is added to the right translation part of each pair to fine -tune the rendering position [x (integer), y (integer), scale (decimal)]:

{{

"*": {{

"Gold ore": "Gold Flash"

},

"Net.minecraft.client.gui.guienchantment": {{

"Enchant": "{x = 1, y = 2, scale = auto} Enchanting test" // There are now 3 available attributes, x, y, scale;

}

}

Here is a fine -tuning of the enchantment. First of all, a automatic scaling is performed. This zoom will be adjusted according to the scaling ratio of the text "enchantment test" and the text "enchantment" of the replacement text.After replacement, the length becomes twice the original, so the position of the replacement text is 0.5 times the position after the displacement of the replacement text to maintain the position of 0.5 times to maintain the alignment of the original text:

In addition to the X, y in the same control character, in addition to filling in the specific value of the relative position, you can also use the value "Auto" to automatically adjust:

• For X, the automatic adjustment will align the post -text and replace the previous text, that is, the middle line of the two texts is aligned.

• For Y, because the height of the font is unchanged, the vertical center in the vertical direction is only the same through the zoom ratio.

When you do not fill in the control field (one or more), the default value of x is 0, the default value of y is 0, and the default value of scale is 1;

When your text itself starts with "{", "}", such as

"Formula": "{[(1-x)*y]}*z"

You can insert the empty control field at the beginning of the right to prevent rendering errors:

"Formula": "{} {[(1-x)*y]}*z"

Of course, all control fields must be at the beginning of replacing the text and end in a norm, otherwise it may cause unpredictable consequences.

For control fields, only right and right, and will not be nested as sub -words.

Digital content matching replacement

This is the record file of the memory prompt in the upper right corner when pressing the game F3. Use record to capture:

 "MEM: 8%319/3605MB": "" 

Now you want to replace it with Chinese:

 "MEM: {0}%{1}/{2} mb": "Memory: occupying percent/Pre> In the game, because each frame is searched and replaced, in order to reduce the overhead and prevent the performance of the game, the matching algorithm based on the automatic machine is not used, because when you have a lot of accessiblesSecondly, the characters we use linear complexity to split inspections For the above examples, we use the number and decimal point symbol (0-9 ,.) to split the string of the original text: {"Mem:", "8", "" "" "" ""%"," "," 319 ","/"," 3605 "," mb "}, recorded all possible numbers (here will merge all numbers and English half -号 —". ", That is, even if it is a shapeFor example, "0.1.1.3" or "." Or "..." will also be treated as a number): {0: "8", 1: "319", 2: 3605 "}, re -runningFormat your translation, fill in {0}, {1}, {2}, fill in the sequence of capture. Note that in the previous article, you must record the string from left to right from 0:

 "MEM: {1}%{0}/{2} mb": "Memory: occupying percent/pre>

The key value recorded above is not in order, so it is not possible!

Network item translation (VMC1.16.X-1.3.5-Beta and subsequent versions)

The neural network using data training in the field provides online translation services. The suspension pointer is on the items of the backpack or toolbar. Press the ALT by default to get the translation result. Only the name of the item is temporarily limited.

Internet translation chat bar (add V1.3)

There is nothing to say, the default key is home key, you can adjust in the control option to switch whether the chat bar is connected to the Internet. The translation results are determined according to the current language type you chose.It will be a bit slow.

Instructions /Translation Retainorg True Reserve the original sentence when the translation is opened.

Due to the lack of funds, there is no money to set up a translation server, and the free translation interface may be GG at any time, so the interface application of this function depends on the user to handle it. Here you only write a baidu translation interface. If you are free, you can go to baiduThe translation application interface is free, and then fills the ID and key into the following configuration files (this file will be automatically generated after the game initializes).

The game uses commands /translation loadconfig actively to load configuration (in order to smoothly upgrade to other versions in the future, the configuration file system comes with MINECRAFT is not used, so please actively load the configuration file after modification).

Config.json (located in config/dyntranslation/, the same mapping file, please fill in NAME, ID, and key) according to the following examples)

{{

"Chattranslate": True,

"Enable": true,

"SPILTWORDS": true,

"Retainorg": false,

"Translateapis": [[

{{

"Name": "baidu", // now only support BAIDU's translation API

"ID": "********************", // For baidu translation, fill in your appid here

"Key": "*************************************************************************************************************************************************************************************************************************************************************," //

}

]

}

If it is covered with the original text, the original sentence will not be kept, and most of the time will not be scaled, but if the original sentence is opened, the sentence is too long, and the words may not be seen under the screen. There is no way for the time being.Tested better fonts, that font has been smooth and anti -aliasing (but may not be compatible).Image-20200413131525429

Deficiency and defects

Dynamic translation cannot be completed:

Non -Fontrenderer's text, such as text in the material, text in the picture, and text in non -OpenGL environments.

The background box during rendering, or the background length of the text editing, is shown in the figure below.

Some components that comes with Minecraft and editing components in MOD will be mistakenly rendered (such as editing column, search bar and waiting for you to enter the components of the character). You enter the characters you definedThe mapping is your translation/replacement result.

Only support Chinese and English words.

... ...

ing reder result show

Precautions

On the Windows platform, all JSON files are encoded in ANSI, otherwise there will be loading failures or garbleds.As shown below:

Image-20200409194226293