mirror of https://github.com/jitsi/jitsi-meet
Split language detectors to be web/native dependent. Take care of strings that contain html.pull/1353/head
parent
e3d4152e32
commit
c361e1e31a
@ -0,0 +1,11 @@ |
||||
import locale from 'react-native-locale-detector'; |
||||
|
||||
/** |
||||
* A language detector that uses native locale. |
||||
*/ |
||||
export default { |
||||
init: Function.prototype, |
||||
type: 'languageDetector', |
||||
detect: () => locale, |
||||
cacheUserLanguage: Function.prototype |
||||
}; |
@ -0,0 +1,34 @@ |
||||
/* global interfaceConfig */ |
||||
import Browser from 'i18next-browser-languagedetector'; |
||||
import ConfigLanguageDetector from './ConfigLanguageDetector'; |
||||
|
||||
/** |
||||
* List of detectors to use in their order. |
||||
* |
||||
* @type {[*]} |
||||
*/ |
||||
const detectors = [ 'querystring', 'localStorage', 'configLanguageDetector' ]; |
||||
|
||||
/** |
||||
* Allow i18n to detect the system language from the browser. |
||||
*/ |
||||
if (interfaceConfig.LANG_DETECTION) { |
||||
detectors.push('navigator'); |
||||
} |
||||
|
||||
/** |
||||
* The language detectors. |
||||
*/ |
||||
const browser = new Browser(null, { |
||||
order: detectors, |
||||
lookupQuerystring: 'lang', |
||||
lookupLocalStorage: 'language', |
||||
caches: [ 'localStorage' ] |
||||
}); |
||||
|
||||
/** |
||||
* adds a language detector that just checks the config |
||||
*/ |
||||
browser.addDetector(ConfigLanguageDetector); |
||||
|
||||
export default browser; |
@ -1,12 +1,32 @@ |
||||
import { translate as reactTranslate } from 'react-i18next'; |
||||
import React from 'react'; |
||||
|
||||
/** |
||||
* Wrap a translatable component. |
||||
* |
||||
* @param {Component} component - the component to wrap |
||||
* @returns {Component} the wrapped component. |
||||
* @param {Component} component - The component to wrap. |
||||
* @returns {Component} The wrapped component. |
||||
*/ |
||||
export function translate(component) { |
||||
// use the default list of namespaces
|
||||
return reactTranslate([ 'main', 'languages' ], { wait: true })(component); |
||||
} |
||||
|
||||
/** |
||||
* Translates key and prepares data to be passed to dangerouslySetInnerHTML. |
||||
* Used when translation text contains html. |
||||
* |
||||
* @param {func} t - Translate function. |
||||
* @param {string} key - The key to translate. |
||||
* @param {Array} options - Optional options. |
||||
* @returns {XML} A span using dangerouslySetInnerHTML to insert html text. |
||||
*/ |
||||
export function translateToHTML(t, key, options = {}) { |
||||
/* eslint-disable react/no-danger */ |
||||
return ( |
||||
<span |
||||
dangerouslySetInnerHTML = {{ __html: t(key, options) }} /> |
||||
); |
||||
|
||||
/* eslint-enable react/no-danger */ |
||||
} |
||||
|
Loading…
Reference in new issue