Search Unity

Bug Text Mesh Pro Ignores any "\n" present on string table entrys

Discussion in 'Localization Tools' started by Houtamelo, Oct 20, 2020.

  1. Houtamelo

    Houtamelo

    Joined:
    Jan 3, 2020
    Posts:
    31
    How to reproduce:

    1 - Create a new project.
    2 - Import the localization and text mesh pro packages.
    3 - Create a en(English) locale.
    4 - Create a string table.
    5 - Create a entry with the text : "My name is Bob\nIt's raining today".
    6 - Using the GameObject menu creator, select "UI/Text -TextMeshPro".
    7 - Select the newly created GameObject.
    8 - Click on the three dots to open the context menu.
    9 - Click on "Localize".
    10 - On the Localize String Event component, assign the entry created on step 5 to the String Reference variable.
    11 - Make sure the Locale Selector chooses the locale created on step 3.
    12 - Make sure Rich text is active on the TextMeshPro component.
    13 - Click on the Play button.

    The text shown on the screen will be "My name is Bob\nIt's raining today", when it should actually be:
    "My name is Bob
    It's raining today".

    PS: while on play mode, opening the "Extra Settings" tab on the TextMeshPro component, then toggling Rich text on and off will fix the text.

    I don't know if this is a problem with either the TextMeshPro or the Localization package, but i thought it would be a good idea to post this here since using "\n" works normally on TextMeshPro except when assigning the text through the Localize String Event component.
     
    karl_jones likes this.
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
  3. Metosian

    Metosian

    Joined:
    May 21, 2018
    Posts:
    14
    Was there any temp fix or hacky workaround for this issue while waiting for a fix?

    Its my personal biggest problem at the moment for changing over my project.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    I think I see the problem. When you type the value into a text field it is treated as a string literal.
    E.G \n becomes \\n.
    We need to convert them back. This is not done by default, we just pass the raw string.
    What you can do is mark the String as a Smart String and check the `Convert Character String Literals` option. This will convert \\ back into \.

    upload_2020-12-4_8-41-24.png

    Then it will work

    upload_2020-12-4_8-58-11.png
    upload_2020-12-4_8-58-19.png

    I spoke to the TMP developer. Seems like a long-standing issue in our TextFields. I'll look into supporting this.
     
    Last edited: Dec 4, 2020
    grrava likes this.