local SupportedLocales = require(script.Parent.Parent.SupportedLocales) --[[ Iterates through a table and returns a list of keys ]] local function SetToList(tableAsSet) local result = {} for key in pairs(tableAsSet) do table.insert(result, key) end return result end local function SetToSortedList(tableAsSet) local result = SetToList(tableAsSet) table.sort(result) return result end --[[ Converts a list of entries (as returned by LocalizationTalbe:GetEntries()) into a list of entries (the kind that the web understands) Returns an info object including the list of entries (called entries) and also some stats gathered during the conversion process: totalRows = number of rows converted totalTranslations = number of translated entries converted supportedLocales = a list of all locales encountered joined with spaces into a string, i.e. "en es" unsupportedLocales = a list of all unsupported locales encountered joined with spaces into a string, i.e. "en-gb es-mx" ]] return function(rbxEntries) local entries = {} local totalRows = 0 local totalTranslations = 0 local supportedSet = {} local unsupportedSet = {} --[[ Takes a translation map as given by LocalizationTable:GetEntries() and creates an entry in the translations list in the object that the web understands Notes any locales it encounters in supportedList Unless the locale isn't supported, in which case it goes in unsupportedlist, and does not get included in the result. ]] local function RbxEntriesToTranslationEntries(translationMap) local result = {} for locale, text in pairs(translationMap) do local normalizedLocale = SupportedLocales.NormalizeLocaleIdForWeb(locale) if SupportedLocales.IsLocaleSupported(normalizedLocale) then table.insert(result, { locale = normalizedLocale, translationText = text, }) supportedSet[normalizedLocale] = true totalTranslations = totalTranslations + 1 else unsupportedSet[locale] = true end end return result end for _, entry in ipairs(rbxEntries) do local translations = RbxEntriesToTranslationEntries(entry.Values) table.insert(entries, { identifier = { key = entry.Key or "", context = entry.Context or "", source = entry.Source or "", }, metadata = { example = entry.Example or "" }, translations = translations, delete = false, } ) totalRows = totalRows + 1 end return { entries = entries, totalRows = totalRows, totalTranslations = totalTranslations, supportedLocales = table.concat(SetToSortedList(supportedSet), ", "), unsupportedLocales = table.concat(SetToSortedList(unsupportedSet), ", "), } end