Skip to main content
Glama
getAvailableLocalesInDictionary.ts1.26 kB
import type { Dictionary, Locale } from '@intlayer/types'; /** * Recursively traverses dictionary content to find all locales that have actual translations. * Returns a Set of locale strings that are present in the translation nodes. */ const extractLocalesFromContent = ( content: any, locales: Set<Locale> = new Set() ): Set<Locale> => { if (!content || typeof content !== 'object') { return locales; } // Check if this is a translation node if (content.nodeType === 'translation' && content.translation) { // Add all locale keys from the translation map Object.keys(content.translation).forEach((locale) => { locales.add(locale as Locale); }); } // Recursively check nested objects for (const value of Object.values(content)) { if (value && typeof value === 'object') { extractLocalesFromContent(value, locales); } } return locales; }; /** * Gets all locales that have actual translations in the dictionary content. * Only returns locales that are present in at least one translation node. */ export const getAvailableLocalesInDictionary = ( dictionary: Dictionary ): Locale[] => { const localesSet = extractLocalesFromContent(dictionary.content); return Array.from(localesSet); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server