diff --git a/docs/translating-dev.md b/docs/translating-dev.md index b4682be136..3209f1e400 100644 --- a/docs/translating-dev.md +++ b/docs/translating-dev.md @@ -36,9 +36,13 @@ function getColorName(hex) { ## Adding variables inside a string. 1. Extend your ``_t()`` call. Instead of ``_t(STRING)`` use ``_t(STRING, {})`` -2. Decide how to name it. Please think about if the person who has to translate it can understand what it does. -3. Add it to the array in ``_t`` for example ``_t(STRING, {variable: this.variable})`` -4. Add the variable inside the string. The syntax for variables is ``%(variable)s``. Please note the s at the end. The name of the variable has to match the previous used name. +1. Decide how to name it. Please think about if the person who has to translate it can understand what it does. E.g. using the name 'recipient' is bad, because a translator does not know if it is the name of a person, an email address, a user ID, etc. Rather use e.g. recipientEmailAddress. +1. Add it to the array in ``_t`` for example ``_t(STRING, {variable: this.variable})`` +1. Add the variable inside the string. The syntax for variables is ``%(variable)s``. Please note the _s_ at the end. The name of the variable has to match the previous used name. + +- You can use the special ``count`` variable to choose between multiple versions of the same string, in order to get the correct pluralization. E.g. ``_t('You have %(count)s new messages', { count: 2 })`` would show 'You have 2 new messages', while ``_t('You have %(count)s new messages', { count: 1 })`` would show 'You have one new message' (assuming a singular version of the string has been added to the translation file. See above). Passing in ``count`` is much prefered over having an if-statement choose the correct string to use, because some languages have much more complicated plural rules than english (e.g. they might need a completely different form if there are three things rather than two). +- If you want to translate text that includes e.g. hyperlinks or other HTML you have to also use tag substitution, e.g. ``_t('Click here!', {}, { 'a': (sub) => {sub} })``. If you don't do the tag substitution you will end up showing literally '' rather than making a hyperlink. +- You can also use React components with normal variable substitution if you want to insert HTML markup, e.g. ``_t('Your email address is %(emailAddress)s', { emailAddress: {userEmailAddress} })``. ## Things to know/Style Guides @@ -47,3 +51,5 @@ function getColorName(hex) { - If a string is presented in the UI with punctuation like a full stop, include this in the translation strings, since punctuation varies between languages too. - Avoid "translation in parts", i.e. concatenating translated strings or using translated strings in variable substitutions. Context is important for translations, and translating partial strings this way is simply not always possible. - Concatenating strings often also introduces an implicit assumption about word order (e.g. that the subject of the sentence comes first), which is incorrect for many languages. +- Translation 'smell test': If you have a string that does not begin with a capital letter (is not the start of a sentence) or it ends with e.g. ':' or a preposition (e.g. 'to') you should recheck that you are not trying to translate a partial sentence. +- If you have multiple strings, that are almost identical, except some part (e.g. a word or two) it is still better to translate the full sentence multiple times. It may seem like inefficient repetion, but unlike programming where you try to minimize repetition, translation is much faster if you have many, full, clear, sentences to work with, rather than fewer, but incomplete sentence fragments. diff --git a/src/components/structures/CompatibilityPage.js b/src/components/structures/CompatibilityPage.js index 88b01cb2bb..10806f4ffa 100644 --- a/src/components/structures/CompatibilityPage.js +++ b/src/components/structures/CompatibilityPage.js @@ -17,7 +17,7 @@ limitations under the License. 'use strict'; var React = require('react'); -import { _t, _tJsx } from 'matrix-react-sdk/lib/languageHandler'; +import { _t } from 'matrix-react-sdk/lib/languageHandler'; module.exports = React.createClass({ displayName: 'CompatibilityPage', @@ -40,30 +40,24 @@ module.exports = React.createClass({ return (
-

{ _tJsx("Sorry, your browser is not able to run Riot.", /(.*?)<\/b>/, (sub) => {sub}) }

+

{ _t("Sorry, your browser is not able to run Riot.", {}, { 'b': (sub) => {sub} }) }

{ _t("Riot uses many advanced browser features, some of which are not available or experimental in your current browser.") }

- { _tJsx('Please install Chrome or Firefox for the best experience.', - [ - /(.*?)<\/a>/, - /(.*?)<\/a>/, - ], - [ - (sub) => {sub}, - (sub) => {sub}, - ] + { _t('Please install Chrome or Firefox for the best experience.', + {}, + { + 'chromeLink': (sub) => {sub}, + 'firefoxLink': (sub) => {sub}, + }, )} - { _tJsx('Safari and Opera work too.', - [ - /(.*?)<\/a>/, - /(.*?)<\/a>/, - ], - [ - (sub) => {sub}, - (sub) => {sub}, - ] + { _t('Safari and Opera work too.', + {}, + { + 'safariLink': (sub) => {sub}, + 'operaLink': (sub) => {sub}, + }, )}

diff --git a/src/components/views/globals/PasswordNagBar.js b/src/components/views/globals/PasswordNagBar.js index bf71fa2c2f..a04d48e0c5 100644 --- a/src/components/views/globals/PasswordNagBar.js +++ b/src/components/views/globals/PasswordNagBar.js @@ -20,7 +20,7 @@ import React from 'react'; import sdk from 'matrix-react-sdk'; import Modal from 'matrix-react-sdk/lib/Modal'; import dis from 'matrix-react-sdk/lib/dispatcher'; -import { _t, _tJsx } from 'matrix-react-sdk/lib/languageHandler'; +import { _t } from 'matrix-react-sdk/lib/languageHandler'; export default React.createClass({ onUpdateClicked: function() { @@ -49,10 +49,10 @@ export default React.createClass({ alt="Warning" />

- { _tJsx( + { _t( "To return to your account in future you need to set a password", - /(.*?)<\/u>/, - (sub) => { return { sub }; }, + {}, + { 'u': (sub) => { sub } }, ) }