MCPcopy Index your code
hub / github.com/lingodotdev/lingo.dev / loadDictionary

Function loadDictionary

packages/compiler/src/_loader-utils.ts:30–81  ·  view source on GitHub ↗
(options: {
  resourcePath: string;
  resourceQuery?: string;
  params: any;
  sourceRoot: string;
  lingoDir: string;
  isDev: boolean;
})

Source from the content-addressed store, hash-verified

28 * Please migrate to @lingo.dev/compiler. See https://lingo.dev/compiler
29 */
30export async function loadDictionary(options: {
31 resourcePath: string;
32 resourceQuery?: string;
33 params: any;
34 sourceRoot: string;
35 lingoDir: string;
36 isDev: boolean;
37}) {
38 const {
39 resourcePath,
40 resourceQuery = "",
41 params,
42 sourceRoot,
43 lingoDir,
44 isDev,
45 } = options;
46 const fullResourcePath = `${resourcePath}${resourceQuery}`;
47
48 if (!resourcePath.match(LCP_DICTIONARY_FILE_NAME)) {
49 return null; // Not a dictionary file
50 }
51
52 const moduleInfo = parseParametrizedModuleId(fullResourcePath);
53 const locale = moduleInfo.params.locale;
54
55 if (!locale) {
56 return null; // No locale specified
57 }
58
59 const lcpParams = {
60 sourceRoot,
61 lingoDir,
62 isDev,
63 };
64
65 await LCP.ready(lcpParams);
66 const lcp = LCP.getInstance(lcpParams);
67
68 const dictionaries = await LCPServer.loadDictionaries({
69 ...params,
70 lcp: lcp.data,
71 });
72
73 const dictionary = dictionaries[locale];
74 if (!dictionary) {
75 throw new Error(
76 `Lingo.dev: Dictionary for locale "${locale}" could not be generated.`,
77 );
78 }
79
80 return dictionary;
81}
82
83/**
84 * Transforms component code

Callers 3

loadFunction · 0.90

Calls 4

readyMethod · 0.80
getInstanceMethod · 0.80
loadDictionariesMethod · 0.80

Tested by

no test coverage detected