From bc35d3e01b4d10f3bfd4daf0aac51be68a5bebad Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 13 Feb 2022 13:31:52 -0500 Subject: [PATCH] Make sure all pages can be translated at load time (with HOC) --- packages/fakeyou/src/App.tsx | 4 ++++ packages/fakeyou/src/AppTranslated.tsx | 28 ++++++++++++++++++++++++++ packages/fakeyou/src/index.tsx | 4 ++-- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 packages/fakeyou/src/AppTranslated.tsx diff --git a/packages/fakeyou/src/App.tsx b/packages/fakeyou/src/App.tsx index 9fe412c3b8..6b1999f154 100644 --- a/packages/fakeyou/src/App.tsx +++ b/packages/fakeyou/src/App.tsx @@ -82,6 +82,7 @@ interface State { //localeFullLanguageTags: string[], isShowingLanguageNotice: boolean, displayLanguage: Language, + primaryLanguageCode: string, // Jobs enqueued during this browser session. ttsInferenceJobs: Array, @@ -121,6 +122,7 @@ class App extends React.Component { //localeFullLanguageTags: [], isShowingLanguageNotice: false, displayLanguage: Language.English, + primaryLanguageCode: 'en', ttsInferenceJobs: [], w2lInferenceJobs: [], @@ -209,6 +211,7 @@ class App extends React.Component { this.setState({ isShowingLanguageNotice: showNotice, displayLanguage: displayLanguage, + primaryLanguageCode: languageCode, }); i18n.changeLanguage(languageCode); @@ -507,6 +510,7 @@ class App extends React.Component { isShowingLangaugeNotice={this.state.isShowingLanguageNotice} clearLanguageNotice={this.clearLanguageNotice} displayLanguage={this.state.displayLanguage} + primaryLanguageCode={this.state.primaryLanguageCode} enqueueTtsJob={this.enqueueTtsJob} ttsInferenceJobs={this.state.ttsInferenceJobs} diff --git a/packages/fakeyou/src/AppTranslated.tsx b/packages/fakeyou/src/AppTranslated.tsx new file mode 100644 index 0000000000..df29c9b855 --- /dev/null +++ b/packages/fakeyou/src/AppTranslated.tsx @@ -0,0 +1,28 @@ +import React from 'react'; +import { withTranslation } from 'react-i18next'; +import { AppWrapper } from './AppWrapper'; + +interface Props { + // Certan browsers (iPhone) have pitiful support for drawing APIs. Worse yet, + // they seem to lose the "touch event sandboxing" that allows for audio to be + // played after user interaction if the XHRs delivering the audio don't do so + // as actual audio mimetypes. (Decoding from base64 and trying to play fails.) + enableSpectrograms: boolean, + + // Whether or not to inform users that the name of the website has changed. + flashVocodesNotice: boolean, +} + +function AppTranslated(props: Props) { + return ( + + ) +} + +// NB: This is a Higher Order Component (HOC) that will pass `t` and `i18n` +// so that we can change the language statefully at runtime. If we don't do +// this, some pages won't respond to translation. +export default withTranslation()(AppTranslated); diff --git a/packages/fakeyou/src/index.tsx b/packages/fakeyou/src/index.tsx index 926f7e1734..bcad5ab112 100644 --- a/packages/fakeyou/src/index.tsx +++ b/packages/fakeyou/src/index.tsx @@ -2,7 +2,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import * as serviceWorker from './serviceWorker'; -import { AppWrapper } from './AppWrapper'; +import AppTranslated from './AppTranslated'; const IS_IOS : boolean = /iPad|iPhone|iPod/.test(navigator.platform || ""); @@ -12,7 +12,7 @@ const flashVocodesNotice = new URLSearchParams(window.location.search).has('voco ReactDOM.render( -