MCPcopy Create free account
hub / github.com/Maps4HTML/MapML.js / load

Function load

load-locales.js:12–41  ·  view source on GitHub ↗
(id)

Source from the content-addressed store, hash-verified

10 return null;
11 },
12 load(id) {
13 if (id === 'generated-locale') {
14 // Load and process each language's messages.json file
15 const enMessagesPath = path.resolve(__dirname, 'node_modules/mapml-extension/src/_locales/en/messages.json');
16 const frMessagesPath = path.resolve(__dirname, 'node_modules/mapml-extension/src/_locales/fr/messages.json');
17
18 const enMessages = JSON.parse(fs.readFileSync(enMessagesPath, 'utf-8'));
19 const frMessages = JSON.parse(fs.readFileSync(frMessagesPath, 'utf-8'));
20
21 // Function to transform messages.json content to the desired structure
22 const transformMessages = (messages) => {
23 return Object.keys(messages).reduce((acc, key) => {
24 if (key !== 'extName' && key !== 'extDescription') {
25 acc[key] = messages[key].message;
26 }
27 return acc;
28 }, {});
29 };
30
31 // Generate locale objects
32 const locale = transformMessages(enMessages);
33 const localeFr = transformMessages(frMessages);
34
35 // Export the transformed objects
36 return `export const locale = ${JSON.stringify(locale)};
37 export const localeFr = ${JSON.stringify(localeFr)};`;
38 }
39 return null;
40
41 }
42 };
43}
44

Callers

nothing calls this directly

Calls 2

transformMessagesFunction · 0.85
resolveMethod · 0.80

Tested by

no test coverage detected