Skip to content

Commit

Permalink
Add internationalization framework with French and Spanish translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaifroid authored Aug 23, 2023
1 parent bd2d03c commit 0240348
Show file tree
Hide file tree
Showing 16 changed files with 1,334 additions and 359 deletions.
233 changes: 233 additions & 0 deletions i18n/en.json

Large diffs are not rendered by default.

233 changes: 233 additions & 0 deletions i18n/es.json

Large diffs are not rendered by default.

233 changes: 233 additions & 0 deletions i18n/fr.json

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
"scripts": {
"serve": "vite",
"preview": "del-cli dist && npm run build-src && vite preview",
"build": "del-cli dist && npm run build-src && npm run build-min",
"prebuild": "del-cli dist",
"build": "rollup --config --file dist/www/js/bundle.js && rollup --config --file dist/www/js/bundle.min.js --environment BUILD:production",
"prebuild-min": "del-cli dist",
"build-min": "rollup --config --file dist/www/js/bundle.min.js --environment BUILD:production",
"prebuild-src": "del-cli dist",
"build-src": "rollup --config --file dist/www/js/bundle.js",
"del-dist": "del-cli dist",
"test": "testcafe all ./tests/initTestCafe.js --app \"http-server --silent -p 8080 .\"",
Expand All @@ -28,6 +31,7 @@
"@types/fs-extra": "^9.0.11",
"bootstrap": "^4.6.2",
"core-js": "3.30.2",
"i18next": "14.0.0",
"jquery": "^3.7.0"
},
"devDependencies": {
Expand Down
5 changes: 3 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ const config = {
exclude: 'node_modules/**',
babelHelpers: 'bundled'
}),
// Needed to get rid of residual "requires" left in the code by Babel...
commonjs(),
// Resolves references to node_modules packages
resolve({
browser: true
}),
// Needed to get rid of residual "requires" left in the code by Babel...
commonjs(),
// styles({
// // mode: 'extract',
// modules: true
Expand All @@ -45,6 +45,7 @@ const config = {
dest: 'dist/www/js'
},
{ src: ['node_modules/bootstrap/dist/css/bootstrap.min.*'], dest: 'dist/www/css' },
{ src: ['i18n/*'], dest: 'dist/i18n' },
{ src: ['archives', 'backgroundscript.js', 'index.html', 'manifest.json', 'manifest.v2.json', 'manifest.webapp', 'package.json', 'LICENSE-GPLv3.txt', 'CHANGELOG.md', 'README.md', '*.pfx', '*.cjs'], dest: 'dist' }
],
flatten: true
Expand Down
3 changes: 3 additions & 0 deletions service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ const precacheFiles = [
'.', // This caches the redirect to www/index.html, in case a user launches the app from its root directory
'manifest.json',
'service-worker.js',
'i18n/en.json',
'i18n/es.json',
'www/css/app.css',
'www/css/kiwixJS_invert.css',
'www/css/kiwixJS_mwInvert.css',
Expand All @@ -123,6 +125,7 @@ const precacheFiles = [
'www/js/lib/filecache.js',
'www/js/lib/promisePolyfill.js',
'www/js/lib/settingsStore.js',
'www/js/lib/translateUI.js',
'www/js/lib/uiUtil.js',
'www/js/lib/utf8.js',
'www/js/lib/util.js',
Expand Down
6 changes: 3 additions & 3 deletions tests/gutenberg_ro.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ function runTests (driver, modes) {
if (mode === 'jquery' || serviceWorkerAPI) {
// Wait until the mode has switched
await driver.sleep(500);
let serviceWorkerStatus = await driver.findElement(By.id('serviceWorkerStatus')).getText();
let serviceWorkerStatus = await driver.findElement(By.id('serviceWorkerStatus')).getAttribute('class');
try {
if (mode === 'serviceworker') {
assert.equal(true, /and\sregistered/i.test(serviceWorkerStatus));
assert.equal(true, /apiAvailable/i.test(serviceWorkerStatus));
} else {
assert.equal(true, /not\sregistered|unavailable/i.test(serviceWorkerStatus));
assert.equal(true, /apiUnavailable/i.test(serviceWorkerStatus));
}
} catch (e) {
if (!~modes.indexOf('serviceworker')) {
Expand Down
38 changes: 20 additions & 18 deletions tests/legacy-ray_charles.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ function runTests (driver, modes) {
const modeSelector = await driver.findElement(By.id(mode + 'ModeRadio'));
// Scroll the element into view so that it can be clicked
await driver.wait(async function () {
const elementIsVisible = await driver.executeScript('var el=arguments[0]; el.scrollIntoView(true); setTimeout(function () {el.click();}, 50); return el.offsetParent;', modeSelector);
const elementIsVisible = await driver.executeScript('var el=arguments[0]; el.scrollIntoView(true); setTimeout(function () {el.click();}, 250); return el.offsetParent;', modeSelector);
return elementIsVisible;
}, 5000);
}, 6000);
// Pause for timeout
await driver.sleep(500);
// Check for and click any approve button in dialogue box
Expand All @@ -146,7 +146,10 @@ function runTests (driver, modes) {
// Check if ServiceWorker mode API is supported
if (mode === 'serviceworker') {
serviceWorkerAPI = await driver.findElement(By.id('modalLabel')).getText().then(function (alertText) {
const supported = !/unsupported|not\savailable/i.test(alertText);
// DEV: Although I have tried to make this generic in the hope that the alert will contain the word
// "ServiceWorker" or "Service Worker" in all languages, we may need to add some failure code to the dialogue box
// to make this more robust, as translators may not be aware of the need to include this word in Roman script
const supported = !/Service\s*Worker/i.test(alertText);
console.log(supported ? '' : '\x1b[33m%s\x1b[0m', ' ' + alertText);
return supported;
})
Expand All @@ -160,12 +163,12 @@ function runTests (driver, modes) {
if (mode === 'jquery' || serviceWorkerAPI) {
// Wait until the mode has switched
await driver.sleep(500);
let serviceWorkerStatus = await driver.findElement(By.id('serviceWorkerStatus')).getText();
let serviceWorkerStatus = await driver.findElement(By.id('serviceWorkerStatus')).getAttribute('class');
try {
if (mode === 'serviceworker') {
assert.equal(true, /and\sregistered/i.test(serviceWorkerStatus));
assert.equal(true, /apiAvailable/i.test(serviceWorkerStatus));
} else {
assert.equal(true, /not\sregistered|unavailable/i.test(serviceWorkerStatus));
assert.equal(true, /apiUnavailable/i.test(serviceWorkerStatus));
}
} catch (e) {
if (!~modes.indexOf('serviceworker')) {
Expand All @@ -178,16 +181,16 @@ function runTests (driver, modes) {
// Click the other mode selector
await otherModeSelector.click();
// Wait until the mode has switched
await driver.sleep(330);
await driver.sleep(400);
// Click the mode selector again
await modeSelector.click();
// Wait until the mode has switched
await driver.sleep(330);
serviceWorkerStatus = await driver.findElement(By.id('serviceWorkerStatus')).getText();
await driver.sleep(400);
serviceWorkerStatus = await driver.findElement(By.id('serviceWorkerStatus')).getAttribute('class');
if (mode === 'serviceworker') {
assert.equal(true, /and\sregistered/i.test(serviceWorkerStatus));
assert.equal(true, /apiAvailable/i.test(serviceWorkerStatus));
} else {
assert.equal(true, /not\sregistered|unavailable/i.test(serviceWorkerStatus));
assert.equal(true, /apiUnavailable/i.test(serviceWorkerStatus));
}
}
} else {
Expand Down Expand Up @@ -231,23 +234,22 @@ function runTests (driver, modes) {
return;
}
// console.log('FilesLength outer: ' + filesLength);
// Wait until the index has loaded
await driver.sleep(3000);
const contentAvailable = await driver.executeScript('return /little\\sgirl/i.test(document.getElementById("articleContent").contentDocument.documentElement.innerHTML)');
assert.equal(contentAvailable, true);
// Switch to iframe and check that the index contains the specified article
await driver.switchTo().frame('articleContent');
// Wait until the index has loaded
await driver.wait(async function () {
const contentAvailable = await driver.executeScript('return document.getElementById("mw-content-text");');
return contentAvailable;
}, 5000);
const articleLink = await driver.findElement(By.xpath('/html/body/div/div/ul/li[77]/a[2]'));
// const articleLink = await driver.findElement(By.linkText('This Little Girl of Mine'));
assert.equal('This Little Girl of Mine', await articleLink.getText());
// Scroll the element into view and navigate to it
await driver.wait(async function () {
const elementIsVisible = await driver.executeScript('var el=arguments[0]; el.scrollIntoView(true); setTimeout(function () {el.click();}, 50); return el.offsetParent;', articleLink);
const elementIsVisible = await driver.executeScript('var el=arguments[0]; el.scrollIntoView(true); setTimeout(function () {el.click();}, 150); return el.offsetParent;', articleLink);
// console.log('Element is visible: ' + elementIsVisible);
return elementIsVisible;
}, 10000);
// Pause for 1 second to allow article to load
// Pause for 1.3 second to allow article to load
await driver.sleep(1300);
let elementText = '';
try {
Expand Down
18 changes: 18 additions & 0 deletions www/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@
margin: 0 1rem;
}

/* Custom file input */

input[type="file"] {
display: none;
}

.custom-file-upload {
border: 2px solid darkgray;
display: inline-block;
padding: 6px 12px;
cursor: pointer;
}

.dark .custom-file-upload {
border: 2px solid darkslategray;
}


/* App theme: dark */

.dark header, .dark #cachingAssets, .dark #about, .dark #configuration, .dark #welcomeText, .dark #articleListWithHeader,
Expand Down
Loading

0 comments on commit 0240348

Please sign in to comment.