Search Unity

Question How to get entry by key without specifying table reference?

Discussion in 'Localization Tools' started by ArikaHoshino, Apr 2, 2023.

  1. ArikaHoshino

    ArikaHoshino

    Joined:
    Sep 14, 2020
    Posts:
    32
    Hi:
    I tried GetLocalizedString without providing a table reference and it will not found translation for the key,
    is this a bug or I am doing somthing wrong?
    Thanks for helps!


    Code (CSharp):
    1.  
    2. private void Start()
    3. {
    4.     var withTableRef = LocalizationSettings.StringDatabase.GetLocalizedString("UI", "GameTitle");
    5.     Debug.Log("withTableRef " + withTableRef);
    6.  
    7.     var withoutTableRef = LocalizationSettings.StringDatabase.GetLocalizedString("GameTitle");
    8.     Debug.Log("withoutTableRef " + withoutTableRef);
    9. }
    10.  
    Run result

    upload_2023-4-3_5-30-8.png

    StringTable "UI", it is in "DefaultStringTableCollection" group
    upload_2023-4-3_5-30-27.png

    Localization Setting
    upload_2023-4-3_5-31-57.png
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    You need to change the Default Table Reference in the localization settings. At the moment it's looking for a table called DefaultStringTableCollection, change it to UI

    upload_2023-4-3_5-31-57~2.png
     
  3. ArikaHoshino

    ArikaHoshino

    Joined:
    Sep 14, 2020
    Posts:
    32
    Thanks, after I change the default to "UI"it works. But I tried to change the default table Reference to other string table in the same group, i.e. "Items" string table, and GetLocalizedString() cannot find the translation again.

    Is there a way to configure the GetLocalizedString() to lookup all string tables in the same group?
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    I'm not sure I understand. You changed it to a different table and now it doesn't work? Did you do this whilst in play mode?
    What do you mean by same group?
     
  5. ArikaHoshino

    ArikaHoshino

    Joined:
    Sep 14, 2020
    Posts:
    32
    upload_2023-4-3_23-34-3.png

    Thanks for the help!

    There are multiple string tables under “DefaultStringTableCollection” group, i.e. string table "Items" and string table "UI" and string table "Buildings" (shown in screenshot above, they are all under “DefaultStringTableCollection” group).

    The problem is, If I set Default Table Collection Name as "UI", by using "LocalizationSettings.StringDatabase.GetLocalizedString("GameTitle");", I can get the entry of "GameTitle", but if I set the Default Table Collection Name as "Items", it would not find the entry of "GameTitle".

    The goal I want to achive is, I would call "LocalizationSettings.StringDatabase.GetLocalizedString({Key});", without specifying a table name, I still can get the entry no matter which string table I set as default. i.e. even I set the Default Table Collection Name as "Items", not "UI", I can still get entry "GameTitle".
     
  6. ArikaHoshino

    ArikaHoshino

    Joined:
    Sep 14, 2020
    Posts:
    32
    The screenshot I took is from Inspector window after selecting a String Table Collection Asset in Project Window.
     
  7. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    The group is only used when showing the selection menu, so we can group them on the menu. We don't do anything else with it.
    The default table collection name can only be a single table collection, it's cant be a group. If you don't want to specify the table then I would put all the entries into a single table, otherwise it's unavoidable and you will need to specify a table.
     
  8. ArikaHoshino

    ArikaHoshino

    Joined:
    Sep 14, 2020
    Posts:
    32
    No problem, thanks
     
    karl_jones likes this.