From 66a4ea4b8a19307f7d1d8c2bf7b98040cf35cbc8 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 14 Nov 2020 18:05:24 -0800 Subject: [PATCH] More translatable strings --- app/components/Sidebar/Settings.js | 32 ++++---- app/scenes/Collection.js | 2 +- app/scenes/Document/components/Header.js | 44 ++++++----- app/scenes/Drafts.js | 2 +- app/scenes/GroupMembers/AddPeopleToGroup.js | 41 +++++----- app/scenes/GroupMembers/GroupMembers.js | 29 +++---- app/scenes/Starred.js | 74 +++++++++--------- app/scenes/Templates.js | 86 ++++++++++----------- app/scenes/Trash.js | 39 +++++----- shared/translations/default.json | 46 ++++++++++- 10 files changed, 222 insertions(+), 173 deletions(-) diff --git a/app/components/Sidebar/Settings.js b/app/components/Sidebar/Settings.js index 3304405ca9..dc93d5fb65 100644 --- a/app/components/Sidebar/Settings.js +++ b/app/components/Sidebar/Settings.js @@ -13,6 +13,7 @@ import { ExpandedIcon, } from "outline-icons"; import * as React from "react"; +import { withTranslation, type TFunction } from "react-i18next"; import type { RouterHistory } from "react-router-dom"; import styled from "styled-components"; import AuthStore from "stores/AuthStore"; @@ -36,6 +37,7 @@ type Props = { history: RouterHistory, policies: PoliciesStore, auth: AuthStore, + t: TFunction, }; @observer @@ -45,7 +47,7 @@ class SettingsSidebar extends React.Component { }; render() { - const { policies, auth } = this.props; + const { policies, t, auth } = this.props; const { team } = auth; if (!team) return null; @@ -56,7 +58,7 @@ class SettingsSidebar extends React.Component { - Return to App + {t("Return to App")} } teamName={team.name} @@ -71,17 +73,17 @@ class SettingsSidebar extends React.Component { } - label="Profile" + label={t("Profile")} /> } - label="Notifications" + label={t("Notifications")} /> } - label="API Tokens" + label={t("API Tokens")} />
@@ -90,44 +92,44 @@ class SettingsSidebar extends React.Component { } - label="Details" + label={t("Details")} /> )} {can.update && ( } - label="Security" + label={t("Security")} /> )} } exact={false} - label="People" + label={t("People")} /> } exact={false} - label="Groups" + label={t("Groups")} /> } - label="Share Links" + label={t("Share Links")} /> {can.export && ( } - label="Export Data" + label={t("Export Data")} /> )}
{can.update && (
-
Integrations
+
{t("Integrations")}
} @@ -144,7 +146,7 @@ class SettingsSidebar extends React.Component { )} {can.update && !isHosted && (
-
Installation
+
{t("Installation")}
)} @@ -164,4 +166,6 @@ const ReturnToApp = styled(Flex)` height: 16px; `; -export default inject("auth", "policies")(SettingsSidebar); +export default withTranslation()( + inject("auth", "policies")(SettingsSidebar) +); diff --git a/app/scenes/Collection.js b/app/scenes/Collection.js index 6092db36ec..0a7fbb2dd4 100644 --- a/app/scenes/Collection.js +++ b/app/scenes/Collection.js @@ -192,7 +192,7 @@ class CollectionScene extends React.Component { - {collectionName} doesn’t contain any + {{ collectionName }} doesn’t contain any documents yet.
diff --git a/app/scenes/Document/components/Header.js b/app/scenes/Document/components/Header.js index 8b6201c8f1..c03b35dbb7 100644 --- a/app/scenes/Document/components/Header.js +++ b/app/scenes/Document/components/Header.js @@ -11,6 +11,7 @@ import { } from "outline-icons"; import { transparentize, darken } from "polished"; import * as React from "react"; +import { withTranslation, Trans, type TFunction } from "react-i18next"; import { Redirect } from "react-router-dom"; import styled from "styled-components"; import breakpoint from "styled-components-breakpoint"; @@ -55,6 +56,7 @@ type Props = { publish?: boolean, autosave?: boolean, }) => void, + t: TFunction, }; @observer @@ -131,6 +133,7 @@ class Header extends React.Component { publishingIsDisabled, ui, auth, + t, } = this.props; const share = shares.getByDocumentId(document.id); @@ -153,7 +156,7 @@ class Header extends React.Component { { <> { {this.isScrolled && ( <Fade> - {document.title} {document.isArchived && <Badge>Archived</Badge>} + {document.title}{" "} + {document.isArchived && <Badge>{t("Archived")}</Badge>} </Fade> )} {isSaving && !isPublishing && ( - Saving… + {t("Saving…")} )}   @@ -217,10 +223,10 @@ class Header extends React.Component { + Anyone with the link
can view this document - +
) : ( "" ) @@ -234,7 +240,7 @@ class Header extends React.Component { neutral small > - Share + {t("Share")}
@@ -243,7 +249,7 @@ class Header extends React.Component { <> { neutral={isDraft} small > - {isDraft ? "Save Draft" : "Done Editing"} + {isDraft ? t("Save Draft") : t("Done Editing")} @@ -264,7 +270,7 @@ class Header extends React.Component { {canEdit && ( { neutral small > - Edit + {t("Edit")} @@ -286,13 +292,13 @@ class Header extends React.Component { document={document} label={ } @@ -307,25 +313,25 @@ class Header extends React.Component { primary small > - New from template + {t("New from template")} )} {can.update && isDraft && !isRevision && ( @@ -425,4 +431,6 @@ const Title = styled.div` `}; `; -export default inject("auth", "ui", "policies", "shares")(Header); +export default withTranslation()
( + inject("auth", "ui", "policies", "shares")(Header) +); diff --git a/app/scenes/Drafts.js b/app/scenes/Drafts.js index efd57554cd..887b8226f5 100644 --- a/app/scenes/Drafts.js +++ b/app/scenes/Drafts.js @@ -82,7 +82,7 @@ class Drafts extends React.Component { {t("Drafts")} - Documents + {t("Documents")} void, + t: TFunction, }; @observer @@ -50,40 +53,45 @@ class AddPeopleToGroup extends React.Component { }); }, 250); - handleAddUser = async (user) => { + handleAddUser = async (user: User) => { + const { t } = this.props; + try { await this.props.groupMemberships.create({ groupId: this.props.group.id, userId: user.id, }); - this.props.ui.showToast(`${user.name} was added to the group`); + this.props.ui.showToast( + t(`{{userName}} was added to the group`, { userName: user.name }) + ); } catch (err) { - this.props.ui.showToast("Could not add user"); + this.props.ui.showToast(t("Could not add user")); } }; render() { - const { users, group, auth } = this.props; + const { users, group, auth, t } = this.props; const { user, team } = auth; if (!user || !team) return null; return ( - Add team members below to give them access to the group. Need to add - someone who’s not yet on the team yet?{" "} + {t( + "Add team members below to give them access to the group. Need to add someone who’s not yet on the team yet?" + )}{" "} - Invite them to {team.name} + {t("Invite them to {{teamName}}", { teamName: team.name })} . { No people matching your search + {t("No people matching your search")} ) : ( - No people left to add + {t("No people left to add")} ) } items={users.notInGroup(group.id, this.query)} @@ -108,7 +116,7 @@ class AddPeopleToGroup extends React.Component { )} /> @@ -119,9 +127,6 @@ class AddPeopleToGroup extends React.Component { } } -export default inject( - "auth", - "users", - "groupMemberships", - "ui" -)(AddPeopleToGroup); +export default withTranslation()( + inject("auth", "users", "groupMemberships", "ui")(AddPeopleToGroup) +); diff --git a/app/scenes/GroupMembers/GroupMembers.js b/app/scenes/GroupMembers/GroupMembers.js index 4838f44061..b4314a5f93 100644 --- a/app/scenes/GroupMembers/GroupMembers.js +++ b/app/scenes/GroupMembers/GroupMembers.js @@ -3,12 +3,14 @@ import { observable } from "mobx"; import { inject, observer } from "mobx-react"; import { PlusIcon } from "outline-icons"; import * as React from "react"; +import { withTranslation, type TFunction } from "react-i18next"; import AuthStore from "stores/AuthStore"; import GroupMembershipsStore from "stores/GroupMembershipsStore"; import PoliciesStore from "stores/PoliciesStore"; import UiStore from "stores/UiStore"; import UsersStore from "stores/UsersStore"; import Group from "models/Group"; +import User from "models/User"; import Button from "components/Button"; import Empty from "components/Empty"; import Flex from "components/Flex"; @@ -26,6 +28,7 @@ type Props = { users: UsersStore, policies: PoliciesStore, groupMemberships: GroupMembershipsStore, + t: TFunction, }; @observer @@ -40,20 +43,24 @@ class GroupMembers extends React.Component { this.addModalOpen = false; }; - handleRemoveUser = async (user) => { + handleRemoveUser = async (user: User) => { + const { t } = this.props; + try { await this.props.groupMemberships.delete({ groupId: this.props.group.id, userId: user.id, }); - this.props.ui.showToast(`${user.name} was removed from the group`); + this.props.ui.showToast( + t(`{{userName}} was removed from the group`, { userName: user.name }) + ); } catch (err) { - this.props.ui.showToast("Could not remove user"); + this.props.ui.showToast(t("Could not remove user")); } }; render() { - const { group, users, groupMemberships, policies, auth } = this.props; + const { group, users, groupMemberships, policies, t, auth } = this.props; const { user } = auth; if (!user) return null; @@ -75,7 +82,7 @@ class GroupMembers extends React.Component { icon={} neutral > - Add people… + {t("Add people…")} @@ -90,7 +97,7 @@ class GroupMembers extends React.Component { items={users.inGroup(group.id)} fetch={groupMemberships.fetchPage} options={{ id: group.id }} - empty={This group has no members.} + empty={{t("This group has no members.")}} renderItem={(item) => ( { } } -export default inject( - "auth", - "users", - "policies", - "groupMemberships", - "ui" -)(GroupMembers); +export default withTranslation()( + inject("auth", "users", "policies", "groupMemberships", "ui")(GroupMembers) +); diff --git a/app/scenes/Starred.js b/app/scenes/Starred.js index 8ca71611c4..9e6f22e31e 100644 --- a/app/scenes/Starred.js +++ b/app/scenes/Starred.js @@ -1,8 +1,8 @@ // @flow import { observer, inject } from "mobx-react"; import * as React from "react"; +import { useTranslation } from "react-i18next"; import { type Match } from "react-router-dom"; - import DocumentsStore from "stores/DocumentsStore"; import Actions, { Action } from "components/Actions"; import CenteredContent from "components/CenteredContent"; @@ -20,44 +20,42 @@ type Props = { match: Match, }; -@observer -class Starred extends React.Component { - render() { - const { fetchStarred, starred, starredAlphabetical } = this.props.documents; - const { sort } = this.props.match.params; +function Starred(props: Props) { + const { t } = useTranslation(); + const { fetchStarred, starred, starredAlphabetical } = props.documents; + const { sort } = props.match.params; - return ( - - - Starred - - - Recently Updated - - - Alphabetical - - - } - empty={You’ve not starred any documents yet.} - fetch={fetchStarred} - documents={sort === "alphabetical" ? starredAlphabetical : starred} - showCollection - /> + return ( + + + {t("Starred")} + + + {t("Recently Updated")} + + + {t("Alphabetical")} + + + } + empty={{t("You’ve not starred any documents yet.")}} + fetch={fetchStarred} + documents={sort === "alphabetical" ? starredAlphabetical : starred} + showCollection + /> - - - - - - - - - - ); - } + + + + + + + + + + ); } -export default inject("documents")(Starred); +export default inject("documents")(observer(Starred)); diff --git a/app/scenes/Templates.js b/app/scenes/Templates.js index 7a2f9b5bb0..0e8c9618cc 100644 --- a/app/scenes/Templates.js +++ b/app/scenes/Templates.js @@ -1,6 +1,7 @@ // @flow import { observer, inject } from "mobx-react"; import * as React from "react"; +import { useTranslation } from "react-i18next"; import { type Match } from "react-router-dom"; import DocumentsStore from "stores/DocumentsStore"; @@ -19,53 +20,46 @@ type Props = { match: Match, }; -@observer -class Templates extends React.Component { - render() { - const { - fetchTemplates, - templates, - templatesAlphabetical, - } = this.props.documents; - const { sort } = this.props.match.params; +function Templates(props: Props) { + const { t } = useTranslation(); + const { fetchTemplates, templates, templatesAlphabetical } = props.documents; + const { sort } = props.match.params; - return ( - - - Templates - - - Recently Updated - - - Alphabetical - - - } - empty={ - - There are no templates just yet. You can create templates to help - your team create consistent and accurate documentation. - - } - fetch={fetchTemplates} - documents={ - sort === "alphabetical" ? templatesAlphabetical : templates - } - showCollection - showDraft - /> + return ( + + + {t("Templates")} + + + {t("Recently Updated")} + + + {t("Alphabetical")} + + + } + empty={ + + {t( + "There are no templates just yet. You can create templates to help your team create consistent and accurate documentation." + )} + + } + fetch={fetchTemplates} + documents={sort === "alphabetical" ? templatesAlphabetical : templates} + showCollection + showDraft + /> - - - - - - - ); - } + + + + + + + ); } -export default inject("documents")(Templates); +export default inject("documents")(observer(Templates)); diff --git a/app/scenes/Trash.js b/app/scenes/Trash.js index 135edbeac0..f6217488a5 100644 --- a/app/scenes/Trash.js +++ b/app/scenes/Trash.js @@ -1,6 +1,7 @@ // @flow import { observer, inject } from "mobx-react"; import * as React from "react"; +import { useTranslation } from "react-i18next"; import DocumentsStore from "stores/DocumentsStore"; import CenteredContent from "components/CenteredContent"; @@ -14,26 +15,24 @@ type Props = { documents: DocumentsStore, }; -@observer -class Trash extends React.Component { - render() { - const { documents } = this.props; +function Trash(props: Props) { + const { t } = useTranslation(); + const { documents } = props; - return ( - - - Trash - Documents} - empty={Trash is empty at the moment.} - showCollection - showTemplate - /> - - ); - } + return ( + + + {t("Trash")} + {t("Documents")}} + empty={{t("Trash is empty at the moment.")}} + showCollection + showTemplate + /> + + ); } -export default inject("documents")(Trash); +export default inject("documents")(observer(Trash)); diff --git a/shared/translations/default.json b/shared/translations/default.json index cfba5cbd10..7dafd1421f 100644 --- a/shared/translations/default.json +++ b/shared/translations/default.json @@ -23,6 +23,18 @@ "Invite people…": "Invite people…", "Invite people": "Invite people", "Create a collection": "Create a collection", + "Return to App": "Return to App", + "Profile": "Profile", + "Notifications": "Notifications", + "API Tokens": "API Tokens", + "Details": "Details", + "Security": "Security", + "People": "People", + "Groups": "Groups", + "Share Links": "Share Links", + "Export Data": "Export Data", + "Integrations": "Integrations", + "Installation": "Installation", "Keyboard shortcuts": "Keyboard shortcuts", "Settings": "Settings", "API documentation": "API documentation", @@ -130,18 +142,44 @@ "Admin": "Admin", "Recently viewed": "Recently viewed", "Created by me": "Created by me", + "Hide contents": "Hide contents", + "Show contents": "Show contents", + "Archived": "Archived", + "Saving…": "Saving…", + "Anyone with the link <1>can view this document": "Anyone with the link <1>can view this document", + "Share": "Share", + "Save": "Save", + "Save Draft": "Save Draft", + "Done Editing": "Done Editing", + "Edit {{noun}}": "Edit {{noun}}", + "New from template": "New from template", + "Publish": "Publish", + "Publish document": "Publish document", + "Publishing…": "Publishing…", + "Documents": "Documents", + "No documents found for your filters.": "No documents found for your filters.", + "You’ve not got any drafts at the moment.": "You’ve not got any drafts at the moment.", + "{{userName}} was added to the group": "{{userName}} was added to the group", + "Add team members below to give them access to the group. Need to add someone who’s not yet on the team yet?": "Add team members below to give them access to the group. Need to add someone who’s not yet on the team yet?", + "Invite them to {{teamName}}": "Invite them to {{teamName}}", + "{{userName}} was removed from the group": "{{userName}} was removed from the group", + "Could not remove user": "Could not remove user", + "Add people…": "Add people…", + "This group has no members.": "This group has no members.", "Profile saved": "Profile saved", "Profile picture updated": "Profile picture updated", "Unable to upload new profile picture": "Unable to upload new profile picture", - "Profile": "Profile", "Photo": "Photo", "Upload": "Upload", "Full name": "Full name", "Language": "Language", "Please note that translations are currently in early access.": "Please note that translations are currently in early access.", - "Saving…": "Saving…", - "Save": "Save", "Delete Account": "Delete Account", "You may delete your account at any time, note that this is unrecoverable": "You may delete your account at any time, note that this is unrecoverable", - "Delete account": "Delete account" + "Delete account": "Delete account", + "Recently Updated": "Recently Updated", + "Alphabetical": "Alphabetical", + "You’ve not starred any documents yet.": "You’ve not starred any documents yet.", + "There are no templates just yet. You can create templates to help your team create consistent and accurate documentation.": "There are no templates just yet. You can create templates to help your team create consistent and accurate documentation.", + "Trash is empty at the moment.": "Trash is empty at the moment." }