Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add en and fr as (the only) languages that can be selected via lang attribute on <mapml-viewer> or ancestors #999

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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