From b0eeff1bf8c9d2cf1e23a79a1f57443bb0593bb8 Mon Sep 17 00:00:00 2001 From: David Ralph Date: Fri, 10 Sep 2021 16:38:53 +0100 Subject: [PATCH] feat(translations): new translation system --- package.json | 1 + src/components/modals/ErrorBoundary.jsx | 8 +- src/components/modals/feedback/Feedback.jsx | 23 ++-- src/components/modals/main/Main.jsx | 19 ++-- .../modals/main/marketplace/Item.jsx | 14 +-- .../main/marketplace/sections/Added.jsx | 23 ++-- .../main/marketplace/sections/Create.jsx | 50 ++++----- .../main/marketplace/sections/Marketplace.jsx | 29 ++--- .../main/marketplace/sections/Sideload.jsx | 10 +- .../modals/main/settings/Dropdown.jsx | 3 +- .../modals/main/settings/KeybindInput.jsx | 11 +- src/components/modals/main/settings/Radio.jsx | 3 +- .../modals/main/settings/ResetModal.jsx | 9 +- .../modals/main/settings/Slider.jsx | 6 +- src/components/modals/main/settings/Text.jsx | 6 +- .../modals/main/settings/sections/About.jsx | 48 +++++---- .../main/settings/sections/Advanced.jsx | 35 +++--- .../main/settings/sections/Appearance.jsx | 72 +++++++------ .../main/settings/sections/Changelog.jsx | 19 ++-- .../main/settings/sections/Experimental.jsx | 11 +- .../main/settings/sections/Greeting.jsx | 25 ++--- .../main/settings/sections/Keybinds.jsx | 37 +++---- .../main/settings/sections/Language.jsx | 14 +-- .../modals/main/settings/sections/Order.jsx | 21 ++-- .../main/settings/sections/QuickLinks.jsx | 17 +-- .../modals/main/settings/sections/Quote.jsx | 50 ++++----- .../modals/main/settings/sections/Search.jsx | 27 ++--- .../modals/main/settings/sections/Stats.jsx | 29 ++--- .../modals/main/settings/sections/Time.jsx | 75 ++++++------- .../modals/main/settings/sections/Weather.jsx | 43 ++++---- .../sections/background/Background.jsx | 101 +++++++++--------- .../settings/sections/background/Colour.jsx | 14 +-- src/components/modals/main/tabs/Addons.jsx | 10 +- .../modals/main/tabs/Marketplace.jsx | 10 +- src/components/modals/main/tabs/Settings.jsx | 36 ++++--- .../modals/main/tabs/backend/Tab.jsx | 59 +++++----- .../modals/main/tabs/backend/Tabs.jsx | 6 +- src/components/modals/welcome/Welcome.jsx | 19 ++-- .../modals/welcome/WelcomeSections.jsx | 73 ++++++------- .../widgets/background/Background.jsx | 9 +- .../widgets/background/Favourite.jsx | 3 +- .../widgets/background/Maximise.jsx | 3 +- .../widgets/background/PhotoInformation.jsx | 25 ++--- src/components/widgets/greeting/Greeting.jsx | 18 ++-- src/components/widgets/navbar/Navbar.jsx | 7 +- src/components/widgets/navbar/Notes.jsx | 8 +- .../widgets/quicklinks/QuickLinks.jsx | 1 - src/components/widgets/quote/Quote.jsx | 6 +- src/components/widgets/search/Search.jsx | 6 +- src/components/widgets/time/Date.jsx | 5 +- src/components/widgets/weather/Weather.jsx | 9 +- src/index.js | 22 +++- src/modules/helpers/settings/modals.js | 5 +- src/modules/variables.js | 6 ++ src/translations/de_DE.json | 5 +- src/translations/en_GB.json | 5 +- src/translations/en_US.json | 5 +- src/translations/es.json | 5 +- src/translations/fr.json | 5 +- src/translations/nl.json | 5 +- src/translations/no.json | 5 +- src/translations/ru.json | 5 +- src/translations/zh_CN.json | 5 +- 63 files changed, 651 insertions(+), 593 deletions(-) create mode 100644 src/modules/variables.js diff --git a/package.json b/package.json index 00ed8306..85ddd08a 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "license": "BSD-3-Clause", "version": "5.3.3", "dependencies": { + "@eartharoid/i18n": "^1.0.0", "@emotion/react": "^11.4.1", "@emotion/styled": "^11.3.0", "@fontsource/lexend-deca": "4.4.5", diff --git a/src/components/modals/ErrorBoundary.jsx b/src/components/modals/ErrorBoundary.jsx index ee62844f..523fef2b 100644 --- a/src/components/modals/ErrorBoundary.jsx +++ b/src/components/modals/ErrorBoundary.jsx @@ -1,3 +1,4 @@ +import variables from 'modules/variables'; import { PureComponent } from 'react'; import { ErrorOutline } from '@material-ui/icons'; @@ -7,7 +8,6 @@ export default class ErrorBoundary extends PureComponent { this.state = { error: false }; - this.language = window.language.modals.main.error_boundary; } static getDerivedStateFromError(error) { @@ -24,9 +24,9 @@ export default class ErrorBoundary extends PureComponent {
-

{this.language.title}

-

{this.language.message}

- +

{variables.language.getMessage(variables.languagecode, 'modals.main.error_boundary.title')}

+

{variables.language.getMessage(variables.languagecode, 'modals.main.error_boundary.message')}

+
); diff --git a/src/components/modals/feedback/Feedback.jsx b/src/components/modals/feedback/Feedback.jsx index 310c140b..49338492 100644 --- a/src/components/modals/feedback/Feedback.jsx +++ b/src/components/modals/feedback/Feedback.jsx @@ -1,8 +1,12 @@ +import variables from 'modules/variables'; import { PureComponent } from 'react'; import './feedback.scss'; export default class FeedbackModal extends PureComponent { + getMessage = (languagecode, text) => variables.language.getMessage(languagecode, text); + languagecode = variables.languagecode; + constructor() { super(); this.state = { @@ -18,7 +22,6 @@ export default class FeedbackModal extends PureComponent { }, formsubmit: '' }; - this.language = window.language.modals.feedback; } async submitForm(e) { @@ -27,11 +30,11 @@ export default class FeedbackModal extends PureComponent { let question_two_error, question_four_error; if (this.state.question_two.value.length <= 0) { - question_two_error = this.language.not_filled; + question_two_error = this.getMessage(this.languagecode, 'modals.feedback.not_filled'); } if (this.state.question_four.value.length <= 0) { - question_four_error = this.language.not_filled; + question_four_error = this.getMessage(this.languagecode, 'modals.feedback.not_filled'); } if (question_two_error || question_four_error) { @@ -58,7 +61,7 @@ export default class FeedbackModal extends PureComponent { }); this.setState({ - formsubmit: this.language.success + formsubmit: this.getMessage(this.languagecode, 'modals.feedback.success') }); setTimeout(() => { @@ -70,36 +73,36 @@ export default class FeedbackModal extends PureComponent { render() { return (
-

{this.language.title}

+

{this.getMessage(this.languagecode, 'modals.feedback.title')}

×
- +

this.setState({ question_one: e.target.value })}/>
- +