From 9217340a9cb44ab7504b012f4bfcfacf06f1c1a6 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 12 Apr 2021 14:54:52 +0530 Subject: [PATCH] use the user's language for docs links for supported languages --- CHANGELOG.md | 3 +++ customize.dist/pages.js | 23 ++++++++++++++++++++--- customize.dist/pages/index.js | 2 +- www/common/common-ui-elements.js | 5 +++-- www/common/drive-ui.js | 10 ++++++---- www/common/inner/share.js | 5 +++-- www/common/sframe-common-file.js | 7 ++++--- www/common/sframe-common.js | 2 +- www/support/inner.js | 2 +- 9 files changed, 42 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c602e292..30e6a813b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ * prompt premium users to cancel their subscriptions before deleting their accounts * check that headers for XLSX export are correctly set via the checkup app * guard against some type errors in the support page +* remove default privacy policy +* remove HTML from most translations +* localize links to the docs where a translation exists # 4.3.1 diff --git a/customize.dist/pages.js b/customize.dist/pages.js index c27a38814..283bd0876 100644 --- a/customize.dist/pages.js +++ b/customize.dist/pages.js @@ -12,9 +12,6 @@ define([ return e; }; - // TODO make a docsLink function which wraps this - // and points to the appropriate translation: - // French, German, or English as a default Pages.externalLink = function (el, href) { if (!el) { return el; } el.setAttribute("rel", "noopener noreferrer"); @@ -25,6 +22,26 @@ define([ return el; }; + // this rewrites URLS to point to the appropriate translation: + // French, German, or English as a default + var documentedLanguages = ['en', 'fr', 'de']; + Pages.localizeDocsLink = function (href) { + try { + var lang = Msg._getLanguage(); + if (documentedLanguages.indexOf(lang) > 0) { + return href.replace('/en/', '/' + lang + '/'); + } + } catch (err) { + console.error(err); + // if it fails just use the default href (English) + } + return href; + }; + + Pages.documentationLink = function (el, href) { + return Pages.externalLink(el, Pages.localizeDocsLink(href)); + }; + var languageSelector = function () { var options = []; var languages = Msg._languages; diff --git a/customize.dist/pages/index.js b/customize.dist/pages/index.js index 7a436b61d..3257126e9 100644 --- a/customize.dist/pages/index.js +++ b/customize.dist/pages/index.js @@ -81,7 +81,7 @@ define([ } var supportText = Pages.setHTML(h('span'), Msg.home_support); - Pages.externalLink(supportText.querySelector('a'), "https://docs.cryptpad.fr/en/how_to_contribute.html"); + Pages.documentationLink(supportText.querySelector('a'), "https://docs.cryptpad.fr/en/how_to_contribute.html"); var opensource = Pages.setHTML(h('p'), Msg.home_opensource); Pages.externalLink(opensource.querySelector('a'), "https://github.com/xwiki-labs/cryptpad"); diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index c004421ac..05390628c 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -369,7 +369,7 @@ define([ h('div.cp-teams-invite-block', [ h('span', Messages.team_inviteLinkSetPassword), h('a.cp-teams-help.fa.fa-question-circle', { - href: origin + 'https://docs.cryptpad.fr/en/user_guide/security.html#passwords-for-documents-and-folders', + href: origin + Pages.localizeDocsLink('https://docs.cryptpad.fr/en/user_guide/security.html#passwords-for-documents-and-folders'), target: "_blank", 'data-tippy-placement': "right" }) @@ -1111,6 +1111,7 @@ define([ if (apps[type]) { href = "https://docs.cryptpad.fr/en/user_guide/apps/" + apps[type] + ".html"; } + href = Pages.localizeDocsLink(href); var content = setHTML(h('p'), Messages.help_genericMore); $(content).find('a').attr({ @@ -2147,7 +2148,7 @@ define([ UI.getFileIcon({type: type})[0], h('div.cp-creation-title-text', [ h('span', newPadH3Title), - createHelper('https://docs.cryptpad.fr/en/user_guide/apps/general.html#new-document', Messages.creation_helperText) + createHelper(Pages.localizeDocsLink('https://docs.cryptpad.fr/en/user_guide/apps/general.html#new-document'), Messages.creation_helperText) ]) ]); $creation.append(title); diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index 6a2a5b53d..87825e0f4 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -19,6 +19,7 @@ define([ '/common/proxy-manager.js', '/customize/application_config.js', '/customize/messages.js', + '/customize/pages.js', ], function ( $, ApiConfig, @@ -37,7 +38,8 @@ define([ h, ProxyManager, AppConfig, - Messages) + Messages, + Pages) { var APP = window.APP = { @@ -2490,7 +2492,7 @@ define([ // Get the upload options var addSharedFolderModal = function (cb) { - var docsHref = common.getBounceURL("https://docs.cryptpad.fr/en/user_guide/share_and_access.html#owners"); + var docsHref = common.getBounceURL(Pages.localizeDocsLink("https://docs.cryptpad.fr/en/user_guide/share_and_access.html#owners")); // Ask for name, password and owner var content = h('div', [ @@ -2503,7 +2505,7 @@ define([ style: 'display:flex;align-items:center;justify-content:space-between' }, [ UI.createCheckbox('cp-app-drive-sf-owned', Messages.sharedFolders_create_owned, true), - UI.createHelper(docsHref, Messages.creation_owned1) // TODO + UI.createHelper(docsHref, Messages.creation_owned1) ]), ]); @@ -4393,7 +4395,7 @@ define([ style: 'display:flex;align-items:center;justify-content:space-between' }, [ UI.createCheckbox('cp-upload-owned', Messages.sharedFolders_create_owned, true), - UI.createHelper('https://docs.cryptpad.fr/en/user_guide/share_and_access.html#owners', Messages.creation_owned1) + UI.createHelper(Pages.localizeDocsLink('https://docs.cryptpad.fr/en/user_guide/share_and_access.html#owners'), Messages.creation_owned1) ]), ]); return void UI.confirm(convertContent, function(res) { diff --git a/www/common/inner/share.js b/www/common/inner/share.js index 614fc23e7..860eb5566 100644 --- a/www/common/inner/share.js +++ b/www/common/inner/share.js @@ -10,8 +10,9 @@ define([ '/common/clipboard.js', '/customize/messages.js', '/bower_components/nthen/index.js', + '/customize/pages.js', ], function ($, Util, Hash, UI, UIElements, Feedback, Modal, h, Clipboard, - Messages, nThen) { + Messages, nThen, Pages) { var Share = {}; var createShareWithFriends = function (config, onShare, linkGetter) { @@ -252,7 +253,7 @@ define([ h('a', {href: '#'}, Messages.passwordFaqLink) ]); $(link).click(function () { - opts.common.openUnsafeURL("https://docs.cryptpad.fr/en/user_guide/security.html#passwords-for-documents-and-folders"); + opts.common.openUnsafeURL(Pages.localizeDocsLink("https://docs.cryptpad.fr/en/user_guide/security.html#passwords-for-documents-and-folders")); }); return link; }; diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index fb432b5ad..c7a66adb9 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -10,10 +10,11 @@ define([ '/common/common-hash.js', '/common/hyperscript.js', '/customize/messages.js', + '/customize/pages.js', '/bower_components/file-saver/FileSaver.min.js', '/bower_components/tweetnacl/nacl-fast.min.js', -], function ($, ApiConfig, FileCrypto, MakeBackup, Thumb, UI, UIElements, Util, Hash, h, Messages) { +], function ($, ApiConfig, FileCrypto, MakeBackup, Thumb, UI, UIElements, Util, Hash, h, Messages, Pages) { var Nacl = window.nacl; var module = {}; @@ -327,7 +328,7 @@ define([ style: 'display:flex;align-items:center;justify-content:space-between' }, [ UI.createCheckbox('cp-upload-owned', Messages.upload_modal_owner, modalState.owned), - createHelper('https://docs.cryptpad.fr/en/user_guide/share_and_access.html#owners', Messages.creation_owned1) + createHelper(Pages.localizeDocsLink('https://docs.cryptpad.fr/en/user_guide/share_and_access.html#owners'), Messages.creation_owned1) ]), manualStore ]); @@ -382,7 +383,7 @@ define([ style: 'display:flex;align-items:center;justify-content:space-between' }, [ UI.createCheckbox('cp-upload-owned', Messages.uploadFolder_modal_owner, modalState.owned), - createHelper('https://docs.cryptpad.fr/en/user_guide/share_and_access.html#owners', Messages.creation_owned1) + createHelper(Pages.localizeDocsLink('https://docs.cryptpad.fr/en/user_guide/share_and_access.html#owners'), Messages.creation_owned1) ]), manualStore ]); diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 0404af648..3043ab039 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -774,7 +774,7 @@ define([ if (i) { i.classList = 'fa fa-shhare-alt'; } var a = error.querySelector('a'); if (a) { - a.setAttribute('href', "https://docs.cryptpad.fr/en/user_guide/user_account.html#confidentiality"); + a.setAttribute('href', Pages.localizeDocsLink("https://docs.cryptpad.fr/en/user_guide/user_account.html#confidentiality")); } UI.errorLoadingScreen(error); }); diff --git a/www/support/inner.js b/www/support/inner.js index 1285c1133..f466e7693 100644 --- a/www/support/inner.js +++ b/www/support/inner.js @@ -170,7 +170,7 @@ define([ create['form'] = function () { var key = 'form'; var $div = makeBlock(key, true); // Msg.support_formHint, .support_formTitle, .support_formButton - Pages.externalLink($div.find('a')[0], 'https://docs.cryptpad.fr/en/user_guide/index.html'); + Pages.documentationLink($div.find('a')[0], 'https://docs.cryptpad.fr/en/user_guide/index.html'); var form = APP.support.makeForm();