bbepis / XUnity.AutoTranslator

MIT License
2.01k stars 293 forks source link

Problem with font resizing #436

Open QY-Dong opened 1 year ago

QY-Dong commented 1 year ago

I edited this issue for so many times as I try to find a solution

I autotranslated a game from English into Chinese. It worked well, except that there's something wrong with the font size. Sometimes the translated text needs more space than the original text (like in “Bravo!=太棒了!” it only displays “了!”)

I tried to change

OverrideFontSize=xx #I tried some numbers
EnableUIResizing=True
ForceUIResizing=True

but didn't work (I don't really know what they mean).

I copied the solution in this issue, for the game The Forest of Love: https://github.com/bbepis/XUnity.AutoTranslator/issues/57 but it didn't work either (I think I did exactly what it said. And I think our problems are exactly the same)

  1. melonloader 0.5.7 open-beta
  2. download the pioneer zip and unpack
  3. download the resizer zip ...

I read this: https://github.com/bbepis/XUnity.AutoTranslator#ui-font-resizing but don't really know how to change resizer.txt. I don't fully understand what the code means. Do I need to do some change with the resizer.txt downloaded from this https://github.com/bbepis/XUnity.AutoTranslator/issues/57 issue, for The Forest of Love?

/Canvas=ChangeFontSizeByPercentage(0.5)
/Canvas/SplashNSFWWarning=ChangeFontSizeByPercentage(0.4)
/Canvas/SplashDeviceSupport=ChangeFontSizeByPercentage(0.4)
/Canvas/PlayMenu=ChangeFontSizeByPercentage(0.5)
/LevelSingletons/SingletonPrefabsBundle(Clone)/PauseScreenUI/Pause Screen Ui Panel=ChangeFontSizeByPercentage(0.5)
/LevelSingletons/SingletonPrefabsBundle(Clone)/MasterLog/Inventory/Canvas/Inventory UI/ItemInfoMultilineFixedWidths/ItemTitleText=ChangeFontSizeByPercentage(0.7)
/LevelSingletons/SingletonPrefabsBundle(Clone)/MasterLog/Inventory/Canvas/Inventory UI/ItemInfoMultilineFixedWidths/ItemDescriptionText=ChangeFontSizeByPercentage(0.7)
/LevelSingletons/SingletonPrefabsBundle(Clone)/MasterLog/QuestLog/QuestLog UI=ChangeFontSizeByPercentage(0.7)
/LevelSingletons/SingletonPrefabsBundle(Clone)/MasterLog/CritterLog/CritterLog UI=ChangeFontSizeByPercentage(0.7)
/LevelSingletons/SingletonPrefabsBundle(Clone)=ChangeFontSizeByPercentage(0.55)

like do I need to change the path? I wrote [Behaviour] EnableTextPathLogging=True in Config.ini, but don't know where to check the logged out path

[23:13:35.897] ------------------------------
[23:13:35.898] MelonLoader v0.5.7 Open-Beta
[23:13:35.898] OS: Windows 10
[23:13:35.899] Hash Code: 49999848531024954985654485098975250521005157544948501005510199495356
[23:13:35.899] ------------------------------
[23:13:35.899] Game Type: MonoBleedingEdge
[23:13:35.900] Game Arch: x64
[23:13:35.900] ------------------------------
[23:13:35.901] Core::BasePath = D:\Games\The Procession to Calvary-resize
[23:13:35.901] Game::BasePath = D:\Games\The Procession to Calvary-resize
[23:13:35.901] Game::DataPath = D:\Games\The Procession to Calvary\The Procession to Calvary_Data
[23:13:35.902] Game::ApplicationPath = D:\Games\The Procession to Calvary\The Procession to Calvary.exe

[23:13:36.211] ------------------------------
[23:13:36.212] Game Name: The Procession to Calvary
[23:13:36.213] Game Developer: Joe Richardson
[23:13:36.217] Unity Version: 2019.4.18f1
[23:13:36.217] Game Version: 1.0.0
[23:13:36.218] ------------------------------

[23:13:36.702] Preferences Loaded!

[23:13:36.737] Loading Plugins from 'D:\Games\The Procession to Calvary-resize\Plugins'...
[23:13:36.740] 0 Plugins loaded.

[23:13:37.829] [MelonStartScreen] Initializing...
[23:13:37.876] [MelonStartScreen] Using Start Screen Theme: "Default"

