diff --git a/apps/documenteditor/mobile/src/controller/Main.jsx b/apps/documenteditor/mobile/src/controller/Main.jsx index 17960c6079..9e970a1990 100644 --- a/apps/documenteditor/mobile/src/controller/Main.jsx +++ b/apps/documenteditor/mobile/src/controller/Main.jsx @@ -20,7 +20,7 @@ import EncodingController from "./Encoding"; import DropdownListController from "./DropdownList"; import { Device } from '../../../../common/mobile/utils/device'; import { processArrayScripts } from '../../../../common/mobile/utils/processArrayScripts.js'; - +import '../../../../common/main/lib/util/LanguageInfo.js' @inject( "users", "storeAppOptions", @@ -186,6 +186,9 @@ class MainController extends Component { this.props.storeAppOptions.wopi = this.editorConfig.wopi; Common.Notifications.trigger('configOptionsFill'); + + this.loadDefaultMetricSettings(); + }; const loadDocument = data => { @@ -496,6 +499,36 @@ class MainController extends Component { } } + loadDefaultMetricSettings() { + const appOptions = this.props.storeAppOptions; + let region = ''; + + if (appOptions.location) { + console.log("Obsolete: The 'location' parameter of the 'editorConfig' section is deprecated. Please use 'region' parameter in the 'editorConfig' section instead."); + region = appOptions.location; + } else if (appOptions.region) { + let val = appOptions.region; + val = Common.util.LanguageInfo.getLanguages().hasOwnProperty(val) ? Common.util.LanguageInfo.getLocalLanguageName(val)[0] : val; + + if (val && typeof val === 'string') { + let arr = val.split(/[\-_]/); + if (arr.length > 1) region = arr[arr.length - 1] + } + } else { + let arr = (appOptions.lang || 'en').split(/[\-_]/); + + if (arr.length > 1) region = arr[arr.length - 1] + if (!region) { + arr = (navigator.language || '').split(/[\-_]/); + if (arr.length > 1) region = arr[arr.length - 1] + } + } + + if (/^(ca|us)$/i.test(region)) { + Common.Utils.Metric.setDefaultMetric(Common.Utils.Metric.c_MetricUnits.inch); + } + } + changeEditorBrandColorForPdf() { const bodyElement = document.body; bodyElement.classList.add('pdf-view'); diff --git a/apps/documenteditor/mobile/src/store/appOptions.js b/apps/documenteditor/mobile/src/store/appOptions.js index 032bc7519d..10513b6f84 100644 --- a/apps/documenteditor/mobile/src/store/appOptions.js +++ b/apps/documenteditor/mobile/src/store/appOptions.js @@ -125,6 +125,7 @@ export class storeAppOptions { this.createUrl = config.createUrl; this.lang = config.lang ?? 'en'; this.location = (typeof (config.location) == 'string') ? config.location.toLowerCase() : ''; + this.region = (typeof (config.region) == 'string') ? config.region.toLowerCase() : config.region; this.sharingSettingsUrl = config.sharingSettingsUrl; this.canRequestSharingSettings = config.canRequestSharingSettings; this.fileChoiceUrl = config.fileChoiceUrl; diff --git a/apps/presentationeditor/mobile/src/controller/Main.jsx b/apps/presentationeditor/mobile/src/controller/Main.jsx index 236d2e1a14..3c190aa293 100644 --- a/apps/presentationeditor/mobile/src/controller/Main.jsx +++ b/apps/presentationeditor/mobile/src/controller/Main.jsx @@ -17,6 +17,7 @@ import PluginsController from '../../../../common/mobile/lib/controller/Plugins. import { Device } from '../../../../common/mobile/utils/device'; import { Themes } from '../../../../common/mobile/lib/controller/Themes.jsx'; import { processArrayScripts } from '../../../../common/mobile/utils/processArrayScripts.js'; +import '../../../../common/main/lib/util/LanguageInfo.js' @inject( "users", @@ -128,6 +129,8 @@ class MainController extends Component { value = LocalStorage.getItem("pe-mobile-allow-macros-request"); this.props.storeApplicationSettings.changeMacrosRequest((value !== null) ? parseInt(value) : 0); + + this.loadDefaultMetricSettings(); }; const loadDocument = data => { @@ -317,6 +320,36 @@ class MainController extends Component { window.onunload = this.onUnload.bind(this); } + loadDefaultMetricSettings() { + const appOptions = this.props.storeAppOptions; + let region = ''; + + if (appOptions.location) { + console.log("Obsolete: The 'location' parameter of the 'editorConfig' section is deprecated. Please use 'region' parameter in the 'editorConfig' section instead."); + region = appOptions.location; + } else if (appOptions.region) { + let val = appOptions.region; + val = Common.util.LanguageInfo.getLanguages().hasOwnProperty(val) ? Common.util.LanguageInfo.getLocalLanguageName(val)[0] : val; + + if (val && typeof val === 'string') { + let arr = val.split(/[\-_]/); + if (arr.length > 1) region = arr[arr.length - 1] + } + } else { + let arr = (appOptions.lang || 'en').split(/[\-_]/); + + if (arr.length > 1) region = arr[arr.length - 1] + if (!region) { + arr = (navigator.language || '').split(/[\-_]/); + if (arr.length > 1) region = arr[arr.length - 1] + } + } + + if (/^(ca|us)$/i.test(region)) { + Common.Utils.Metric.setDefaultMetric(Common.Utils.Metric.c_MetricUnits.inch); + } + } + onDocumentModifiedChanged () { const isModified = this.api.asc_isDocumentCanSave(); if (this._state.isDocModified !== isModified) { diff --git a/apps/presentationeditor/mobile/src/store/appOptions.js b/apps/presentationeditor/mobile/src/store/appOptions.js index ad9351c67f..606fb9486e 100644 --- a/apps/presentationeditor/mobile/src/store/appOptions.js +++ b/apps/presentationeditor/mobile/src/store/appOptions.js @@ -60,6 +60,7 @@ export class storeAppOptions { this.createUrl = config.createUrl; this.lang = config.lang; this.location = (typeof (config.location) == 'string') ? config.location.toLowerCase() : ''; + this.region = (typeof (config.region) == 'string') ? config.region.toLowerCase() : config.region; this.sharingSettingsUrl = config.sharingSettingsUrl; this.fileChoiceUrl = config.fileChoiceUrl; this.mergeFolderUrl = config.mergeFolderUrl; diff --git a/apps/spreadsheeteditor/mobile/src/controller/Main.jsx b/apps/spreadsheeteditor/mobile/src/controller/Main.jsx index 2381a6a606..47b46ed26e 100644 --- a/apps/spreadsheeteditor/mobile/src/controller/Main.jsx +++ b/apps/spreadsheeteditor/mobile/src/controller/Main.jsx @@ -24,6 +24,7 @@ import { StatusbarController } from "./Statusbar"; import { Device } from '../../../../common/mobile/utils/device'; import { Themes } from '../../../../common/mobile/lib/controller/Themes.jsx'; import { processArrayScripts } from '../../../../common/mobile/utils/processArrayScripts.js'; +import '../../../../common/main/lib/util/LanguageInfo.js' @inject( "users", @@ -188,7 +189,7 @@ class MainController extends Component { EditorUIController.isSupportEditFeature(); this.editorConfig = Object.assign({}, this.editorConfig, data.config); - this.appOptions.lang = this.editorConfig.lang; + this.appOptions.lang = this.editorConfig.lang; const appOptions = this.props.storeAppOptions; appOptions.setConfigOptions(this.editorConfig, _t); @@ -204,30 +205,27 @@ class MainController extends Component { if (value !== null) { this.api.asc_setLocale(parseInt(value)); } else { - value = appOptions.region; - value = Common.util.LanguageInfo.getLanguages().hasOwnProperty(value) ? value : Common.util.LanguageInfo.getLocalLanguageCode(value); - if (value !== null) { - value = parseInt(value); - } else { - value = (appOptions.lang) ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(appOptions.lang)) : 0x0409; - } - this.api.asc_setLocale(value); + value = appOptions.region; + value = Common.util.LanguageInfo.getLanguages().hasOwnProperty(value) ? value : Common.util.LanguageInfo.getLocalLanguageCode(value); + if (value !== null) { + value = parseInt(value); + } else { + value = (appOptions.lang) ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(appOptions.lang)) : 0x0409; + } + this.api.asc_setLocale(value); } - if (appOptions.location == 'us' || appOptions.location == 'ca') { - Common.Utils.Metric.setDefaultMetric(Common.Utils.Metric.c_MetricUnits.inch); - } - - //if (!appOptions.customization || !(appOptions.customization.loaderName || appOptions.customization.loaderLogo)) - //$('#editor_sdk').append('