Merge pull request #894 from ONLYOFFICE/fix/def-lang

Fix/def lang
This commit is contained in:
Julia Radzhabova 2021-05-21 17:14:13 +03:00 committed by GitHub
commit 5dc775f830
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 129 additions and 39 deletions

View file

@ -39,7 +39,8 @@ Common.Locale = new(function() {
var l10n = null; var l10n = null;
var loadcallback, var loadcallback,
apply = false, apply = false,
currentLang = 'en'; defLang = '{{DEFAULT_LANG}}',
currentLang = defLang;
var _applyLocalization = function(callback) { var _applyLocalization = function(callback) {
try { try {
@ -83,7 +84,11 @@ Common.Locale = new(function() {
}; };
var _getCurrentLanguage = function() { var _getCurrentLanguage = function() {
return (currentLang || 'en'); return currentLang;
};
var _getLoadedLanguage = function() {
return loadedLang;
}; };
var _getUrlParameterByName = function(name) { var _getUrlParameterByName = function(name) {
@ -94,23 +99,26 @@ Common.Locale = new(function() {
}; };
var _requireLang = function () { var _requireLang = function () {
var lang = (_getUrlParameterByName('lang') || 'en').split(/[\-_]/)[0]; var lang = (_getUrlParameterByName('lang') || defLang).split(/[\-_]/)[0];
currentLang = lang; currentLang = lang;
fetch('locale/' + lang + '.json') fetch('locale/' + lang + '.json')
.then(function(response) { .then(function(response) {
if (!response.ok) { if (!response.ok) {
currentLang = 'en'; currentLang = defLang;
if (lang != 'en') if (lang != defLang)
/* load default lang if fetch failed */ /* load default lang if fetch failed */
return fetch('locale/en.json'); return fetch('locale/' + defLang + '.json');
throw new Error('server error'); throw new Error('server error');
} }
return response.json(); return response.json();
}).then(function(response) { }).then(function(response) {
if ( response.then ) if ( response.json ) {
if (!response.ok)
throw new Error('server error');
return response.json(); return response.json();
else { } else {
l10n = response; l10n = response;
/* to break promises chain */ /* to break promises chain */
throw new Error('loaded'); throw new Error('loaded');
@ -122,8 +130,10 @@ Common.Locale = new(function() {
l10n = l10n || {}; l10n = l10n || {};
apply && _applyLocalization(); apply && _applyLocalization();
if ( e.message == 'loaded' ) { if ( e.message == 'loaded' ) {
} else } else {
currentLang = null;
console.log('fetch error: ' + e); console.log('fetch error: ' + e);
}
}); });
}; };

View file

@ -632,7 +632,7 @@ define([
this.$window = $('#' + this.initConfig.id); this.$window = $('#' + this.initConfig.id);
if (Common.Locale.getCurrentLanguage() !== 'en') if (Common.Locale.getCurrentLanguage() && Common.Locale.getCurrentLanguage() !== 'en')
this.$window.attr('applang', Common.Locale.getCurrentLanguage()); this.$window.attr('applang', Common.Locale.getCurrentLanguage());
this.binding.keydown = _.bind(_keydown,this); this.binding.keydown = _.bind(_keydown,this);

View file

@ -48,7 +48,7 @@ define([
'common/main/lib/view/ExternalDiagramEditor' 'common/main/lib/view/ExternalDiagramEditor'
], function () { 'use strict'; ], function () { 'use strict';
Common.Controllers.ExternalDiagramEditor = Backbone.Controller.extend(_.extend((function() { Common.Controllers.ExternalDiagramEditor = Backbone.Controller.extend(_.extend((function() {
var appLang = 'en', var appLang = '{{DEFAULT_LANG}}',
customization = undefined, customization = undefined,
targetApp = '', targetApp = '',
externalEditor = null, externalEditor = null,

View file

@ -48,7 +48,7 @@ define([
'common/main/lib/view/ExternalMergeEditor' 'common/main/lib/view/ExternalMergeEditor'
], function () { 'use strict'; ], function () { 'use strict';
Common.Controllers.ExternalMergeEditor = Backbone.Controller.extend(_.extend((function() { Common.Controllers.ExternalMergeEditor = Backbone.Controller.extend(_.extend((function() {
var appLang = 'en', var appLang = '{{DEFAULT_LANG}}',
customization = undefined, customization = undefined,
targetApp = '', targetApp = '',
externalEditor = null; externalEditor = null;

View file

@ -7,6 +7,8 @@ define([
], function () { ], function () {
'use strict'; 'use strict';
!Common.UI && (Common.UI = {});
Common.UI.Themes = new (function(locale) { Common.UI.Themes = new (function(locale) {
!locale && (locale = {}); !locale && (locale = {});
var themes_map = { var themes_map = {

View file

@ -1250,7 +1250,7 @@ define([
if (Asc.c_oLicenseResult.ExpiredLimited === licType) if (Asc.c_oLicenseResult.ExpiredLimited === licType)
this._state.licenseType = licType; this._state.licenseType = licType;
if ( this.onServerVersion(params.asc_getBuildVersion()) ) return; if ( this.onServerVersion(params.asc_getBuildVersion()) || !this.onLanguageLoaded()) return;
this.permissions.review = (this.permissions.review === undefined) ? (this.permissions.edit !== false) : this.permissions.review; this.permissions.review = (this.permissions.review === undefined) ? (this.permissions.edit !== false) : this.permissions.review;
@ -2476,6 +2476,18 @@ define([
this._renameDialog.show(Common.Utils.innerWidth() - this._renameDialog.options.width - 15, 30); this._renameDialog.show(Common.Utils.innerWidth() - this._renameDialog.options.width - 15, 30);
}, },
onLanguageLoaded: function() {
if (!Common.Locale.getCurrentLanguage()) {
Common.UI.warning({
msg: this.errorLang,
buttons: [],
closable: false
});
return false;
}
return true;
},
leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.', leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.',
criticalErrorTitle: 'Error', criticalErrorTitle: 'Error',
notcriticalErrorTitle: 'Warning', notcriticalErrorTitle: 'Warning',
@ -2844,7 +2856,8 @@ define([
txtNoTableOfFigures: "No table of figures entries found.", txtNoTableOfFigures: "No table of figures entries found.",
txtTableOfFigures: 'Table of figures', txtTableOfFigures: 'Table of figures',
txtStyle_endnote_text: 'Endnote Text', txtStyle_endnote_text: 'Endnote Text',
txtTOCHeading: 'TOC Heading' txtTOCHeading: 'TOC Heading',
errorLang: 'The interface language is not loaded.<br>Please contact your Document Server administrator.'
} }
})(), DE.Controllers.Main || {})) })(), DE.Controllers.Main || {}))
}); });

View file

@ -1520,7 +1520,7 @@ define([
Common.UI.BaseView.prototype.initialize.call(this,arguments); Common.UI.BaseView.prototype.initialize.call(this,arguments);
this.menu = options.menu; this.menu = options.menu;
this.urlPref = 'resources/help/en/'; this.urlPref = 'resources/help/{{DEFAULT_LANG}}/';
this.openUrl = null; this.openUrl = null;
this.en_data = [ this.en_data = [
@ -1638,12 +1638,12 @@ define([
var config = { var config = {
dataType: 'json', dataType: 'json',
error: function () { error: function () {
if ( me.urlPref.indexOf('resources/help/en/')<0 ) { if ( me.urlPref.indexOf('resources/help/{{DEFAULT_LANG}}/')<0 ) {
me.urlPref = 'resources/help/en/'; me.urlPref = 'resources/help/{{DEFAULT_LANG}}/';
store.url = 'resources/help/en/Contents.json'; store.url = 'resources/help/{{DEFAULT_LANG}}/Contents.json';
store.fetch(config); store.fetch(config);
} else { } else {
me.urlPref = 'resources/help/en/'; me.urlPref = 'resources/help/{{DEFAULT_LANG}}/';
store.reset(me.en_data); store.reset(me.en_data);
} }
}, },

View file

@ -783,7 +783,7 @@ define([
if (Asc.c_oLicenseResult.ExpiredLimited === licType) if (Asc.c_oLicenseResult.ExpiredLimited === licType)
me._state.licenseType = licType; me._state.licenseType = licType;
if ( me.onServerVersion(params.asc_getBuildVersion()) ) return; if ( me.onServerVersion(params.asc_getBuildVersion()) || !me.onLanguageLoaded()) return;
me.appOptions.permissionsLicense = licType; me.appOptions.permissionsLicense = licType;
me.permissions.review = (me.permissions.review === undefined) ? (me.permissions.edit !== false) : me.permissions.review; me.permissions.review = (me.permissions.review === undefined) ? (me.permissions.edit !== false) : me.permissions.review;
@ -1497,6 +1497,17 @@ define([
} }
}, },
onLanguageLoaded: function() {
if (!Common.Locale.getCurrentLanguage()) {
uiApp.modal({
title : this.notcriticalErrorTitle,
text : this.errorLang
});
return false;
}
return true;
},
leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' to await the autosave of the document. Click \'Leave this Page\' to discard all the unsaved changes.', leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' to await the autosave of the document. Click \'Leave this Page\' to discard all the unsaved changes.',
criticalErrorTitle: 'Error', criticalErrorTitle: 'Error',
notcriticalErrorTitle: 'Warning', notcriticalErrorTitle: 'Warning',
@ -1643,7 +1654,8 @@ define([
txtEvenPage: "Even Page", txtEvenPage: "Even Page",
txtOddPage: "Odd Page", txtOddPage: "Odd Page",
txtSameAsPrev: "Same as Previous", txtSameAsPrev: "Same as Previous",
txtCurrentDocument: "Current Document" txtCurrentDocument: "Current Document",
errorLang: 'The interface language is not loaded.<br>Please contact your Document Server administrator.'
} }
})(), DE.Controllers.Main || {})) })(), DE.Controllers.Main || {}))
}); });

View file

@ -976,7 +976,7 @@ define([
if (Asc.c_oLicenseResult.ExpiredLimited === licType) if (Asc.c_oLicenseResult.ExpiredLimited === licType)
this._state.licenseType = licType; this._state.licenseType = licType;
if ( this.onServerVersion(params.asc_getBuildVersion()) ) return; if ( this.onServerVersion(params.asc_getBuildVersion()) || !this.onLanguageLoaded() ) return;
if (params.asc_getRights() !== Asc.c_oRights.Edit) if (params.asc_getRights() !== Asc.c_oRights.Edit)
this.permissions.edit = false; this.permissions.edit = false;
@ -2107,6 +2107,18 @@ define([
this._renameDialog.show(Common.Utils.innerWidth() - this._renameDialog.options.width - 15, 30); this._renameDialog.show(Common.Utils.innerWidth() - this._renameDialog.options.width - 15, 30);
}, },
onLanguageLoaded: function() {
if (!Common.Locale.getCurrentLanguage()) {
Common.UI.warning({
msg: this.errorLang,
buttons: [],
closable: false
});
return false;
}
return true;
},
// Translation // Translation
leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.', leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.',
criticalErrorTitle: 'Error', criticalErrorTitle: 'Error',
@ -2469,7 +2481,8 @@ define([
textRenameLabel: 'Enter a name to be used for collaboration', textRenameLabel: 'Enter a name to be used for collaboration',
textRenameError: 'User name must not be empty.', textRenameError: 'User name must not be empty.',
textLongName: 'Enter a name that is less than 128 characters.', textLongName: 'Enter a name that is less than 128 characters.',
textGuest: 'Guest' textGuest: 'Guest',
errorLang: 'The interface language is not loaded.<br>Please contact your Document Server administrator.'
} }
})(), PE.Controllers.Main || {})) })(), PE.Controllers.Main || {}))
}); });

View file

@ -1321,7 +1321,7 @@ define([
Common.UI.BaseView.prototype.initialize.call(this,arguments); Common.UI.BaseView.prototype.initialize.call(this,arguments);
this.menu = options.menu; this.menu = options.menu;
this.urlPref = 'resources/help/en/'; this.urlPref = 'resources/help/{{DEFAULT_LANG}}/';
this.en_data = [ this.en_data = [
{"src": "ProgramInterface/ProgramInterface.htm", "name": "Introducing Presentation Editor user interface", "headername": "Program Interface"}, {"src": "ProgramInterface/ProgramInterface.htm", "name": "Introducing Presentation Editor user interface", "headername": "Program Interface"},
@ -1421,12 +1421,12 @@ define([
var config = { var config = {
dataType: 'json', dataType: 'json',
error: function () { error: function () {
if ( me.urlPref.indexOf('resources/help/en/')<0 ) { if ( me.urlPref.indexOf('resources/help/{{DEFAULT_LANG}}/')<0 ) {
me.urlPref = 'resources/help/en/'; me.urlPref = 'resources/help/{{DEFAULT_LANG}}/';
store.url = 'resources/help/en/Contents.json'; store.url = 'resources/help/{{DEFAULT_LANG}}/Contents.json';
store.fetch(config); store.fetch(config);
} else { } else {
me.urlPref = 'resources/help/en/'; me.urlPref = 'resources/help/{{DEFAULT_LANG}}/';
store.reset(me.en_data); store.reset(me.en_data);
} }
}, },

View file

@ -715,7 +715,7 @@ define([
if (Asc.c_oLicenseResult.ExpiredLimited === licType) if (Asc.c_oLicenseResult.ExpiredLimited === licType)
me._state.licenseType = licType; me._state.licenseType = licType;
if ( me.onServerVersion(params.asc_getBuildVersion()) ) return; if ( me.onServerVersion(params.asc_getBuildVersion()) || !me.onLanguageLoaded() ) return;
me.appOptions.permissionsLicense = licType; me.appOptions.permissionsLicense = licType;
me.permissions.review = (me.permissions.review === undefined) ? (me.permissions.edit !== false) : me.permissions.review; me.permissions.review = (me.permissions.review === undefined) ? (me.permissions.edit !== false) : me.permissions.review;
@ -1398,6 +1398,17 @@ define([
} }
}, },
onLanguageLoaded: function() {
if (!Common.Locale.getCurrentLanguage()) {
uiApp.modal({
title : this.notcriticalErrorTitle,
text : this.errorLang
});
return false;
}
return true;
},
// Translation // Translation
leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' to await the autosave of the document. Click \'Leave this Page\' to discard all the unsaved changes.', leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' to await the autosave of the document. Click \'Leave this Page\' to discard all the unsaved changes.',
criticalErrorTitle: 'Error', criticalErrorTitle: 'Error',
@ -1573,7 +1584,8 @@ define([
warnLicenseLimitedRenewed: 'License needs to be renewed.<br>You have a limited access to document editing functionality.<br>Please contact your administrator to get full access', warnLicenseLimitedRenewed: 'License needs to be renewed.<br>You have a limited access to document editing functionality.<br>Please contact your administrator to get full access',
warnLicenseLimitedNoAccess: 'License expired.<br>You have no access to document editing functionality.<br>Please contact your administrator.', warnLicenseLimitedNoAccess: 'License expired.<br>You have no access to document editing functionality.<br>Please contact your administrator.',
textGuest: 'Guest', textGuest: 'Guest',
txtAddFirstSlide: 'Click to add first slide' txtAddFirstSlide: 'Click to add first slide',
errorLang: 'The interface language is not loaded.<br>Please contact your Document Server administrator.'
} }
})(), PE.Controllers.Main || {})) })(), PE.Controllers.Main || {}))
}); });

View file

@ -1049,7 +1049,7 @@ define([
if (Asc.c_oLicenseResult.ExpiredLimited === licType) if (Asc.c_oLicenseResult.ExpiredLimited === licType)
this._state.licenseType = licType; this._state.licenseType = licType;
if ( this.onServerVersion(params.asc_getBuildVersion()) ) return; if ( this.onServerVersion(params.asc_getBuildVersion()) || !this.onLanguageLoaded() ) return;
if (params.asc_getRights() !== Asc.c_oRights.Edit) if (params.asc_getRights() !== Asc.c_oRights.Edit)
this.permissions.edit = false; this.permissions.edit = false;
@ -2452,6 +2452,18 @@ define([
this._renameDialog.show(Common.Utils.innerWidth() - this._renameDialog.options.width - 15, 30); this._renameDialog.show(Common.Utils.innerWidth() - this._renameDialog.options.width - 15, 30);
}, },
onLanguageLoaded: function() {
if (!Common.Locale.getCurrentLanguage()) {
Common.UI.warning({
msg: this.errorLang,
buttons: [],
closable: false
});
return false;
}
return true;
},
leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.', leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.',
criticalErrorTitle: 'Error', criticalErrorTitle: 'Error',
notcriticalErrorTitle: 'Warning', notcriticalErrorTitle: 'Warning',
@ -2849,7 +2861,8 @@ define([
errorPasteMultiSelect: 'This action cannot be done on a multiple range selection.<br>Select a single range and try again.', errorPasteMultiSelect: 'This action cannot be done on a multiple range selection.<br>Select a single range and try again.',
errorPivotWithoutUnderlying: 'The Pivot Table report was saved without the underlying data.<br>Use the \'Refresh\' button to update the report.', errorPivotWithoutUnderlying: 'The Pivot Table report was saved without the underlying data.<br>Use the \'Refresh\' button to update the report.',
txtQuarter: 'Qtr', txtQuarter: 'Qtr',
txtOr: '%1 or %2' txtOr: '%1 or %2',
errorLang: 'The interface language is not loaded.<br>Please contact your Document Server administrator.'
} }
})(), SSE.Controllers.Main || {})) })(), SSE.Controllers.Main || {}))
}); });

View file

@ -2176,7 +2176,7 @@ define([
Common.UI.BaseView.prototype.initialize.call(this,arguments); Common.UI.BaseView.prototype.initialize.call(this,arguments);
this.menu = options.menu; this.menu = options.menu;
this.urlPref = 'resources/help/en/'; this.urlPref = 'resources/help/{{DEFAULT_LANG}}/';
this.en_data = [ this.en_data = [
{"src": "ProgramInterface/ProgramInterface.htm", "name": "Introducing Spreadsheet Editor user interface", "headername": "Program Interface"}, {"src": "ProgramInterface/ProgramInterface.htm", "name": "Introducing Spreadsheet Editor user interface", "headername": "Program Interface"},
@ -2278,12 +2278,12 @@ define([
var config = { var config = {
dataType: 'json', dataType: 'json',
error: function () { error: function () {
if ( me.urlPref.indexOf('resources/help/en/')<0 ) { if ( me.urlPref.indexOf('resources/help/{{DEFAULT_LANG}}/')<0 ) {
me.urlPref = 'resources/help/en/'; me.urlPref = 'resources/help/{{DEFAULT_LANG}}/';
store.url = 'resources/help/en/Contents.json'; store.url = 'resources/help/{{DEFAULT_LANG}}/Contents.json';
store.fetch(config); store.fetch(config);
} else { } else {
me.urlPref = 'resources/help/en/'; me.urlPref = 'resources/help/{{DEFAULT_LANG}}/';
store.reset(me.en_data); store.reset(me.en_data);
} }
}, },

View file

@ -741,7 +741,7 @@ define([
if (Asc.c_oLicenseResult.ExpiredLimited === licType) if (Asc.c_oLicenseResult.ExpiredLimited === licType)
me._state.licenseType = licType; me._state.licenseType = licType;
if ( me.onServerVersion(params.asc_getBuildVersion()) ) return; if ( me.onServerVersion(params.asc_getBuildVersion()) || !me.onLanguageLoaded() ) return;
if (params.asc_getRights() !== Asc.c_oRights.Edit) { if (params.asc_getRights() !== Asc.c_oRights.Edit) {
me.permissions.edit = false; me.permissions.edit = false;
@ -1601,6 +1601,17 @@ define([
} }
}, },
onLanguageLoaded: function() {
if (!Common.Locale.getCurrentLanguage()) {
uiApp.modal({
title : this.notcriticalErrorTitle,
text : this.errorLang
});
return false;
}
return true;
},
leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' to await the autosave of the document. Click \'Leave this Page\' to discard all the unsaved changes.', leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' to await the autosave of the document. Click \'Leave this Page\' to discard all the unsaved changes.',
criticalErrorTitle: 'Error', criticalErrorTitle: 'Error',
notcriticalErrorTitle: 'Warning', notcriticalErrorTitle: 'Warning',
@ -1795,7 +1806,8 @@ define([
warnLicenseLimitedNoAccess: 'License expired.<br>You have no access to document editing functionality.<br>Please contact your administrator.', warnLicenseLimitedNoAccess: 'License expired.<br>You have no access to document editing functionality.<br>Please contact your administrator.',
textGuest: 'Guest', textGuest: 'Guest',
errorDataValidate: 'The value you entered is not valid.<br>A user has restricted values that can be entered into this cell.', errorDataValidate: 'The value you entered is not valid.<br>A user has restricted values that can be entered into this cell.',
errorLockedCellPivot: 'You cannot change data inside a pivot table.' errorLockedCellPivot: 'You cannot change data inside a pivot table.',
errorLang: 'The interface language is not loaded.<br>Please contact your Document Server administrator.'
} }
})(), SSE.Controllers.Main || {})) })(), SSE.Controllers.Main || {}))
}); });

View file

@ -66,6 +66,9 @@ module.exports = function(grunt) {
}, { }, {
from: /\{\{HELP_URL\}\}/g, from: /\{\{HELP_URL\}\}/g,
to: _encode(process.env.HELP_URL) || 'https://helpcenter.onlyoffice.com' to: _encode(process.env.HELP_URL) || 'https://helpcenter.onlyoffice.com'
}, {
from: /\{\{DEFAULT_LANG\}\}/g,
to: _encode(process.env.DEFAULT_LANG) || 'en'
}]; }];
var helpreplacements = [ var helpreplacements = [