Skip to content

Commit e08a338

Browse files
committed
HFP-2650 Add warning when switching language
1 parent c885e16 commit e08a338

File tree

21 files changed

+162
-23
lines changed

21 files changed

+162
-23
lines changed

language/ar.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/bs.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/de.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/el.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/en.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,9 @@ H5PEditor.language.core = {
205205
libraryMissing: 'Missing required library %lib.',
206206
scriptMissing: 'Could not load upgrades script for %lib.',
207207
language: 'Language',
208-
noLanguagesSupported: 'No languages supported'
208+
noLanguagesSupported: 'No languages supported',
209+
changeLanguage: 'Change language to :language?',
210+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
211+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
212+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
209213
};

language/es.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/eu.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,9 @@ H5PEditor.language.core = {
205205
libraryMissing: 'Missing required library %lib.',
206206
scriptMissing: 'Could not load upgrades script for %lib.',
207207
language: 'Language',
208-
noLanguagesSupported: 'No languages supported'
208+
noLanguagesSupported: 'No languages supported',
209+
changeLanguage: 'Change language to :language?',
210+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
211+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
212+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
209213
};

language/fi.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/fr.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/it.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/nb.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Mangler påkrevd bibliotek %lib.',
204204
scriptMissing: 'Kunne ikke laste oppgraderingsskript for %lib.',
205205
language: 'Språk',
206-
noLanguagesSupported: 'Ingen språk støttet'
206+
noLanguagesSupported: 'Ingen språk støttet',
207+
changeLanguage: 'Bytt språk til :language?',
208+
thisWillPotentially: "Dette kan potensielt tilbakestille all teksten og oversettelsene. Du kan ikke omgjøre dette. Innholdet vil ikke bli endret. Vil du fortsette?",
209+
notAllTextsChanged: 'Ikke alle tekstene ble endret, det er kun delvis støtte for :language.',
210+
ifYouWantTo: 'Hvis du vil fullføre oversettelsen for :language kan du lære mer om <a href=":url" target="_new">bidra med oversettelser til H5P</a>'
207211
};

language/nl.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/nn.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/pl.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/pt-br.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/pt.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

language/tr.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,9 @@ H5PEditor.language.core = {
203203
libraryMissing: 'Missing required library %lib.',
204204
scriptMissing: 'Could not load upgrades script for %lib.',
205205
language: 'Language',
206-
noLanguagesSupported: 'No languages supported'
206+
noLanguagesSupported: 'No languages supported',
207+
changeLanguage: 'Change language to :language?',
208+
thisWillPotentially: "This will potentially reset all the text and translations. You can't undo this. The content itself will not be changed. Do you want to proceed?",
209+
notAllTextsChanged: 'Not all texts were changed, there is only partial coverage for :language.',
210+
ifYouWantTo: 'If you want to complete the translation for :language you can learn about <a href=":url" target="_new">contributing translations to H5P</a>'
207211
};

