Thread Tools Display Modes
07/27/22, 03:10 PM   #1
trollusk
AddOn Author - Click to view addons
Join Date: Nov 2020
Posts: 8
Force UI to use changed localization string?

If I change a localization string in-game, is there a way to force the UI elements that use the string, to update themselves?

Specifically, I can successfully change the string for the "N" label on the compass with:

Lua Code:
  1. GetString(SI_COMPASS_NORTH_ABBREVIATION)    -- returns "N"
  2. SafeAddString(SI_COMPASS_NORTH_ABBREVIATION, " ", 10)
  3. GetString(SI_COMPASS_NORTH_ABBREVIATION)    -- returns " "

However the compass does not update itself to use the changed string. This does not change if I /reloadui or change zones, etc.
  Reply With Quote
07/28/22, 02:47 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,962
No there isn't, you need to make sure the text is updated before it is used at any control at the UI.
e.g. try to change the constant early before your EVENT_ADD_ON_LOADED.
But it may be that this still is too late as vanilla code lua files always get loaded before your addon files, including your addon files (e.g. via the txt manifest loaded language/Transaltion files) loaded before event_Add_on_loaded.

The text is just read from the constant and then passed to a label control e.g.. The label is not touched if you change the constant!
You need to update the label again via labelControl:SetText(GetString(SI_CONSTANT_HERE)) to make it show the updated text.

So I guess in the end you need to update the label controls at the compass manually via your addon, to show your new text.

Last edited by Baertram : 07/28/22 at 02:52 AM.
  Reply With Quote
07/28/22, 03:36 AM   #3
trollusk
AddOn Author - Click to view addons
Join Date: Nov 2020
Posts: 8
Thanks. Using zgoo I have found that ZO_CompassContainer controls all the compass "contents" (pins and N/S/E/W labels). However, I can't find any child label controls. ZO_CompassContainer has 7 child controls, all of which are custom compass pins that my mod has added. It does not seem to have children for the normal game pins (quest markers etc) or for the direction labels.

Strangely ZO_CompassContainer has 99 children, but all of them are nil except numbers 75-81, which are custom pins as described above. I guess this the large number of empty child slots is in case the compass gets very crowded.
  Reply With Quote
07/28/22, 06:32 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,962
https://github.com/esoui/esoui/blob/...mpass.lua#L519

Searching for SI_COMPASS_NORTH_ABBREVIATION brought me here.
So you should do the same as this function seems to do at vanilla code.

Lua Code:
  1. local fontTouse = IsInGamepadPreferredMode() and "ZoFontGamepadBold34" or "ZoFontHeader4"
  2. COMPASS:SetCardinalDirections(fontTouse)
  Reply With Quote
07/28/22, 08:35 PM   #5
trollusk
AddOn Author - Click to view addons
Join Date: Nov 2020
Posts: 8
You are a star!

Passing nonsense as a font name causes the label to be invisible:

Lua Code:
  1. ZO_CompassContainer:SetCardinalDirection(GetString(SI_COMPASS_NORTH_ABBREVIATION), "zzzzzzzzz", CARDINAL_DIRECTION_NORTH)
  Reply With Quote
07/29/22, 01:27 AM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,962
Keep in mind that changing the SI_ constants of the vanilla game could make other addons break which rely on it, via string comparison e.g.

Not applicable here I guess but for e.g. some menu entries the descriptors of the menu buttons use those SI_ constants and the only way to identify the ciorrect button/tab would be this constants. And they could be re-used the same time at other coding you would need to change (e.g. the word "Research" or somethign similar).
So if you change them you'd change the menu button too by accident (depends on if the menu button is created as the menu opens, then it would be changed, or even before as vanilla code was loaded already -> Gamepad input UI often does create the stuff as it opens!)

At best create your own MY_ADDON_CONSTANT = "String here" as only vanilla game string constants should start with SI_, and then apply them ONLY THERE where really needed, so all other constants and code and addons still run fine.

That said, in your example here, you could just check the function I've linked above and rebuild it.
Lua Code:
  1. --original function code
  2. function Compass:SetCardinalDirections(font)
  3.     self.container:SetCardinalDirection(GetString(SI_COMPASS_NORTH_ABBREVIATION), font, CARDINAL_DIRECTION_NORTH)
  4.     self.container:SetCardinalDirection(GetString(SI_COMPASS_EAST_ABBREVIATION), font, CARDINAL_DIRECTION_EAST)
  5.     self.container:SetCardinalDirection(GetString(SI_COMPASS_WEST_ABBREVIATION), font, CARDINAL_DIRECTION_WEST)
  6.     self.container:SetCardinalDirection(GetString(SI_COMPASS_SOUTH_ABBREVIATION), font, CARDINAL_DIRECTION_SOUTH)
  7. end
  8.  
  9.  
  10. --Your function:
  11. local function MyUpdateCompassCardinalDirections(font)
  12.     local compassContainer = COMPASS.container
  13.     compassContainer:SetCardinalDirection(GetString(MY_ADDON_COMPASS_NORTH_ABBREVIATION), font, CARDINAL_DIRECTION_NORTH)
  14.     compassContainer:SetCardinalDirection(GetString(MY_ADDON_EAST_ABBREVIATION), font, CARDINAL_DIRECTION_EAST)
  15.     compassContainer:SetCardinalDirection(GetString(MY_ADDON_WEST_ABBREVIATION), font, CARDINAL_DIRECTION_WEST)
  16.     compassContainer:SetCardinalDirection(GetString(MY_ADDON_SOUTH_ABBREVIATION), font, CARDINAL_DIRECTION_SOUTH)
  17. end

This would keep the original string constant alive for other addons use!
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Force UI to use changed localization string?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off