[23:13:39.743] Loading Mods from 'D:\Games\The Procession to Calvary-resize\Mods'...
[23:13:39.788] ------------------------------
[23:13:39.823] Melon Assembly loaded: '.\Mods\FontOverride.dll'
[23:13:39.825] SHA256 Hash: '004268a086d947a6c135a30ae5d3f8bef18899f85eb581645b90c91b115a16fa'
[23:13:39.830] Melon Assembly loaded: '.\Mods\XUnity.AutoTranslator.Plugin.MelonMod.dll'
[23:13:39.831] SHA256 Hash: '5ddbba13eb29cad6bc3859a3c5e3cba9c3214d7925312494ed3f1b06f224033b'

[23:13:39.906] [WARNING] Some Melons are missing dependencies, which you may have to install.
If these are optional dependencies, mark them as optional using the MelonOptionalDependencies attribute.
This warning will turn into an error and Melons with missing dependencies will not be loaded in the next version of MelonLoader.
- 'FontOverride' is missing the following dependencies:
    - 'Newtonsoft.Json' v12.0.0.0
[23:13:39.927] ------------------------------
[23:13:39.927] FontOverride v0.0.1
[23:13:39.929] by rfcclub
[23:13:39.933] Assembly: FontOverride.dll
[23:13:39.935] ------------------------------
[23:13:39.941] ------------------------------
[23:13:39.941] XUnity Auto Translator v5.3.0
[23:13:39.944] by gravydevsupreme
[23:13:39.948] Assembly: XUnity.AutoTranslator.Plugin.MelonMod.dll
[23:13:39.950] ------------------------------
[23:13:39.952] ------------------------------
[23:13:39.954] 2 Mods loaded.

[23:13:39.975] Support Module Loaded: D:\Games\The Procession to Calvary-resize\MelonLoader\Dependencies\SupportModules\Mono.dll
[23:13:50.521] [FontOverride] -------------method found SetText
[23:13:50.545] [FontOverride] -------------method found SetTranslatedText
[23:13:50.553] [FontOverride] -------------method found GetOrCreateOverrideFontTextMeshPro
[23:13:50.664] Screen resolution determine to be: 1920x1080
[23:13:50.667] Version of TextMesh Pro: 1.4.0.
[23:13:50.743] Hooked UnityEngine.UI.Text.set_text through Harmony hooks.
[23:13:50.756] Hooked UnityEngine.UI.Text.OnEnable through Harmony hooks.
[23:13:50.764] Hooked TMPro.TextMeshProUGUI.OnEnable through Harmony hooks.
[23:13:50.774] Hooked TMPro.TextMeshPro.OnEnable through Harmony hooks.
[23:13:50.782] Hooked TMPro.TMP_Text.set_text through Harmony hooks.
[23:13:50.793] Hooked TMPro.TMP_Text.SetText through Harmony hooks.
[23:13:50.801] Hooked TMPro.TMP_Text.SetText through Harmony hooks.
[23:13:50.813] Hooked TMPro.TMP_Text.SetText through Harmony hooks.
[23:13:50.834] Hooked TMPro.TMP_Text.SetCharArray through Harmony hooks.
[23:13:50.857] Hooked TMPro.TMP_Text.SetCharArray through Harmony hooks.
[23:13:50.878] Hooked TMPro.TMP_Text.SetCharArray through Harmony hooks.
[23:13:50.889] Hooked UnityEngine.GUI.BeginGroup through Harmony hooks.
[23:13:50.896] Hooked UnityEngine.GUI.DoLabel through Harmony hooks.
[23:13:50.908] Hooked UnityEngine.GUI.DoButton through Harmony hooks.
[23:13:50.928] Hooked UnityEngine.GUI.DoButtonGrid through Harmony hooks.
[23:13:50.943] Hooked UnityEngine.GUI.DoToggle through Harmony hooks.
[23:13:50.957] Hooked UnityEngine.GUI.Box through Harmony hooks.
[23:13:50.976] Hooked UnityEngine.GUI.DoRepeatButton through Harmony hooks.
[23:13:50.986] Hooked UnityEngine.GUI.DoModalWindow through Harmony hooks.
[23:13:51.002] Hooked UnityEngine.GUI.DoWindow through Harmony hooks.
[23:13:51.142] [WARNING] Cannot use same fallback endpoint as primary.
[23:13:51.143] Disabling certificate checks for endpoints because of configuration.
[23:13:51.157] Probing whether OnLevelWasLoaded or SceneManager is supported in this version of Unity. Any warnings related to OnLevelWasLoaded coming from Unity can safely be ignored.
[23:13:51.160] SceneManager is supported in this version of Unity.
[23:13:51.181] Attempting to load TextMesh Pro font from asset bundle.
[23:13:51.451] Loaded TextMesh Pro font uses version: 1.1.0
**[23:13:51.455] [WARNING] TextMesh Pro version mismatch. Font asset version: 1.1.0, TextMesh Pro version: 1.4.0**
[23:13:51.472] [FontOverride] Modify TMP Setting
**[23:13:51.485] [ERROR] An error occurred while trying to load fallback font for TextMesh Pro.**

