WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   How to spell out the result of plural UI escape sequences? (https://www.wowinterface.com/forums/showthread.php?t=59606)

LudiusMaximus 06-05-23 06:12 PM

How to spell out the result of plural UI escape sequences?
 
Hi, how can I get the interpreted version of a string including plural UI escape sequences?

Lua Code:
  1. local pluralString = "2 |4car:cars;"
  2. -- Do something with pluralString such that the result is what would be printed.
  3. local interpretedPluralString = ???
  4. assert(interpretedPluralString == "2 cars")
Thanks in advance! :)

SDPhantom 06-06-23 01:14 AM

I believe that's in the C-code renderer for FontStrings, not anything we have access to.

LudiusMaximus 06-06-23 02:35 PM

I found a way. :)

Lua Code:
  1. local converterTooltip = CreateFrame("GameTooltip", "converterTooltip", nil, "GameTooltipTemplate")
  2. local function CovertLine(line)
  3.   converterTooltip:ClearLines()
  4.   converterTooltip:AddLine(line)
  5.   return _G[converterTooltip:GetName().."TextLeft1"]:GetText()
  6. end

SDPhantom 06-06-23 10:23 PM

Doesn't it just spit back the UI escape code? You can expose it by doing something like :gsub("|","||"). What this does is escape the identifier so FontStrings will show the raw code.

LudiusMaximus 06-07-23 04:15 PM

Hm, it definitely works for the plural escape sequences. E.g. turning "2 |4car:cars;" into "2 cars".

SDPhantom 06-10-23 10:56 PM

Unexpected behavior, but my own tests are confirming it as well. I simplified it down to running through a FontString, which would be where the processing happens, stripping the overhead of the Tooltip code.
Lua Code:
  1. local ProcessLocalizedString; do--  Package persistent FontString object into function prototype's scope
  2.     local ConverterFontString=UIParent:CreateFontString(nil,"BACKGROUND","GameFontNormal");
  3.     function ProcessLocalizedString(text)
  4.         ConverterFontString:SetText(text);
  5.         return ConverterFontString:GetText();
  6.     end
  7. end

LudiusMaximus 06-11-23 02:38 PM

Nice, this is even better! Thank you! :)


All times are GMT -6. The time now is 11:19 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI