View Single Post
02-23-24, 12:52 AM   #22
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,894
If french (frFR) didn't exists then

Code:
tinsert(data, {item.announce[GetLocale()], item.icon, item.name})
would be the same as
Code:
tinsert(data, {item.announce["frFR"], item.icon, item.name})
which in the end would be
Code:
tinsert(data, {nil, item.icon, item.name})
Inserting nil will cause tinsert to error.

You could use something like the following that will test if the users locale announce field is in addon.db and if not, default to using the enUS text.
Lua Code:
  1. local locale = GetLocale() -- get the current locale eg. "frFR"
  2. local function updateData()
  3.     wipe(data)
  4.     for _, item in ipairs(addon.db) do
  5.         local announceText = item.announce[locale] or item.announce.enUS -- default to enUS if the locale text doesn't exist.
  6.         tinsert(data, {announceText, item.icon, item.name})
  7.     end
  8. end

This assumes there will be a enUS field in EVERY announce table.

You could of course, if you prefer, default to .frFR or .deDE whichever locale oocures in every entry.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-23-24 at 08:40 AM.
  Reply With Quote