Skip to content

Commit

Permalink
[i18] fix alerts (#253)
Browse files Browse the repository at this point in the history
* Fix alerts

* Remove the function

* Fix alert non-translated items

* Translate createwallet too
  • Loading branch information
panleone authored Nov 8, 2023
1 parent d911720 commit 325e2a4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion scripts/dashboard/CreateWallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function generateWallet() {

<button class="pivx-button-big" @click="generateWallet()">
<span class="buttoni-icon" v-html="pLogo"> </span>
<span class="buttoni-text" data-i18n="ldCardOneButton"
<span class="buttoni-text" data-i18n="dCardOneButton"
>Create A New Wallet</span
>
</button>
Expand Down
57 changes: 39 additions & 18 deletions scripts/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { negotiateLanguages } from '@fluent/langneg';
/**
* @type {translation_template}
*/
export const ALERTS = {};
export let ALERTS = {};

/**
* @type {translation_template}
Expand Down Expand Up @@ -41,6 +41,10 @@ async function getLanguage(code) {
async function setTranslationKey(key, langName) {
const lang = await getLanguage(langName);

if (key === 'ALERTS') {
await setAlertKey(langName);
return;
}
if (lang[key]) {
translation[key] = lang[key];
} else {
Expand All @@ -54,6 +58,38 @@ async function setTranslationKey(key, langName) {
}
}

/**
* Set the alert key for a given langName
* @param {String} langName - language name
*/
async function setAlertKey(langName) {
const lang = await getLanguage(langName);
translation['ALERTS'] = lang['ALERTS'];
for (const subKey in lang['ALERTS']) {
setAlertSubKey(subKey, langName);
}
}

/**
* Set a given subkey for ALERTS key for a given langName
* @param {String} langName - language name
* @param {String} subKey - ALERT subkey that we want to set
*/
async function setAlertSubKey(subKey, langName) {
const lang = await getLanguage(langName);
const item = lang['ALERTS'][subKey];
if (item !== '') {
translation['ALERTS'][subKey] = item;
} else {
if (langName === defaultLang) {
//Should not happen but just in case
translation['ALERTS'][subKey] = '';
return;
}
await setAlertSubKey(subKey, getParentLanguage(langName));
}
}

/**
* Takes the language name and sets the translation settings based on the language file
* @param {string} langName
Expand Down Expand Up @@ -83,7 +119,7 @@ export async function switchTranslation(langName) {
if (wallet.isLoaded() && cNet) {
await updateEncryptionGUI();
}
loadAlerts();
ALERTS = translation['ALERTS'];
fillAnalyticSelect();
if (wallet.isLoaded()) {
await guiToggleReceiveType(cReceiveType);
Expand Down Expand Up @@ -145,22 +181,7 @@ export function translateStaticHTML(i18nLangs) {
}
}
});
loadAlerts();
}

/**
* Translates the alerts by loading the data into the ALERTS object
*/
export function loadAlerts() {
// Alerts are designated by a special 'ALERTS' entry in each translation file
let fFoundAlerts = false;
for (const [alert_key, alert_translation] of Object.entries(translation)) {
if (fFoundAlerts) {
ALERTS[alert_key] = alert_translation;
}
// Skip all entries until we find the ALERTS flag
if (alert_key === 'ALERTS') fFoundAlerts = true;
}
ALERTS = translation['ALERTS'];
}

export const arrActiveLangs = [
Expand Down
4 changes: 2 additions & 2 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,13 @@ async function setAnalytics(level, fSilent = false) {
*/
export async function logOut() {
const fContinue = await confirmPopup({
title: `${translation.CONFIRM_POPUP_DELETE_ACCOUNT_TITLE}`,
title: `${ALERTS.CONFIRM_POPUP_DELETE_ACCOUNT_TITLE}`,
html: `
<b>${tr(translation.netSwitchUnsavedWarningSubtitle, [
{ network: cChainParams.current.name },
])}</b>
<br>
${translation.CONFIRM_POPUP_DELETE_ACCOUNT}
${ALERTS.CONFIRM_POPUP_DELETE_ACCOUNT}
<br>
<br>
`,
Expand Down

0 comments on commit 325e2a4

Please sign in to comment.