System.MissingMethodException: TMPro.TMP_FontAsset TMPro.TMP_FontAsset.CreateFontAsset(UnityEngine.Font,int,int,UnityEngine.TextCore.LowLevel.GlyphRenderMode,int,int,TMPro.AtlasPopulationMode)

  at FontOverride.TMPSettingPatch.Postfix (UnityEngine.Object& __result) [0x0003b] in <5a97424209c24f5a8fe9476602f85fbb>:0 

  at DMD<>?-274930432.NativeDetour_Wrapper<UnityEngine.Resources::Load>?0 (System.String path, System.Type systemTypeInstance) [0x00025] in <d8a9696fa0d4443f96936882ec5028a0>:0 

  at UnityEngine.Resources.Load[T] (System.String path) [0x00001] in <12e76cd50cc64cf19e759e981cb725af>:0 

  at TMPro.TMP_Settings.get_instance () [0x0000d] in <833ff524c1474dceb00c07f026e5da3d>:0 

  at TMPro.TMP_Settings.get_fallbackFontAssets () [0x00000] in <833ff524c1474dceb00c07f026e5da3d>:0 

  at DMD<>?-274930432.FastReflection<TMPro.TMP_Settings.get_fallbackFontAssets> (System.Object , System.Object[] ) [0x00000] in <a23b5907f7354045bf28fe23808a076a>:0 

  at XUnity.Common.Utilities.CachedProperty.Get (System.Object instance) [0x0000a] in <5f5c77dda5b3447393f01a7ca8c77c71>:0 

  at XUnity.AutoTranslator.Plugin.Core.AutoTranslationPlugin.LoadFallbackFont () [0x0004e] in <1a6ac5ec5b0a4c7096c6ff8454095a49>:0 
[23:13:51.506] Loaded resize command text files.
[23:13:51.513] --- Loading Global Translations ---
[23:13:51.527] Loaded translation text files (took 0.01 seconds)
[23:13:51.543] Created variation translations (took 0 seconds)
[23:13:51.551] Created token translations (took 0 seconds)
[23:13:51.555] Loaded XUnity.AutoTranslator into Unity [2019.4.18f1] game.
[23:13:51.776] Skipping plugin scan because no plugin-specific translations has been registered.
[23:13:53.759] [FontOverride] System.MissingMethodException: TMPro.TMP_FontAsset TMPro.TMP_FontAsset.CreateFontAsset(UnityEngine.Font,int,int,UnityEngine.TextCore.LowLevel.GlyphRenderMode,int,int,TMPro.AtlasPopulationMode)

  at FontOverride.FontStore.SetTranslatedText (System.String translatedText, System.Boolean init) [0x00014] in <5a97424209c24f5a8fe9476602f85fbb>:0 
[23:13:53.763] [FontOverride] System.MissingMethodException: TMPro.TMP_FontAsset TMPro.TMP_FontAsset.CreateFontAsset(UnityEngine.Font,int,int,UnityEngine.TextCore.LowLevel.GlyphRenderMode,int,int,TMPro.AtlasPopulationMode)

  at FontOverride.FontStore.SetTranslatedText (System.String translatedText, System.Boolean init) [0x00014] in <5a97424209c24f5a8fe9476602f85fbb>:0 
[23:13:53.766] [FontOverride] System.MissingMethodException: TMPro.TMP_FontAsset TMPro.TMP_FontAsset.CreateFontAsset(UnityEngine.Font,int,int,UnityEngine.TextCore.LowLevel.GlyphRenderMode,int,int,TMPro.AtlasPopulationMode)

...

Is there a way to solve this? I don't know the easier way to change the font size in _AutoGeneratedTranslations.txt either. Is New Game=<size=50%>新游戏</size>supposed to work?

I0lOl0I commented 1 year ago

you are doing it completely wrong. copy paste the primer from a different game will not work at all.

you need to enable EnableTextPathLogging in your config, install the RuntimeUnityEditor plugin, start the game and now you need to check the log to find what primer used in the specific sentence to control the text. then you copy and save the path to the resizer and set the desired size.

you can also check here https://github.com/bbepis/XUnity.AutoTranslator/issues/366#issuecomment-1477144926

