"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7305/react/features/base/i18n/functions.tsx" (26 May 2023, 1575 Bytes) of package /linux/misc/jitsi-meet-7305.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TSX (TypeScript with React) source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 import React from 'react';
    2 import { WithTranslation, withTranslation } from 'react-i18next';
    3 
    4 import i18next from './i18next';
    5 
    6 /**
    7  * Changes the main translation bundle.
    8  *
    9  * @param {string} language - The language e.g. 'en', 'fr'.
   10  * @param {string} url - The url of the translation bundle.
   11  * @returns {void}
   12  */
   13 export async function changeLanguageBundle(language: string, url: string) {
   14     const res = await fetch(url);
   15     const bundle = await res.json();
   16 
   17     i18next.addResourceBundle(language, 'main', bundle, true, true);
   18 }
   19 
   20 /**
   21  * Wraps a specific React Component in order to enable translations in it.
   22  *
   23  * @param {Component} component - The React Component to wrap.
   24  * @returns {Component} The React Component which wraps {@link component} and
   25  * enables translations in it.
   26  */
   27 export function translate<P extends WithTranslation>(component: React.ComponentType<P>) {
   28     // Use the default list of namespaces.
   29     return withTranslation([ 'main', 'languages', 'countries' ])(component);
   30 }
   31 
   32 /**
   33  * Translates a specific key to text containing HTML via a specific translate
   34  * function.
   35  *
   36  * @param {Function} t - The translate function.
   37  * @param {string} key - The key to translate.
   38  * @param {Array<*>} options - The options, if any, to pass to {@link t}.
   39  * @returns {ReactElement} A ReactElement which depicts the translated HTML
   40  * text.
   41  */
   42 export function translateToHTML(t: Function, key: string, options: Object = {}) {
   43     // eslint-disable-next-line react/no-danger
   44     return <span dangerouslySetInnerHTML = {{ __html: t(key, options) }} />;
   45 }