Search Unity

Resolved Localize arguments when formating

Discussion in 'Localization Tools' started by MUGIK, Apr 22, 2021.

  1. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Hello.
    I don't know how to google this correctly :)

    Consider the next example:
    String Tables ->
    - Dialogs ->
    -- say_hello = "Hello {Name}!"
    - Names ->
    -- name_tim - "Tim"
    -- name_bart - "Bart"

    The name to display will be chosen at runtime.
    For now, to display the correct name I need to wait for name to complete the GetLocalizedString async operation. It may need an entire frame because synchronous localization is not done yet.
    Then I need to wait for dialog to localize with the provided argument, which also may require the entire frame.
    Such behavior will produce noticeable text popping on the screen while localization is loading.

    What is the right way to localize arguments?
    Is there a way to localize like this: "Hello {Names.name_tim}!"?

    Ps
    Example is synthetic, actual use is a bit more complex.

    I've read all manual and didn't find anything related
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    You can mark your tables as preload https://docs.unity3d.com/Packages/com.unity.localization@0.11/manual/StringTables.html#preloading
    Look at the Samples we have, one shows how to wait for preloading to complete. Once preloading is done then strings will be returned during the same frame.
    Do you plan to localize the names? We do plan to support embedding localized values like this in the future, the synchronous support is the first step towards this.
    For now it sounds like preloading should solve your problems.
     
  3. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Yes, kinda

    That's good.

    It would be cool to have a setting to enable this on every table. But synchronous loading solves this problem better.

    Thanks!
     
    karl_jones likes this.
  4. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    @karl_jones It's the question for another thread but maybe it's quite simple to solve, so...

    I want my editor code to add entries to tables.
    The problem is that I need to call these 2 methods:
    Code (CSharp):
    1.  
    2. LocalizationEditorSettings.EditorEvents.RaiseTableEntryAdded(table, entry);
    3. LocalizationEditorSettings.EditorEvents.RaiseCollectionModified(null, table);
    But I can't, because they are internal methods.
    upload_2021-4-22_19-49-21.png

    I made a workaround in the past. I grabbed source code of the package and created the embedded package (placed source code inside Packages folder).
    This way I was able to create required code and call these internal methods.
    Now the problem with this solution is: I can't easily upgrade to a newer version of the localization package:(

    Is there a better way to properly add entries to tables?
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    Hi,
    Not at the moment but it's something we should support. I'm not sure exposing the events is the answer though, we should just update when you call the add method. Could you file a bug report?
     
  6. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Do I need to attach a repro project?
     
  7. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    Actually it's ok. I already have an idea for a fix so I'll raise the bug myself.
     
  8. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Thanks! I've almost filled up the report, but with my poor English it's hard to understand:)
    Glad I saw your message.

    Is there any timestamp when this could be fixed?
    Should I just again use the embedded package(with the new package version) or is it worth waiting?
     
  9. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    I think we will probably move some of those events directly into the tables and make them static so they can be called directly by the tables so you won't need to call them. So I would not use the events anymore and wait for the fix unless it's a problem in which case carry on calling the event for the moment. Hopefully we should have a new release in a few weeks and ill try and get this in with it
     
    MUGIK likes this.