View Single Post
08/15/15, 08:00 PM   #16
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by haggen View Post
Am I bugging you guys too much ? I hope not

Another question: I just found this post http://www.esoui.com/forums/showthread.php?t=2136 about localization/internationalization strings.

But why should I bother to learn that, when I could simply do something like...

Code:
GetMyString = { ["Hello"] = "Hello" }
GetMyString["Hello"]
What's the benefit here of following the ZO standard ?

Thanks again!
Because in your example no matter what language the user is using
Lua Code:
  1. GetMyString["Hello"]
  2. -- would give you "Hello"
So it would always be in English.


The method discussed in that thread is used to get strings for the users client language.
As Garkin posted:
Lua Code:
  1. ## Title: My Addon
  2. ## Version: 1.0
  3. ## Author: Garkin
  4. ## APIVersion: 100008
  5.  
  6. Lang/$(language).lua
  7. addon.lua

The Lang/$(language).lua line would automatically load the correct language file (see code below) for the users current language. Each language file you create would have different definitions in it.

Lua Code:
  1. -- Lang/en.lua (english language file):
  2. ZO_CreateStringId("STRING_JEWELRY", "Jewelry")
  3.  
  4. -- Lang/de.lua (german language file):
  5. ZO_CreateStringId("STRING_JEWELRY", "Schmuck")
  6.  
  7. -- Lang/fr.lua (french language file):
  8. ZO_CreateStringId("STRING_JEWELRY", "Bijoux")

This way you do not need to worry about what language the client is using. When you call
Lua Code:
  1. GetString(STRING_JEWELRY)
If the users client is in english it will return "Jewelry", if the client is in german it will return "Schmuck", if it is in french it will return "Bijoux", exc...

It frees you from having to worry about what language the users client is in. Otherwise every time you wanted to do your version of GetMyString, you would have to have something like this:

Lua Code:
  1. GetMyString = { ["EnJewelry"] = "Jewelry", ["DeJewelry"] = "Schmuch", ["FrJewelry"] = "Bijoux" }
  2. -- Then you would have to determine what language the client
  3. -- was in and then get the appropriate string for that language:
  4. GetMyString["EnJewelry"]

I should point out this is not something you have to do. This is only done if you are concerned with translating/displaying the strings in the users client language. If you are not concerned with that, then there would be nothing wrong with just defining the strings in normal variables & just using them when you need them:
Lua Code:
  1. local lootMsg = "You looted something!"
  2. ...
  3. local function OnLoot()
  4.    d(lootMsg)
  5. end

Last edited by circonian : 08/15/15 at 09:34 PM.
  Reply With Quote