UNPKG

@intlayer/core

Version:

Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.

1 lines 1.87 kB
{"version":3,"file":"getIntlayer.mjs","names":[],"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { getAppLogger } from '@intlayer/config/client';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n DictionaryRegistryElement,\n LocalesValues,\n} from '@intlayer/types';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getDictionary } from './getDictionary';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L,\n plugins?: Plugins[]\n): DeepTransformContent<\n DictionaryRegistryContent<T>,\n IInterpreterPluginState,\n L\n> => {\n const dictionaries = getDictionaries();\n const dictionary = dictionaries[key as T] as DictionaryRegistryElement<T>;\n\n if (!dictionary) {\n if (configuration.build.optimize) {\n const logger = getAppLogger(configuration);\n logger(\n 'Build optimization is enabled, the dictionary may have been purged. You can disable build optimization, or configure the traversePattern to include the current component.',\n {\n level: 'error',\n isVerbose: true,\n }\n );\n }\n throw new Error(`Dictionary ${key as string} not found`, dictionaries);\n }\n\n return getDictionary<DictionaryRegistryElement<T>, L>(\n dictionary,\n locale,\n plugins\n );\n};\n"],"mappings":";;;;;;AAiBA,MAAa,eAIX,KACA,QACA,YAKG;CACH,MAAM,eAAe,iBAAiB;CACtC,MAAM,aAAa,aAAa;AAEhC,KAAI,CAAC,YAAY;AACf,MAAI,cAAc,MAAM,SAEtB,CADe,aAAa,cAAc,CAExC,8KACA;GACE,OAAO;GACP,WAAW;GACZ,CACF;AAEH,QAAM,IAAI,MAAM,cAAc,IAAc,aAAa,aAAa;;AAGxE,QAAO,cACL,YACA,QACA,QACD"}