scripts/h5peditor-form.js

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ ns.Form = function (library, startLanguages) {
2323
'<option value="-">' + ns.t('core', 'noLanguagesSupported') + '</option>' +
2424
'</select>' +
2525
'</div>' +
26+
'<div class="h5peditor-language-notice">' +
27+
'<div class="first"></div>' +
28+
'<div class="last"></div>' +
29+
'</div>' +
2630
'</div>' +
2731
'</div>' +
2832
'</div>'
@@ -55,15 +59,18 @@ ns.Form = function (library, startLanguages) {
5559

5660
// Locate the language switcher DOM element
5761
const $switcher = this.$form.find('.h5peditor-language-switcher select');
62+
const $notice = this.$form.find('.h5peditor-language-notice');
63+
const loadedLibs = [];
5864
const languages = {};
65+
let selected = 'en'; // TODO: Get from starting library
5966

6067
/**
6168
* Create options DOM elements
6269
*
6370
* @private
6471
* @return {string}
6572
*/
66-
const createOptions = function (selected) {
73+
const createOptions = function () {
6774
let options = '';
6875
for (let code in languages) {
6976
let label = ns.supportedLanguages[code] ? ns.supportedLanguages[code] : code.toLocaleUpperCase();
@@ -72,6 +79,17 @@ ns.Form = function (library, startLanguages) {
7279
return options;
7380
};
7481

82+
/**
83+
* Figure out if all loaded libraries supports the chosen language code
84+
*
85+
* @private
86+
* @param {string} code
87+
* @return {boolean}
88+
*/
89+
const isSupportedByAll = function (code) {
90+
return (languages[code].length === loadedLibs.length);
91+
}
92+
7593
/**
7694
* Add new languages for content type.
7795
*
@@ -89,9 +107,10 @@ ns.Form = function (library, startLanguages) {
89107
languages[code].push(lib);
90108
}
91109
}
110+
loadedLibs.push(lib);
92111

93112
// Update
94-
$switcher.html(createOptions($switcher.val()));
113+
$switcher.html(createOptions());
95114
};
96115

97116
/**
@@ -113,14 +132,39 @@ ns.Form = function (library, startLanguages) {
113132
}
114133
}
115134
}
135+
loadedLibs.splice(loadedLibs.indexOf(lib), 1);
116136

117137
// Update
118-
$switcher.html(createOptions($switcher.val()));
138+
$switcher.html(createOptions());
119139
};
120140

121141
// Handle switching language and loading new translations
122-
$switcher.change(function () {
123-
console.log('Loading new translations', this.value);
142+
$switcher.change(function (e) {
143+
// Create confirmation dialog
144+
const confirmDialog = new H5P.ConfirmationDialog({
145+
headerText: ns.t('core', 'changeLanguage', {':language': ns.supportedLanguages[this.value]}),
146+
dialogText: ns.t('core', 'thisWillPotentially'),
147+
}).appendTo(document.body);
148+
confirmDialog.on('confirmed', function () {
149+
selected = $switcher.val();
150+
151+
// Figure out if all libraries were supported
152+
if (!isSupportedByAll(selected)) {
153+
// Show a warning message
154+
$notice.children('.first').html(ns.t('core', 'notAllTextsChanged', {':language': ns.supportedLanguages[selected]}));
155+
$notice.children('.last').html(ns.t('core', 'ifYouWantTo', {':language': ns.supportedLanguages[selected], ':url': 'https://h5p.org/contributing#translating'}));
156+
$notice.addClass('show');
157+
}
158+
else {
159+
// Hide a warning message
160+
$notice.removeClass('show');
161+
}
162+
});
163+
confirmDialog.on('canceled', function () {
164+
$switcher.val(selected);
165+
});
166+
// Show
167+
confirmDialog.show($switcher.offset().top);
124168
});
125169

126170
// Add initial langauges for content type

scripts/h5peditor-library.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ ns.Library.prototype.loadLibrary = function (libraryName, preserveParams) {
381381

382382
this.$libraryWrapper.html(ns.t('core', 'loading')).attr('class', 'libwrap ' + libraryName.split(' ')[0].toLowerCase().replace('.', '-') + '-editor' + (this.libraries.length === 1 ? ' no-margin' : ''));
383383

384+
//TODO: Get language code from ancestor
384385
ns.loadLibrary(libraryName, function (semantics) {
385386
that.currentLibrary = libraryName;
386387
that.params.library = libraryName;

styles/css/application.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

styles/scss/application.scss

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,3 +1245,29 @@ a {
12451245
font-size: 15px;
12461246
}
12471247
}
1248+
.h5peditor-language-notice {
1249+
display: none;
1250+
clear: both;
1251+
font-size: 14px;
1252+
background: #dcf6ff;
1253+
color: #295b7a;
1254+
padding: 10px 20px 10px 40px;
1255+
line-height: 1.5;
1256+
position: relative;
1257+
1258+
&:before {
1259+
font-family: fixed;
1260+
content: "(!)";
1261+
position: absolute;
1262+
left: 15px;
1263+
}
1264+
&.show {
1265+
display: block;
1266+
}
1267+
.first {
1268+
font-weight: bold;
1269+
}
1270+
a {
1271+
text-decoration: underline;
1272+
}
1273+
}

0 commit comments

Comments
 (0)