QY-Dong commented 1 year ago

you are doing it completely wrong. copy paste the primer from a different game will not work at all.

you need to enable EnableTextPathLogging in your config, install the RuntimeUnityEditor plugin, start the game and now you need to check the log to find what primer used in the specific sentence to control the text. then you copy and save the path to the resizer and set the desired size.

you can also check here #366 (comment)

Thank you. I figured out how to check out the text path following your instruction. It worked well in the game The West of Loathing (I can see the path of each translated text in log file). However, in the other game, when I enable EnableTextPathLogging=True, it only translates without showing the translated text in the game (there are still translations in the autotranslation file. and it will work again if I turn it into False). It's the same case for both bepinex and melonloader. so is there another way to know the path of those text?

Here's the error when I enable EnableTextPathLogging=True

[Error :XUnity.AutoTranslator] An error occurred while setting text on a component. System.ArgumentException: Expected object to be a GameObject or component. Parameter name: obj at XUnity.AutoTranslator.Plugin.Core.Extensions.ComponentExtensions.GetAssociatedGameObject (System.Object obj) [0x0001d] in <1a6ac5ec5b0a4c7096c6ff8454095a49>:0 at XUnity.AutoTranslator.Plugin.Core.Extensions.ComponentExtensions.GetPathSegments (System.Object obj) [0x00000] in <1a6ac5ec5b0a4c7096c6ff8454095a49>:0 at XUnity.AutoTranslator.Plugin.Core.Extensions.ComponentExtensions.GetPath (System.Object obj) [0x00006] in <1a6ac5ec5b0a4c7096c6ff8454095a49>:0 at XUnity.AutoTranslator.Plugin.Core.AutoTranslationPlugin.SetText (System.Object ui, System.String text, System.Boolean isTranslated, System.String originalText, XUnity.AutoTranslator.Plugin.Core.TextTranslationInfo info) [0x00033] in <1a6ac5ec5b0a4c7096c6ff8454095a49>:0

7AllenWalker7 commented 11 months ago

you are doing it completely wrong. copy paste the primer from a different game will not work at all.

you need to enable EnableTextPathLogging in your config, install the RuntimeUnityEditor plugin, start the game and now you need to check the log to find what primer used in the specific sentence to control the text. then you copy and save the path to the resizer and set the desired size.

you can also check here #366 (comment)

Hello. Can you have sample for this? [Info :XUnity.AutoTranslator] Setting text on 'TMPro.TextMeshProUGUI' to '> Сервер' [Info :XUnity.AutoTranslator] Path : /Canvas/MenuContainer/MainButtons/HostButton/Text (TMP) [Info :XUnity.AutoTranslator] Level: 2 [Info :XUnity.AutoTranslator] Setting text on 'TMPro.TextMeshProUGUI' to '> Авторы' [Info :XUnity.AutoTranslator] Path : /Canvas/MenuContainer/MainButtons/Credits/Text (TMP) [Info :XUnity.AutoTranslator] Level: 2 [Info :XUnity.AutoTranslator] Setting text on 'TMPro.TextMeshProUGUI' to '> Настройки' [Info :XUnity.AutoTranslator] Path : /Canvas/MenuContainer/MainButtons/SettingsButton/Text (TMP) [Info :XUnity.AutoTranslator] Level: 2 [Info :XUnity.AutoTranslator] Setting text on 'TMPro.TextMeshProUGUI' to '> Подключиться' [Info :XUnity.AutoTranslator] Path : /Canvas/MenuContainer/MainButtons/JoinACrew/Text (TMP) [Info :XUnity.AutoTranslator] Level: 2 [Info :XUnity.AutoTranslator] Setting text on 'TMPro.TextMeshProUGUI' to '> Выход' [Info :XUnity.AutoTranslator] Path : /Canvas/MenuContainer/MainButtons/QuitButton/Text (TMP) I create fileresizer.txt and add

/Canvas/MenuContainer/MainButtons/HostButton/Text=ChangeFontSizeByPercentage(0.5)

