use the user's language for docs links for supported languages

This commit is contained in:
ansuz 2021-04-12 14:54:52 +05:30
parent e4403719d4
commit 9217340a9c
9 changed files with 42 additions and 17 deletions

View File

@ -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

View File

@ -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;

View File

@ -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");

View File

@ -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);

View File

@ -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) {

View File

@ -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;
};

View File

@ -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
]);

View File

@ -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);
});

View File

@ -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();