From 896d3a402ce4d26f9134ba588a7cc88aebc2d556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 4 Jul 2019 17:41:09 +0200 Subject: [PATCH] Add BCP47 to helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/document.js | 18 ++++++++---------- src/helpers/index.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 src/helpers/index.js diff --git a/src/document.js b/src/document.js index b9e297d4a..d0e2cc687 100644 --- a/src/document.js +++ b/src/document.js @@ -1,3 +1,5 @@ +import { getRootPath } from 'nextcloud-server/dist/router' +import { languageToBCP47 } from './helpers' /* TODO: move to one object */ /* global richdocuments_directEdit richdocuments_fileId richdocuments_urlsrc richdocuments_token richdocuments_path richdocuments_permissions richdocuments_title getURLParameter richdocuments_canonical_webroot */ @@ -142,11 +144,11 @@ var documentsMain = { // generates docKey for given fileId _generateDocKey: function(wopiFileId) { - var ocurl = OC.getRootPath() + '/index.php/apps/richdocuments/wopi/files/' + wopiFileId + var ocurl = getRootPath() + '/index.php/apps/richdocuments/wopi/files/' + wopiFileId if (richdocuments_canonical_webroot) { if (!richdocuments_canonical_webroot.startsWith('/')) { richdocuments_canonical_webroot = '/' + richdocuments_canonical_webroot } - ocurl = ocurl.replace(OC.getRootPath(), richdocuments_canonical_webroot) + ocurl = ocurl.replace(getRootPath(), richdocuments_canonical_webroot) } return ocurl @@ -165,10 +167,6 @@ var documentsMain = { return null }, - getLanguage: function() { - return OC.getLanguage ? OC.getLanguage() : OC.getLocale() - }, - UI: { /* Editor wrapper HTML */ container: '
' @@ -380,7 +378,7 @@ var documentsMain = { // WOPISrc - URL that loolwsd will access (ie. pointing to ownCloud) // index.php is forced here to avoid different wopi srcs for the same document - var wopiurl = window.location.protocol + '//' + window.location.host + OC.getRootPath() + '/index.php/apps/richdocuments/wopi/files/' + fileId + var wopiurl = window.location.protocol + '//' + window.location.host + getRootPath() + '/index.php/apps/richdocuments/wopi/files/' + fileId var wopisrc = encodeURIComponent(wopiurl) // urlsrc - the URL from discovery xml that we access for the particular @@ -390,7 +388,7 @@ var documentsMain = { var urlsrc = documentsMain.urlsrc + 'WOPISrc=' + wopisrc + '&title=' + encodeURIComponent(title) - + '&lang=' + documentsMain.getLanguage().replace('_', '-') // loleaflet expects a BCP47 language tag syntax + + '&lang=' + languageToBCP47() + '&permission=readonly' // access_token - must be passed via a form post @@ -562,7 +560,7 @@ var documentsMain = { $(document.body).prepend(documentsMain.UI.container) // WOPISrc - URL that loolwsd will access (ie. pointing to ownCloud) - var wopiurl = window.location.protocol + '//' + window.location.host + OC.getRootPath() + '/index.php/apps/richdocuments/wopi/files/' + documentsMain.fileId + var wopiurl = window.location.protocol + '//' + window.location.host + getRootPath() + '/index.php/apps/richdocuments/wopi/files/' + documentsMain.fileId var wopisrc = encodeURIComponent(wopiurl) // urlsrc - the URL from discovery xml that we access for the particular @@ -572,7 +570,7 @@ var documentsMain = { var urlsrc = documentsMain.urlsrc + 'WOPISrc=' + wopisrc + '&title=' + encodeURIComponent(title) - + '&lang=' + documentsMain.getLanguage().replace(/^([a-z]{2}).*_([A-Z]{2})$/, function(match, p1, p2) { return p1 + '-' + p2.toLowerCase() }) // loleaflet expects a BCP47 language tag syntax + + '&lang=' + languageToBCP47() + '&closebutton=1' + '&revisionhistory=1' if (!documentsMain.canEdit || action === 'view') { diff --git a/src/helpers/index.js b/src/helpers/index.js new file mode 100644 index 000000000..bebca3fc6 --- /dev/null +++ b/src/helpers/index.js @@ -0,0 +1,33 @@ +/* + * @copyright Copyright (c) 2019 Julius Härtl + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +import { getLanguage } from 'nextcloud-server/dist/l10n' + +const languageToBCP47 = () => { + // loleaflet expects a BCP47 language tag syntax + return getLanguage() + .replace(/^([a-z]{2}).*_([A-Z]{2})$/, (match, p1, p2) => p1 + '-' + p2.toLowerCase()) +} + +export { + languageToBCP47 +}