Can't get string fallback to work on script assigned localized text

Hello! I’ve been struggling to get a fallback text to show and I’m not sure what I’m doing wrong. I’m trying to get the en-GB text for my 2nd and 3rd example to return the en values (seen below).


Whenever I get the text via script
(using table.GetEntry(entryName).GetLocalizedString(passedArgs);)
it returns null, when I’m expecting it to return the en values of the same key.

I can confirm that:

  • The en-GB Locale has the Metadata → Fallback Locale set to English (en)

  • I have “Use Fallback” set to true under the String Database dropdown in the Project Settings → Localization

  • The string value for the en-GB values is null in the Localization Table, there aren’t any spaces or hidden characters

  • The code is accessing the correct table and key

  • The text object I’m editing (TMPro) does not have a Localize String Event component on it

  • I’ve also tried it with the component, but since I’m setting the text via code I don’t see why I’d need it

I can provide more info as requested.
Thanks in advance!

Hi,
Are you able to share the project or file a bug report with an example project?

I’ve submitted a bug report for this under:
(Case 1355010) Localization Package - Can’t get string fallback to work on script assigned localized text

1 Like

For anyone looking at this/having the same issue, a ticket has been created under the Issue Tracker. It can be viewed here: Unity Issue Tracker - GetLocalizedString does not return fallback locale string when key value is empty

1 Like

Hey. I just took a look at the bug. I have responded with this:

After further investigation this behavior is actually by design.
I can see in your script UnityLocalizationManager you are using a list of LocalizedStringTable. A StringTable does not support fallbacks, it will always return the entry, even if it is empty. This is intentional as you may want to access metadata etc and StringTables are not aware of fallbacks. If you want to get the entry of a table with fallback support you should use one of the following:

  • LocalizedString.
  • LocalizationSettings.StringDatabase.GetTableEntry
  • LocalizationSettings.StringDatabase.GetLocalizedString

The fallback behavior is handled during the GetTableEntry stage. I updated your code and got it working with the following changes:

void LoadStrings(StringTable stringTable)
    {
        switch (currentTopic)
        {
            case 0:
                baseText.text = LocalizationSettings.StringDatabase.GetLocalizedString(stringTable.TableCollectionName, huckDialogueStarter + currentPage, arguments:testValues);
                return;
            case 1:
                baseText.text = LocalizationSettings.StringDatabase.GetLocalizedString(stringTable.TableCollectionName, cutsceneStarter + currentPage, arguments:testValues);
                return;
            case 2:
                baseText.text = LocalizationSettings.StringDatabase.GetLocalizedString(stringTable.TableCollectionName, itemData[currentPage], arguments:testValues);
                return;
        }
    }

So in short StringTables are not designed to do fallbacks. Fallbacks are handled by LocalizationSettings.StringDatabase.GetTableEntry.

1 Like

Ah, I understand now. Thank you!

1 Like