From d4929b558edec1a473ae2c4e431bd74cd1f2e7fd Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Fri, 22 Sep 2017 21:43:27 +0200 Subject: [PATCH 1/5] Add dummy translation function to mark translatable strings Signed-off-by: Stefan Parviainen --- src/autocomplete/CommandProvider.js | 34 ++++++++--------- src/components/structures/UserSettings.js | 38 +++++++++---------- src/components/views/elements/AppTile.js | 6 +-- .../views/rooms/MessageComposerInput.js | 18 ++++----- src/languageHandler.js | 6 +++ 5 files changed, 54 insertions(+), 48 deletions(-) diff --git a/src/autocomplete/CommandProvider.js b/src/autocomplete/CommandProvider.js index 011ad0a7dc..42347d3955 100644 --- a/src/autocomplete/CommandProvider.js +++ b/src/autocomplete/CommandProvider.js @@ -16,7 +16,7 @@ limitations under the License. */ import React from 'react'; -import { _t } from '../languageHandler'; +import { _t, _td } from '../languageHandler'; import AutocompleteProvider from './AutocompleteProvider'; import FuzzyMatcher from './FuzzyMatcher'; import {TextualCompletion} from './Components'; @@ -27,82 +27,82 @@ const COMMANDS = [ { command: '/me', args: '', - description: 'Displays action', + description: _td('Displays action'), }, { command: '/ban', args: ' [reason]', - description: 'Bans user with given id', + description: _td('Bans user with given id'), }, { command: '/unban', args: '', - description: 'Unbans user with given id', + description: _td('Unbans user with given id'), }, { command: '/op', args: ' []', - description: 'Define the power level of a user', + description: _td('Define the power level of a user'), }, { command: '/deop', args: '', - description: 'Deops user with given id', + description: _td('Deops user with given id'), }, { command: '/invite', args: '', - description: 'Invites user with given id to current room', + description: _td('Invites user with given id to current room'), }, { command: '/join', args: '', - description: 'Joins room with given alias', + description: _td('Joins room with given alias'), }, { command: '/part', args: '[]', - description: 'Leave room', + description: _td('Leave room'), }, { command: '/topic', args: '', - description: 'Sets the room topic', + description: _td('Sets the room topic'), }, { command: '/kick', args: ' [reason]', - description: 'Kicks user with given id', + description: _td('Kicks user with given id'), }, { command: '/nick', args: '', - description: 'Changes your display nickname', + description: _td('Changes your display nickname'), }, { command: '/ddg', args: '', - description: 'Searches DuckDuckGo for results', + description: _td('Searches DuckDuckGo for results'), }, { command: '/tint', args: ' []', - description: 'Changes colour scheme of current room', + description: _td('Changes colour scheme of current room'), }, { command: '/verify', args: ' ', - description: 'Verifies a user, device, and pubkey tuple', + description: _td('Verifies a user, device, and pubkey tuple'), }, { command: '/ignore', args: '', - description: 'Ignores a user, hiding their messages from you', + description: _td('Ignores a user, hiding their messages from you'), }, { command: '/unignore', args: '', - description: 'Stops ignoring a user, showing their messages going forward', + description: _td('Stops ignoring a user, showing their messages going forward'), }, // Omitting `/markdown` as it only seems to apply to OldComposer ]; diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index d2f27b63e1..572ee79a69 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -32,7 +32,7 @@ const AddThreepid = require('../../AddThreepid'); const SdkConfig = require('../../SdkConfig'); import Analytics from '../../Analytics'; import AccessibleButton from '../views/elements/AccessibleButton'; -import { _t } from '../../languageHandler'; +import { _t, _td } from '../../languageHandler'; import * as languageHandler from '../../languageHandler'; import * as FormattingUtils from '../../utils/FormattingUtils'; @@ -63,55 +63,55 @@ const gHVersionLabel = function(repo, token='') { const SETTINGS_LABELS = [ { id: 'autoplayGifsAndVideos', - label: 'Autoplay GIFs and videos', + label: _td('Autoplay GIFs and videos'), }, { id: 'hideReadReceipts', - label: 'Hide read receipts', + label: _td('Hide read receipts'), }, { id: 'dontSendTypingNotifications', - label: "Don't send typing notifications", + label: _td("Don't send typing notifications"), }, { id: 'alwaysShowTimestamps', - label: 'Always show message timestamps', + label: _td('Always show message timestamps'), }, { id: 'showTwelveHourTimestamps', - label: 'Show timestamps in 12 hour format (e.g. 2:30pm)', + label: _td('Show timestamps in 12 hour format (e.g. 2:30pm)'), }, { id: 'hideJoinLeaves', - label: 'Hide join/leave messages (invites/kicks/bans unaffected)', + label: _td('Hide join/leave messages (invites/kicks/bans unaffected)'), }, { id: 'hideAvatarDisplaynameChanges', - label: 'Hide avatar and display name changes', + label: _td('Hide avatar and display name changes'), }, { id: 'useCompactLayout', - label: 'Use compact timeline layout', + label: _td('Use compact timeline layout'), }, { id: 'hideRedactions', - label: 'Hide removed messages', + label: _td('Hide removed messages'), }, { id: 'enableSyntaxHighlightLanguageDetection', - label: 'Enable automatic language detection for syntax highlighting', + label: _td('Enable automatic language detection for syntax highlighting'), }, { id: 'MessageComposerInput.autoReplaceEmoji', - label: 'Automatically replace plain text Emoji', + label: _td('Automatically replace plain text Emoji'), }, { id: 'MessageComposerInput.dontSuggestEmoji', - label: 'Disable Emoji suggestions while typing', + label: _td('Disable Emoji suggestions while typing'), }, { id: 'Pill.shouldHidePillAvatar', - label: 'Hide avatars in user and room mentions', + label: _td('Hide avatars in user and room mentions'), }, /* { @@ -124,7 +124,7 @@ const SETTINGS_LABELS = [ const ANALYTICS_SETTINGS_LABELS = [ { id: 'analyticsOptOut', - label: 'Opt out of analytics', + label: _td('Opt out of analytics'), fn: function(checked) { Analytics[checked ? 'disable' : 'enable'](); }, @@ -134,7 +134,7 @@ const ANALYTICS_SETTINGS_LABELS = [ const WEBRTC_SETTINGS_LABELS = [ { id: 'webRtcForceTURN', - label: 'Disable Peer-to-Peer for 1:1 calls', + label: _td('Disable Peer-to-Peer for 1:1 calls'), }, ]; @@ -143,7 +143,7 @@ const WEBRTC_SETTINGS_LABELS = [ const CRYPTO_SETTINGS_LABELS = [ { id: 'blacklistUnverifiedDevices', - label: 'Never send encrypted messages to unverified devices from this device', + label: _td('Never send encrypted messages to unverified devices from this device'), fn: function(checked) { MatrixClientPeg.get().setGlobalBlacklistUnverifiedDevices(checked); }, @@ -166,12 +166,12 @@ const CRYPTO_SETTINGS_LABELS = [ const THEMES = [ { id: 'theme', - label: 'Light theme', + label: _td('Light theme'), value: 'light', }, { id: 'theme', - label: 'Dark theme', + label: _td('Dark theme'), value: 'dark', }, ]; diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 7436f84f69..1d7e4bd217 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -22,7 +22,7 @@ import MatrixClientPeg from '../../../MatrixClientPeg'; import ScalarAuthClient from '../../../ScalarAuthClient'; import SdkConfig from '../../../SdkConfig'; import Modal from '../../../Modal'; -import { _t } from '../../../languageHandler'; +import { _t, _td } from '../../../languageHandler'; import sdk from '../../../index'; import AppPermission from './AppPermission'; import AppWarning from './AppWarning'; @@ -170,9 +170,9 @@ export default React.createClass({ // These strings are translated at the point that they are inserted in to the DOM, in the render method _deleteWidgetLabel() { if (this._canUserModify()) { - return 'Delete widget'; + return _td('Delete widget'); } - return 'Revoke widget access'; + return _td('Revoke widget access'); }, /* TODO -- Store permission in account data so that it is persisted across multiple devices */ diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index 37602a94ca..39666c94a4 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -30,7 +30,7 @@ import SlashCommands from '../../../SlashCommands'; import KeyCode from '../../../KeyCode'; import Modal from '../../../Modal'; import sdk from '../../../index'; -import { _t } from '../../../languageHandler'; +import { _t, _td } from '../../../languageHandler'; import Analytics from '../../../Analytics'; import dis from '../../../dispatcher'; @@ -1032,10 +1032,10 @@ export default class MessageComposerInput extends React.Component { buttons. */ getSelectionInfo(editorState: EditorState) { const styleName = { - BOLD: 'bold', - ITALIC: 'italic', - STRIKETHROUGH: 'strike', - UNDERLINE: 'underline', + BOLD: _td('bold'), + ITALIC: _td('italic'), + STRIKETHROUGH: _td('strike'), + UNDERLINE: _td('underline'), }; const originalStyle = editorState.getCurrentInlineStyle().toArray(); @@ -1044,10 +1044,10 @@ export default class MessageComposerInput extends React.Component { .filter((styleName) => !!styleName); const blockName = { - 'code-block': 'code', - 'blockquote': 'quote', - 'unordered-list-item': 'bullet', - 'ordered-list-item': 'numbullet', + 'code-block': _td('code'), + 'blockquote': _td('quote'), + 'unordered-list-item': _td('bullet'), + 'ordered-list-item': _td('numbullet'), }; const originalBlockType = editorState.getCurrentContent() .getBlockForKey(editorState.getSelection().getStartKey()) diff --git a/src/languageHandler.js b/src/languageHandler.js index 4455d58b04..12242a2e15 100644 --- a/src/languageHandler.js +++ b/src/languageHandler.js @@ -29,6 +29,12 @@ counterpart.setSeparator('|'); // Fall back to English counterpart.setFallbackLocale('en'); +// Function which only purpose is to mark that a string is translatable +// Does not actually do anything. It's helpful for automatic extraction of translatable strings +export function _td(s) { + return s; +} + // The translation function. This is just a simple wrapper to counterpart, // but exists mostly because we must use the same counterpart instance // between modules (ie. here (react-sdk) and the app (riot-web), and if we From cc441f42f9594f3e59b58ece05ccfaa2b99e4422 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Sat, 23 Sep 2017 09:02:51 +0200 Subject: [PATCH 2/5] Some more translatable strings Signed-off-by: Stefan Parviainen --- src/components/views/dialogs/KeyShareDialog.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/views/dialogs/KeyShareDialog.js b/src/components/views/dialogs/KeyShareDialog.js index aed8e6a5af..c44e856382 100644 --- a/src/components/views/dialogs/KeyShareDialog.js +++ b/src/components/views/dialogs/KeyShareDialog.js @@ -18,7 +18,7 @@ import Modal from '../../../Modal'; import React from 'react'; import sdk from '../../../index'; -import { _t } from '../../../languageHandler'; +import { _t, _td } from '../../../languageHandler'; /** * Dialog which asks the user whether they want to share their keys with @@ -116,11 +116,11 @@ export default React.createClass({ let text; if (this.state.wasNewDevice) { - text = "You added a new device '%(displayName)s', which is" - + " requesting encryption keys."; + text = _td("You added a new device '%(displayName)s', which is" + + " requesting encryption keys."); } else { - text = "Your unverified device '%(displayName)s' is requesting" - + " encryption keys."; + text = _td("Your unverified device '%(displayName)s' is requesting" + + " encryption keys."); } text = _t(text, {displayName: displayName}); From 14bce1119c15feefee5813c8f4cd50ded7f76526 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Sat, 23 Sep 2017 21:36:10 +0200 Subject: [PATCH 3/5] Make theme names translatable Signed-off-by: Stefan Parviainen --- src/components/structures/UserSettings.js | 2 +- src/i18n/strings/en_EN.json | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 572ee79a69..5e7658f056 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -793,7 +793,7 @@ module.exports = React.createClass({ onChange={ onChange } /> ; }, diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index a0945d7f50..8b53f17d8c 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -879,5 +879,7 @@ "Failed to remove the room from the summary of %(groupId)s": "Failed to remove the room from the summary of %(groupId)s", "The room '%(roomName)' could not be removed from the summary.": "The room '%(roomName)' could not be removed from the summary.", "Failed to remove a user from the summary of %(groupId)s": "Failed to remove a user from the summary of %(groupId)s", - "The user '%(displayName)s' could not be removed from the summary.": "The user '%(displayName)s' could not be removed from the summary." + "The user '%(displayName)s' could not be removed from the summary.": "The user '%(displayName)s' could not be removed from the summary.", + "Light theme": "Light theme", + "Dark theme": "Dark theme" } From dbae5a66e3a3b1b83bd08304c408a3939b11ed59 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Sun, 24 Sep 2017 09:43:52 +0200 Subject: [PATCH 4/5] Use translation in img alt text Signed-off-by: Stefan Parviainen --- src/components/views/room_settings/AliasSettings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/room_settings/AliasSettings.js b/src/components/views/room_settings/AliasSettings.js index f37bd4271a..ea3bad390f 100644 --- a/src/components/views/room_settings/AliasSettings.js +++ b/src/components/views/room_settings/AliasSettings.js @@ -299,7 +299,7 @@ module.exports = React.createClass({ blurToCancel={ false } onValueChanged={ self.onAliasAdded } />
- Add
: "" From 2b5b7080572940fed75960b76ede1725e7cb6b35 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Sun, 24 Sep 2017 10:14:04 +0200 Subject: [PATCH 5/5] Translate unknown presence label Signed-off-by: Stefan Parviainen --- src/components/views/rooms/PresenceLabel.js | 2 +- src/i18n/strings/en_EN.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/views/rooms/PresenceLabel.js b/src/components/views/rooms/PresenceLabel.js index 47a723f5cd..87b218e2e2 100644 --- a/src/components/views/rooms/PresenceLabel.js +++ b/src/components/views/rooms/PresenceLabel.js @@ -70,7 +70,7 @@ module.exports = React.createClass({ if (presence === "online") return _t("Online"); if (presence === "unavailable") return _t("Idle"); // XXX: is this actually right? if (presence === "offline") return _t("Offline"); - return "Unknown"; + return _t("Unknown"); }, render: function() { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 8b53f17d8c..f3e4b93e9c 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -881,5 +881,6 @@ "Failed to remove a user from the summary of %(groupId)s": "Failed to remove a user from the summary of %(groupId)s", "The user '%(displayName)s' could not be removed from the summary.": "The user '%(displayName)s' could not be removed from the summary.", "Light theme": "Light theme", - "Dark theme": "Dark theme" + "Dark theme": "Dark theme", + "Unknown": "Unknown" }