-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add en and fr as (the only) languages that can be
selected via lang attribute on <mapml-viewer> or ancestors Add grunt plugin to generate locale, localeFr keys for DefaultMapOptions.js Add postintall for playwright, remove from gh action setup.
- Loading branch information
1 parent
37d69c1
commit 56a8791
Showing
40 changed files
with
1,160 additions
and
3,550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// load-locales.js | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
function loadLocalePlugin() { | ||
return { | ||
name: 'load-locale', | ||
resolveId(source) { | ||
if (source === 'generated-locale') return source; | ||
return null; | ||
}, | ||
load(id) { | ||
if (id === 'generated-locale') { | ||
// Load and process each language's messages.json file | ||
const enMessagesPath = path.resolve(__dirname, 'node_modules/mapml-extension/src/_locales/en/messages.json'); | ||
const frMessagesPath = path.resolve(__dirname, 'node_modules/mapml-extension/src/_locales/fr/messages.json'); | ||
|
||
const enMessages = JSON.parse(fs.readFileSync(enMessagesPath, 'utf-8')); | ||
const frMessages = JSON.parse(fs.readFileSync(frMessagesPath, 'utf-8')); | ||
|
||
// Function to transform messages.json content to the desired structure | ||
const transformMessages = (messages) => { | ||
return Object.keys(messages).reduce((acc, key) => { | ||
if (key !== 'extName' && key !== 'extDescription') { | ||
acc[key] = messages[key].message; | ||
} | ||
return acc; | ||
}, {}); | ||
}; | ||
|
||
// Generate locale objects | ||
const locale = transformMessages(enMessages); | ||
const localeFr = transformMessages(frMessages); | ||
|
||
// Export the transformed objects | ||
return `export const locale = ${JSON.stringify(locale)}; | ||
export const localeFr = ${JSON.stringify(localeFr)};`; | ||
} | ||
return null; | ||
|
||
} | ||
}; | ||
} | ||
|
||
module.exports = loadLocalePlugin; |
Oops, something went wrong.