but its not work(

Atamg1994 commented 11 months ago

you are doing it completely wrong. copy paste the primer from a different game will not work at all. you need to enable EnableTextPathLogging in your config, install the RuntimeUnityEditor plugin, start the game and now you need to check the log to find what primer used in the specific sentence to control the text. then you copy and save the path to the resizer and set the desired size. you can also check here #366 (comment)

Hello. Can you have sample for this? [Info :XUnity.AutoTranslator] Setting text on 'TMPro.TextMeshProUGUI' to '> Сервер' [Info :XUnity.AutoTranslator] Path : /Canvas/MenuContainer/MainButtons/HostButton/Text (TMP) [Info :XUnity.AutoTranslator] Level: 2 [Info :XUnity.AutoTranslator] Setting text on 'TMPro.TextMeshProUGUI' to '> Авторы' [Info :XUnity.AutoTranslator] Path : /Canvas/MenuContainer/MainButtons/Credits/Text (TMP) [Info :XUnity.AutoTranslator] Level: 2 [Info :XUnity.AutoTranslator] Setting text on 'TMPro.TextMeshProUGUI' to '> Настройки' [Info :XUnity.AutoTranslator] Path : /Canvas/MenuContainer/MainButtons/SettingsButton/Text (TMP) [Info :XUnity.AutoTranslator] Level: 2 [Info :XUnity.AutoTranslator] Setting text on 'TMPro.TextMeshProUGUI' to '> Подключиться' [Info :XUnity.AutoTranslator] Path : /Canvas/MenuContainer/MainButtons/JoinACrew/Text (TMP) [Info :XUnity.AutoTranslator] Level: 2 [Info :XUnity.AutoTranslator] Setting text on 'TMPro.TextMeshProUGUI' to '> Выход' [Info :XUnity.AutoTranslator] Path : /Canvas/MenuContainer/MainButtons/QuitButton/Text (TMP) I create fileresizer.txt and add

/Canvas/MenuContainer/MainButtons/HostButton/Text=ChangeFontSizeByPercentage(0.5)

but its not work(

The resize did not work for you because the path is not fully specified, you wrote part of the name Elsenta Let me give you an example /main/MainButtons/text= - the path can be like this maybe so /main/Main buttons/text element (tmp)= boring-sounding component name in full but we can allow the last full release /main/Main Buttons=-thus you don’t need the full path to write a resize that can be transferred to all menu items if you apply it to the parent element

Need /Canvas/MenuContainer/MainButtons/HostButton/Text (TMP)=ChangeFontSizeByPercentage(0.5) -- full path Or /Canvas/MenuContainer/MainButtons/HostButton=ChangeFontSizeByPercentage(0.5) -- Or /Canvas/MenuContainer/MainButtons=ChangeFontSizeByPercentage(0.5) -- resize all buttons in container MainButtons

7AllenWalker7 commented 11 months ago

I try /Canvas/MenuContainer/MainButtons/HostButton and /Canvas/MenuContainer/MainButtons not work. filename resizer.txt may be need edit... Where should this file be located?

Atamg1994 commented 11 months ago

I try /Canvas/MenuContainer/MainButtons/HostButton and /Canvas/MenuContainer/MainButtons not work. filename resizer.txt may be need edit... Where should this file be located?

where your translated texts are!

7AllenWalker7 commented 11 months ago

It's there, but it doesn't work.

Atamg1994 commented 11 months ago

It's there, but it doesn't work.

that means then you're probably doing something wrong... I can't give you any advice here, I don't know, I'll have to install the game and check it out..

7AllenWalker7 commented 11 months ago

how many line in resizer.txt possibly?

Atamg1994 commented 11 months ago

how many line in resizer.txt possibly?

how many size changes will you write as many lines the extra ones need to be removed remove empty lines

7AllenWalker7 commented 11 months ago

I mean, I can write this? In resizer.txt

/Systems/UI/Canvas/PlayerCursor/InteractText=ChangeFontSizeByPercentage(50);
/Systems/UI/Canvas/IngamePlayerHUD=ChangeFontSizeByPercentage(50);
Atamg1994 commented 11 months ago

resizer.txt Here's an example from another game of what the file should look like

Atamg1994 commented 11 months ago

I mean, I can write this? In resizer.txt

/Systems/UI/Canvas/PlayerCursor/InteractText=ChangeFontSizeByPercentage(50);
/Systems/UI/Canvas/IngamePlayerHUD=ChangeFontSizeByPercentage(50);

No you not correct 50% = 0.5 100%= 1 ...

7AllenWalker7 commented 11 months ago

I checked it on another text, it works. but doesn’t want menu items) /Canvas/MenuContainer/MainButtons/HostButton

I0lOl0I commented 11 months ago

I checked it on another text, it works. but doesn’t want menu items) /Canvas/MenuContainer/MainButtons/HostButton

If you want to find a specific path of text, you can change the translated text to something completely wrong to make it easier for you to search in the log, for example, change "Main Menu" button in the translation file to doggy.

I don't recommend the ChangeFontSizeByPercentage command, as it is buggy sometimes and causes further text resizing on translation file reload.