From d65285923f6bd31283d81aae333ab99d99b6d270 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Mon, 13 May 2024 13:01:18 +0200 Subject: [PATCH] Documentation link in task application. --- conversejs/build-conversejs-patch-i18n.js | 4 ++ .../plugins/tasks/templates/muc-task-app.js | 15 ++++--- .../custom/shared/components/font-awesome.js | 11 +++-- conversejs/custom/shared/lib/help.js | 44 +++++++++++++++++++ conversejs/loc.keys.js | 2 +- languages/en.yml | 3 -- 6 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 conversejs/custom/shared/lib/help.js diff --git a/conversejs/build-conversejs-patch-i18n.js b/conversejs/build-conversejs-patch-i18n.js index ec2325d5..eca841ac 100644 --- a/conversejs/build-conversejs-patch-i18n.js +++ b/conversejs/build-conversejs-patch-i18n.js @@ -54,6 +54,10 @@ function patch (lang) { const label = labels[key] patchLabel(destContent, label, yaml[key] ?? '') } + + // We add an extra _livechat_language, so we can compute url to documentation + // (same thing as _language in build-languages.js) + patchLabel(destContent, '_livechat_language', lang) fs.writeFileSync(destFile, destContent.join('\n')) } diff --git a/conversejs/custom/plugins/tasks/templates/muc-task-app.js b/conversejs/custom/plugins/tasks/templates/muc-task-app.js index 5545810e..ef82e064 100644 --- a/conversejs/custom/plugins/tasks/templates/muc-task-app.js +++ b/conversejs/custom/plugins/tasks/templates/muc-task-app.js @@ -1,3 +1,4 @@ +import { converseLocalizedHelpUrl } from '../../../shared/lib/help' import { html } from 'lit' import { __ } from 'i18n' @@ -23,15 +24,19 @@ export function tplMUCTaskApp (el, mucModel) { // eslint-disable-next-line no-undef const i18nTasks = __(LOC_tasks) // eslint-disable-next-line no-undef - const i18nHint = __(LOC_task_app_info) + const i18nHelp = __(LOC_online_help) + const helpUrl = converseLocalizedHelpUrl({ + page: 'documentation/user/streamers/tasks' + }) + return html`
${i18nTasks}
- + title="${i18nHelp}" + > diff --git a/conversejs/custom/shared/components/font-awesome.js b/conversejs/custom/shared/components/font-awesome.js index 7225e544..132db080 100644 --- a/conversejs/custom/shared/components/font-awesome.js +++ b/conversejs/custom/shared/components/font-awesome.js @@ -11,9 +11,14 @@ export default () => { - - - + + + + + + + + ` } diff --git a/conversejs/custom/shared/lib/help.js b/conversejs/custom/shared/lib/help.js new file mode 100644 index 00000000..c3feb529 --- /dev/null +++ b/conversejs/custom/shared/lib/help.js @@ -0,0 +1,44 @@ +import { __ } from 'i18n' + +/** + * Returns the current language code. + * This is the code that correspond to the path for localized documentation + * (in other words: 'fr', not 'fr-FR'). + * This is the 'ConverseJS version' of the same function in `client/utils/help`. + * @returns language code + */ +function getLangCode () { + // See the build-languages.js script for more information about this trick. + const s = __('_livechat_language') + if (s === '_livechat_language') { + return 'en' + } + return s +} + +function helpUrl (options) { + let url = 'https://livingston.frama.io/peertube-plugin-livechat/' + if (options.lang && /^[a-zA-Z_-]+$/.test(options.lang)) { + url = url + options.lang + '/' + } + if (options.page && /^[\w/-]+$/.test(options.page)) { + url = url + options.page + '/' + } + return url +} + +/** + * Returns the url of the documentation, in the current user language. + * This is the 'ConverseJS version' of the same function in `client/utils/help`. +*/ +function converseLocalizedHelpUrl (helpUrlOptions) { + const lang = getLangCode().toLowerCase() // lowercase is needed for zh-hans for example + if (lang === 'en') { + return helpUrl(helpUrlOptions) + } + return helpUrl(Object.assign({}, helpUrlOptions, { lang })) +} + +export { + converseLocalizedHelpUrl +} diff --git a/conversejs/loc.keys.js b/conversejs/loc.keys.js index ee31e53a..67e2f163 100644 --- a/conversejs/loc.keys.js +++ b/conversejs/loc.keys.js @@ -16,6 +16,7 @@ const locKeys = [ 'login_remote_peertube_video_not_found_try_anyway_button', 'login_remote_peertube_video_open_failed', 'login_external_auth_alert_message', + 'online_help', 'tasks', 'task_list_create', 'task_list_create_error', @@ -27,7 +28,6 @@ const locKeys = [ 'task_description', 'task_delete', 'task_delete_confirm', - 'task_app_info', 'task_list_pick_title', 'task_list_pick_empty', 'task_list_pick_message' diff --git a/languages/en.yml b/languages/en.yml index ae5b8ebf..a8e8b333 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -446,9 +446,6 @@ task_name: 'Task name' task_description: 'Description' task_delete: 'Delete task' task_delete_confirm: 'Are you sure you want to delete this task?' -task_app_info: | - You can create tasks and task lists, which are shared between all room's admins. - See the livechat streamers documentation for more information. task_list_pick_title: 'Please choose a task list' task_list_pick_empty: 'There is no task list for now, please first create one' task_list_pick_message: |