Skip to content

Commit

Permalink
Add en and fr as (the only) languages that can be
Browse files Browse the repository at this point in the history
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
prushforth committed Oct 30, 2024
1 parent 37d69c1 commit 56a8791
Show file tree
Hide file tree
Showing 40 changed files with 1,160 additions and 3,550 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
node-version: latest
- run: sudo apt-get install xvfb
- run: npm install
- run: npx playwright install --with-deps
- run: npm install -g grunt-cli
- run: grunt default
- run: xvfb-run --auto-servernum -- npx playwright test --grep-invert="popupTabNavigation\.test\.js|layerContextMenuKeyboard\.test\.js" --workers=1 --retries=3
Expand Down
9 changes: 5 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = function(grunt) {
const Diff = require('diff');
const nodeResolve = require('@rollup/plugin-node-resolve');
grunt.initConfig({
const Diff = require('diff');
const nodeResolve = require('@rollup/plugin-node-resolve');
const loadLocalePlugin = require('./load-locales.js');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
cssmin: {
options: {
Expand Down Expand Up @@ -193,7 +194,7 @@ module.exports = function(grunt) {
rollup: {
options: {
format: 'es',
plugins: [nodeResolve()],
plugins: [nodeResolve(),loadLocalePlugin()],
external: './pmtilesRules.js'
},
main: {
Expand Down
45 changes: 45 additions & 0 deletions load-locales.js
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;
Loading

0 comments on commit 56a8791

Please sign in to comment.