Skip to content

Commit

Permalink
[i18n] Various fixes (Closes #329)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferllings committed Mar 18, 2024
1 parent cc8f986 commit 157f549
Show file tree
Hide file tree
Showing 21 changed files with 34 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/controllers/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (browsers, store) => {
const i18n = new(require('../i18n'))(lang)
let config = {
version: app.getVersion(),
i18n: i18n.asObject().About
i18n: i18n.asObject()
}
sendEvent('init', config)
})
Expand All @@ -20,7 +20,7 @@ module.exports = (browsers, store) => {
case 'langChanged':
const lang = store.get('lang')
const i18n = new(require('../i18n'))(lang)
win.webContents.send(event, i18n.asObject().About)
win.webContents.send(event, i18n.asObject())
break
default:
win.webContents.send(event, ...params)
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/deficiency.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = (browsers, store) => {
const lang = store.get('lang')
const i18n = new(require('../i18n'))(lang)
let config = {
i18n: i18n.asObject().Deficiency
i18n: i18n.asObject()
}
sendEvent('init', config)
})
Expand All @@ -19,7 +19,7 @@ module.exports = (browsers, store) => {
case 'langChanged':
const lang = store.get('lang')
const i18n = new(require('../i18n'))(lang)
win.webContents.send(event, i18n.asObject().Deficiency)
win.webContents.send(event, i18n.asObject())
break
default:
win.webContents.send(event, ...params)
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = (browsers, store) => {
const lang = store.get('lang')
const i18n = new(require('../i18n'))(lang)
let config = {
i18n: i18n.asObject().Main
i18n: i18n.asObject()
}
sendEvent('init', config)
})
Expand All @@ -23,7 +23,7 @@ module.exports = (browsers, store) => {
case 'langChanged':
const lang = store.get('lang')
const i18n = new(require('../i18n'))(lang)
win.webContents.send(event, i18n.asObject().Main)
win.webContents.send(event, i18n.asObject())
break
default:
win.webContents.send(event, ...params)
Expand Down
2 changes: 1 addition & 1 deletion src/views/about.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>About</title>
Expand Down
2 changes: 1 addition & 1 deletion src/views/deficiency.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Colour blindness simulation</title>
Expand Down
4 changes: 3 additions & 1 deletion src/views/js/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ ipcRenderer.on('langChanged', (event, i18n) => {
translateHTML(i18n)
})

function translateHTML(i18n) {
function translateHTML(_i18n) {
document.querySelector('html').lang = _i18n.Main['lang']
const i18n = _i18n["About"];
// translate html elements.
document.title = i18n['Title'];
document.querySelector('h1#header-main').textContent = i18n['Colour Contrast Analyser (CCA)'];
Expand Down
8 changes: 5 additions & 3 deletions src/views/js/deficiency.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ ipcRenderer.on('contrastRatioChanged', (event, contrastRatio) => {
applyContrastRatio(contrastRatio)
})

ipcRenderer.on('langChanged', (event, i18nNew) => {
i18n = i18nNew
ipcRenderer.on('langChanged', (event, i18n) => {
translateHTML(i18n)
})

Expand All @@ -49,7 +48,10 @@ function applyContrastRatio (contrastRatio) {
})
}

function translateHTML(i18n) {
function translateHTML(_i18n) {
document.querySelector('html').lang = _i18n.Main['lang']
const i18n = _i18n["Deficiency"];

// translate html elements.
document.title = i18n['Title']
document.querySelector('body > main > h1').textContent = i18n['Colour blindness simulation']
Expand Down
12 changes: 5 additions & 7 deletions src/views/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const announceForAccessibility = (message)=>{
}

ipcRenderer.on('init', async (event, config) => {
i18n = config.i18n
translateHTML(i18n)
i18n = config.i18n["Main"];
translateHTML()
const theme = await store.get("colorScheme");
setColorScheme(theme);
// init format selector
Expand Down Expand Up @@ -118,8 +118,7 @@ ipcRenderer.on('colorSchemeChanged',async (event,newScheme)=>{
setColorScheme(newScheme);
})

ipcRenderer.on('langChanged', (event, i18nNew) => {
i18n = i18nNew
ipcRenderer.on('langChanged', (event, i18n) => {
translateHTML(i18n)
//TODO applyContrastRatio()
})
Expand Down Expand Up @@ -336,7 +335,7 @@ function applyColorHSVSliders(section, color) {
function applyColorSample(section, color) {
if (section === 'foreground') {
document.querySelector('#sample-preview .text').style.color = color.rgb
document.querySelector('#sample-preview .icon svg').style.stroke = color.rgb
document.querySelector('#sample-preview .icon svg').style.stroke = color.rgb
} else {
document.querySelector('#sample-preview .text').style.background = color.rgb
document.querySelector('#sample-preview .icon').style.background = color.rgb
Expand Down Expand Up @@ -445,8 +444,7 @@ function changeFormat(section, el) {
store.set(`${section}.format`, el.value)
}

function translateHTML(i18n) {

function translateHTML() {
// translate html elements.
document.querySelector('html').lang = i18n['lang']
document.querySelector('title').textContent = i18n['Title']
Expand Down
7 changes: 4 additions & 3 deletions src/views/js/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ function close() {window.close();}
* @description translate html elements.
*/
function translateHTML(_i18n) {
document.querySelector('html').lang = _i18n.Main['lang']
const i18n = _i18n["Preferences"];
document.title = i18n['Title'];
document.querySelector('h1').textContent = i18n['Preferences'];

/* Options fieldset */
document.querySelector('fieldset#options>legend').textContent = i18n['Options'];
document.querySelector('fieldset#options>legend').textContent = i18n['Options'];
// Rounding Precision
document.querySelector('label[for="option-rounding"]').textContent = i18n['Contrast ratio precision'];
document.querySelectorAll('#option-rounding > option').forEach((opt,idx)=>{
Expand Down Expand Up @@ -164,8 +165,8 @@ function translateHTML(_i18n) {
// background, foreground picker
document.querySelector('label[for="shortcut-background-picker"]').textContent = i18n['Picker foreground'];
document.querySelector('label[for="shortcut-foreground-picker"]').textContent = i18n['Picker background'];
document.querySelector('fieldset#copy > legend').textContent = i18n['Copy results'];

document.querySelector('fieldset#copy > legend').textContent = _i18n.Menu['Copy results'];
/* Copy results fieldset */
document.querySelectorAll("#copy-format-example>li>span").forEach((el,idx)=>{
const i18nTexts = [i18n["Foreground colour in hexa format"],
Expand Down
4 changes: 1 addition & 3 deletions src/views/preferences.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<!DOCTYPE html>
<html>

<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Preferences</title>
<link rel="stylesheet" href="css/global.css" />
<link rel="stylesheet" href="css/preferences.css" />
<link rel="stylesheet" href="css/tabs.css" />
</head>

<body>
<main>
<h1 class="sr-only">Preferences</h1>
Expand Down
1 change: 0 additions & 1 deletion src/views/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
"Electron" : "Electron",
"Add-on":"Add-on",
"Shortcuts": "Shortcuts",
"Copy results":"Copy results",
"Picker foreground": "Picker foreground",
"Picker background": "Picker background",
"Reset":"Reset",
Expand Down
1 change: 0 additions & 1 deletion src/views/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
"Electron" : "Electron",
"Add-on":"Add-on",
"Shortcuts": "Atajos",
"Copy results":"Copy results",
"Picker foreground": "Selector de primer plano",
"Picker background": "Selector de fondo",
"Reset":"Reset",
Expand Down
17 changes: 8 additions & 9 deletions src/views/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Preferences": "Préférences",
"Edit": "Édition",
"Copy results": "Copier les résultats",
"Copy short results": "Copy short results",
"Copy short results": "Copier les résultats (simplifiés)",
"Cut": "Couper",
"Copy": "Copier",
"Paste": "Coller",
Expand Down Expand Up @@ -127,16 +127,15 @@
"Electron" : "Electron",
"Add-on":"Add-on",
"Shortcuts": "Raccourcis",
"Copy results":"Copy results",
"Picker foreground": "Sélecteur de premier plan",
"Picker background": "Sélecteur d'arrière-plan",
"Reset":"Reset",
"Short results template":"Short results template",
"Regular results template":"Regular results template",
"Foreground colour in hexa format":"Foreground colour in hexa format",
"Background colour in hexa format":"background colour in hexa format",
"Contrast ratio (raw)":"Contrast ratio (raw)",
"Contrast ratio (rounded)":"Contrast ratio (rounded)",
"Reset":"Réinitialiser",
"Short results template":"Modèle de résultats courts",
"Regular results template":"Modèle de résultats complets",
"Foreground colour in hexa format":"Couleur de premier plan au format hexadécimal",
"Background colour in hexa format":"Couleur d'arrière-plan au format hexadécimal",
"Contrast ratio (raw)":"Ratio de contraste (brut)",
"Contrast ratio (rounded)":"Ratio de contraste (contraste)",
"Save": "Sauvegarder",
"Cancel": "Annuler",
"Color Picker type": "Type de sélecteur"
Expand Down
1 change: 0 additions & 1 deletion src/views/translations/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
"Electron" : "Electron",
"Add-on":"Add-on",
"Shortcuts" : "Gyorsbillentyűk",
"Copy results":"Copy results",
"Picker foreground" : "Előtérszín pipetta",
"Picker background" : "Háttérszín pipetta",
"Reset":"Reset",
Expand Down
1 change: 0 additions & 1 deletion src/views/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
"Electron" : "Electron",
"Add-on":"Add-on",
"Shortcuts": "Tasti di scelta rapida",
"Copy results":"Copia risultati",
"Picker foreground": "Selettore primo piano",
"Picker background": "Selettore sfondo",
"Reset":"Ripristina",
Expand Down
1 change: 0 additions & 1 deletion src/views/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
"Electron" : "Electron",
"Add-on":"Add-on",
"Shortcuts": "ショートカットキー",
"Copy results":"結果コピー",
"Picker foreground": "前景色ピッカー",
"Picker background": "背景色ピッカー",
"Reset":"リセット",
Expand Down
1 change: 0 additions & 1 deletion src/views/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
"Electron" : "일렉트론",
"Add-on":"에드온",
"Shortcuts": "단축키",
"Copy results":"결과 복사",
"Picker foreground": "화면에서 글자 색상 선택",
"Picker background": "화면에서 배경 색상 선택",
"Reset":"되돌리기",
Expand Down
1 change: 0 additions & 1 deletion src/views/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
"Contrast ratio (raw)":"Współczynnik kontrastu (surowy)",
"Contrast ratio (rounded)":"Współczynnik kontrastu (zaokrąglony)",
"Shortcuts": "Skróty",
"Copy results":"Skopiuj wyniki",
"Picker foreground": "Próbnik koloru pierwszoplanowego",
"Picker background": "Próbnik koloru tła",
"Save": "Zapisz",
Expand Down
1 change: 0 additions & 1 deletion src/views/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
"Contrast ratio (raw)":"Contrast ratio (raw)",
"Contrast ratio (rounded)":"Contrast ratio (rounded)",
"Shortcuts": "Горячие клавиши",
"Copy results":"Copy results",
"Picker foreground": "Пипетка для текста",
"Picker background": "Пипетка для фона",
"Save": "Сохранить",
Expand Down
1 change: 0 additions & 1 deletion src/views/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
"Electron": "Electron",
"Add-on": "插件",
"Shortcuts": "快捷键",
"Copy results": "复制结果",
"Picker foreground": "取色器前景",
"Picker background": "取色器背景",
"Reset": "重置",
Expand Down
1 change: 0 additions & 1 deletion src/views/translations/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
"Electron": "Electron",
"Add-on": "插件",
"Shortcuts": "快捷鍵",
"Copy results": "復製結果",
"Picker foreground": "取色器前景",
"Picker background": "取色器背景",
"Reset": "重置",
Expand Down

0 comments on commit 157f549

Please sign in to comment.