(options: {
resourcePath: string;
resourceQuery?: string;
params: any;
sourceRoot: string;
lingoDir: string;
isDev: boolean;
})
| 28 | * Please migrate to @lingo.dev/compiler. See https://lingo.dev/compiler |
| 29 | */ |
| 30 | export 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 |
no test coverage detected