ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Tutorials & Other Helpful Info (https://www.esoui.com/forums/forumdisplay.php?f=172)
-   -   Findig "ingame used" text values for reuse in your addons (https://www.esoui.com/forums/showthread.php?t=6725)

Baertram 01/05/17 08:59 AM

Findig "ingame used" text values for reuse in your addons
 
Hey there,

after I've had to learn this in the past I'd like to share the knowledge about the ingame texts (strings) that we are able to reuse in our addons, and thus don't need to re-translate them with our own texts.

Find ingame used strings
To find some ingame texts you are able to search them in the ESOUI source code. The filename is located here:
Code:

esoui\ingamelocalization\localizegeneratedstrings.lua
-Download the esoui source code here for your local copy-

-Or browse through online at github-
-> -Direct link to the localizations file "localizegeneratedstrings.lua"-



Use ingame used strings in your addon
To use a string from the lua file you need the unique constant name from the array
"EsoStrings"

Code:

EsoStrings =
{
    "", -- Sync string for ClientKeyboardStrings first entry
    "English", -- SI_INPUT_LANGUAGE_ENGLISH
    "German", -- SI_INPUT_LANGUAGE_GERMAN
    "French", -- SI_INPUT_LANGUAGE_FRENCH
    "Japanese", -- SI_INPUT_LANGUAGE_JAPANESE
    "Unknown", -- SI_INPUT_LANGUAGE_UNKNOWN
    "Input Language Changed to: <<1>>", -- SI_ALERT_INPUT_LANGUAGE_CHANGE
    "Current Keyboard Layout: <<1>>", -- SI_KEYBIND_CURRENT_KEYBOARD_LAYOUT
    "Lua is reaching its memory limit.  You should consider disabling some addons and reloading the UI.", -- SI_LUA_LOW_MEMORY
    "Graphics Options", -- SI_WINDOW_TITLE_GRAPHICS_OPTIONS
    "Low", -- SI_LOW
    "High", -- SI_HIGH
...
}

The constants are written as a comment (starting with --) behind each string, e.g. SI_INPUT_LANGUAGE_ENGLISH or SI_WINDOW_TITLE_GRAPHICS_OPTIONS.

In your addon you're able to use this constant to get the localized string, depending on your game client's language then.
Use the following function
Code:

GetString(myStrings_SI_Constant)
The function can be used with an additional optional parameter2, but you need to set the parameter1 into "" then!
-> See description of param2 in post 2 of this thread
Code:

GetString("myStrings_SI_Constant", param2)

Example
In order to show the localized text for the chosen constant SI_INPUT_LANGUAGE_ENGLISH (will translate to "English", "Anglaise", "Englisch" depending on your game client's language)

Lua Code:
  1. local myLocalizedVariable = GetString(SI_INPUT_LANGUAGE_ENGLISH)
  2. --myLocalizedVariable  will contain the String "English" now

You're also able to use GetString() without assigning it to a local/global variable before.
This way you can use the game texts inside your LAM menus e.g. and don't have to think about translations (except the non standard game languages like Portuguese, Italian and so on)


Lua Code:
  1. --LAM optionsPanel array
  2. local optionsPanel = {
  3.        {
  4.             type = 'header',
  5.             name = GetString("SI_WINDOW_TITLE_GRAPHICS_OPTIONS"),
  6.         },
  7. ...
  8. }

sirinsidiator 01/05/17 09:39 AM

Nice writeup. Two small additions:
You don't need to pass the stringId as a string, unless you want to use the second argument to GetString:

Lua Code:
  1. GetString("SI_ITEMTYPE0") -- works
  2. GetString(SI_ITEMTYPE0) -- works
  3. GetString(SI_ITEMTYPE, ITEMTYPE_NONE) -- doesn't work
  4. GetString("SI_ITEMTYPE", ITEMTYPE_NONE) -- works

You can directly assign the stringId in LAM since a few versions ago:
Lua Code:
  1. --LAM optionsPanel array
  2.     local optionsPanel = {
  3.            {
  4.                 type = 'header',
  5.                 name = SI_WINDOW_TITLE_GRAPHICS_OPTIONS,
  6.             },
  7.     ...
  8.     }

Carter_DC 08/11/17 03:04 AM

Hi, there.

And if i want, let's say not to add my own translations to each single area name in the game ?
where do i find the constants for area names used for localization, cuz it seems to me they aren't in this file ?

sirinsidiator 08/11/17 03:57 AM

There are a lot of strings that are not defined in Lua. Some of them can be received via the API, but a lot of them are just not accessible.

In the case of zone names (if that is what you mean with areas), you can get a name for a zoneId via the GetZoneNameById api function. To get the zoneId of the map you are looking at, you can use GetCurrentMapZoneIndex and GetZoneId (on the return value).

Ayantir 08/11/17 05:31 AM

I would also add that you can add those constants in XML files, such as

Lua Code:
  1. <Label name="something" text="SI_YES" />

It will display Yes or its translation in your UI.


All times are GMT -6. The time now is 05:38 AM.

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