Localized help urls:

Links to documentation are now using the front-end language to point to the translated documentation page
(except for some links generated from the backend, in the diagnostic tool for example).

Partial fix for #224.
This commit is contained in:
John Livingston
2023-09-06 17:58:54 +02:00
parent 21de3404c3
commit 5ecff1d916
5 changed files with 57 additions and 8 deletions

37
client/utils/help.ts Normal file
View File

@ -0,0 +1,37 @@
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import { helpUrl } from 'shared/lib/help'
/**
* Returns the current language code.
* This is the code that correspond to the path for localized documentation
* (in other words: 'fr', not 'fr-FR')
* @param clientOptions client options
* @returns language code
*/
async function getLangCode ({ peertubeHelpers }: RegisterClientOptions): Promise<string> {
// See the build-languages.js script for more information about this trick.
const s = await peertubeHelpers.translate('_language')
if (s === '_language') {
return 'en'
}
return s
}
/**
* Returns the url of the documentation, in the current user language.
* @param clientOptions client options
*/
async function localizedHelpUrl (
clientOptions: RegisterClientOptions,
helpUrlOptions: Parameters<typeof helpUrl>[0]
): Promise<string> {
const lang = (await getLangCode(clientOptions)).toLowerCase() // lowercase is needed for zh-hans for example
if (lang === 'en') {
return helpUrl(helpUrlOptions)
}
return helpUrl(Object.assign({}, helpUrlOptions, { lang }))
}
export {
localizedHelpUrl
}

View File

@ -1,7 +1,7 @@
import type { Video } from '@peertube/peertube-types'
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import { videoHasWebchat, videoHasRemoteWebchat } from 'shared/lib/video'
import { helpUrl } from 'shared/lib/help'
import { localizedHelpUrl } from './utils/help'
import { logger } from './videowatch/logger'
import { closeSVG, openBlankChatSVG, openChatSVG, shareChatUrlSVG, helpButtonSVG } from './videowatch/buttons'
import { displayButton, displayButtonOptions } from './videowatch/button'
@ -74,6 +74,9 @@ function register (registerOptions: RegisterClientOptions): void {
container: HTMLElement, video: Video, showOpenBlank: boolean, showShareUrlButton: boolean
): Promise<void> {
logger.log('Adding livechat in the DOM...')
const viewersDocumentationHelpUrl = await localizedHelpUrl(registerOptions, {
page: 'documentation/user/viewers'
})
const p = new Promise<void>((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Promise.all([
@ -137,9 +140,7 @@ function register (registerOptions: RegisterClientOptions): void {
buttonContainer,
name: 'help',
label: labelHelp,
href: helpUrl({
page: 'documentation/user/viewers'
}),
href: viewersDocumentationHelpUrl,
targetBlank: true,
icon: helpButtonSVG,
additionalClasses: []

View File

@ -4,7 +4,7 @@ import { helpButtonSVG } from './buttons'
import { logger } from './logger'
import { getIframeUri, getXMPPAddr, UriOptions } from './uri'
import { isAutoColorsAvailable } from 'shared/lib/autocolors'
import { helpUrl } from 'shared/lib/help'
import { localizedHelpUrl } from '../utils/help'
interface ShareForm {
shareString: HTMLInputElement
@ -25,6 +25,10 @@ interface ShareForm {
async function shareChatUrl (registerOptions: RegisterClientOptions, settings: any, video: Video): Promise<void> {
const peertubeHelpers = registerOptions.peertubeHelpers
const streamersHelpUrl = await localizedHelpUrl(registerOptions, {
page: 'documentation/user/streamers'
})
const [
labelShare,
labelWeb,
@ -92,9 +96,7 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a
divShareString.append(openButton)
const helpButton = document.createElement('a')
helpButton.href = helpUrl({
page: 'documentation/user/streamers'
})
helpButton.href = streamersHelpUrl
helpButton.target = '_blank'
helpButton.innerHTML = helpButtonSVG()
helpButton.title = labelHelp