From 1087b365978f0ec3a5ebb10e10dbd9aee4b0e932 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 18 Oct 2017 17:32:46 +0100 Subject: [PATCH 1/5] fix editing visuals on groupview header --- src/components/structures/GroupView.js | 49 ++++++++++++++++---------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/components/structures/GroupView.js b/src/components/structures/GroupView.js index 26f8c4a413..c4edc4cea4 100644 --- a/src/components/structures/GroupView.js +++ b/src/components/structures/GroupView.js @@ -490,15 +490,15 @@ export default React.createClass({ }); }, - _onNameChange: function(e) { - const newProfileForm = Object.assign(this.state.profileForm, { name: e.target.value }); + _onNameChange: function(value) { + const newProfileForm = Object.assign(this.state.profileForm, { name: value }); this.setState({ profileForm: newProfileForm, }); }, - _onShortDescChange: function(e) { - const newProfileForm = Object.assign(this.state.profileForm, { short_description: e.target.value }); + _onShortDescChange: function(value) { + const newProfileForm = Object.assign(this.state.profileForm, { short_description: value }); this.setState({ profileForm: newProfileForm, }); @@ -878,18 +878,29 @@ export default React.createClass({ ); - nameNode = ; - shortDescNode = ; + + const EditableText = sdk.getComponent("elements.EditableText"); + + nameNode = ; + + shortDescNode = + rightButtons.push( ; if (summary.profile && summary.profile.name) { - nameNode =
+ nameNode =
{ summary.profile.name } ({ this.props.groupId })
; } else { - nameNode = { this.props.groupId }; + nameNode = { this.props.groupId }; } if (summary.profile && summary.profile.short_description) { - shortDescNode = { summary.profile.short_description }; + shortDescNode = { summary.profile.short_description }; } rightButtons.push( Date: Wed, 18 Oct 2017 19:36:07 +0100 Subject: [PATCH 2/5] Make gen-i18n support 'HTML' Where by 'HTML' I mean just run the same regex as riot does over some text. Also make it walk multiple paths. This mostly means it can be used for riot-web. --- scripts/gen-i18n.js | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/scripts/gen-i18n.js b/scripts/gen-i18n.js index 3ce5aeb312..c6e162cfb0 100644 --- a/scripts/gen-i18n.js +++ b/scripts/gen-i18n.js @@ -34,6 +34,13 @@ const TRANSLATIONS_FUNCS = ['_t', '_td', '_tJsx']; const INPUT_TRANSLATIONS_FILE = 'src/i18n/strings/en_EN.json'; +// NB. The sync version of walk is broken for single files so we walk +// all of res rather than just res/home.html. +// https://git.daplie.com/Daplie/node-walk/merge_requests/1 fixes it, +// or if we get bored waiting for it to be merged, we could switch +// to a project that's actively maintained. +const SEARCH_PATHS = ['src', 'res']; + const FLOW_PARSER_OPTS = { esproposal_class_instance_fields: true, esproposal_class_static_fields: true, @@ -64,7 +71,7 @@ function getTKey(arg) { return null; } -function getTranslations(file) { +function getTranslationsJs(file) { const tree = flowParser.parse(fs.readFileSync(file, { encoding: 'utf8' }), FLOW_PARSER_OPTS); const trs = new Set(); @@ -106,6 +113,20 @@ function getTranslations(file) { return trs; } +function getTranslationsOther(file) { + const contents = fs.readFileSync(file, { encoding: 'utf8' }); + + const trs = new Set(); + + // Taken from riot-web src/components/structures/HomePage.js + const translationsRegex = /_t\(['"]([\s\S]*?)['"]\)/mg; + let matches; + while (matches = translationsRegex.exec(contents)) { + trs.add(matches[1]); + } + return trs; +} + // gather en_EN plural strings from the input translations file: // the en_EN strings are all in the source with the exception of // pluralised strings, which we need to pull in from elsewhere. @@ -123,20 +144,32 @@ for (const key of Object.keys(inputTranslationsRaw)) { const translatables = new Set(); -walk.walkSync("src", { +const walkOpts = { listeners: { file: function(root, fileStats, next) { - if (!fileStats.name.endsWith('.js')) return; - const fullPath = path.join(root, fileStats.name); - const trs = getTranslations(fullPath); + + let ltrs; + if (fileStats.name.endsWith('.js')) { + trs = getTranslationsJs(fullPath); + } else if (fileStats.name.endsWith('.html')) { + trs = getTranslationsOther(fullPath); + } else { + return; + } console.log(`${fullPath} (${trs.size} strings)`); for (const tr of trs.values()) { translatables.add(tr); } }, } -}); +}; + +for (const path of SEARCH_PATHS) { + if (fs.existsSync(path)) { + walk.walkSync(path, walkOpts); + } +} const trObj = {}; for (const tr of translatables) { From 7fe8c9cb01b3a3e38d55b8d7ef529887619c5a36 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 19 Oct 2017 01:48:49 +0200 Subject: [PATCH 3/5] fix lint --- src/components/structures/GroupView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/GroupView.js b/src/components/structures/GroupView.js index c4edc4cea4..5da4e7b413 100644 --- a/src/components/structures/GroupView.js +++ b/src/components/structures/GroupView.js @@ -899,7 +899,7 @@ export default React.createClass({ initialValue={this.state.profileForm.short_description} onValueChanged={this._onShortDescChange} tabIndex="2" - dir="auto" /> + dir="auto" />; rightButtons.push( Date: Thu, 19 Oct 2017 10:19:43 +0100 Subject: [PATCH 4/5] Add i18n script to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0ae6fd999b..3d15529e1c 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "scripts": { "reskindex": "node scripts/reskindex.js -h header", "reskindex:watch": "node scripts/reskindex.js -h header -w", + "i18n": "node scripts/gen-i18n.js", "build": "npm run reskindex && babel src -d lib --source-maps --copy-files", "build:watch": "babel src -w -d lib --source-maps --copy-files", "emoji-data-strip": "node scripts/emoji-data-strip.js", From 027a70ffe7f2f38db7d3e9cdf6c2f93f4fe698d6 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 19 Oct 2017 10:51:54 +0100 Subject: [PATCH 5/5] Add gen-i18n as a 'binary' and add appropriate shebang --- package.json | 5 +++-- scripts/gen-i18n.js | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) mode change 100644 => 100755 scripts/gen-i18n.js diff --git a/package.json b/package.json index 3d15529e1c..0ee4c3e331 100644 --- a/package.json +++ b/package.json @@ -28,12 +28,13 @@ "test" ], "bin": { - "reskindex": "scripts/reskindex.js" + "reskindex": "scripts/reskindex.js", + "matrix-gen-i18n": "scripts/gen-i18n.js" }, "scripts": { "reskindex": "node scripts/reskindex.js -h header", "reskindex:watch": "node scripts/reskindex.js -h header -w", - "i18n": "node scripts/gen-i18n.js", + "i18n": "matrix-gen-i18n", "build": "npm run reskindex && babel src -d lib --source-maps --copy-files", "build:watch": "babel src -w -d lib --source-maps --copy-files", "emoji-data-strip": "node scripts/emoji-data-strip.js", diff --git a/scripts/gen-i18n.js b/scripts/gen-i18n.js old mode 100644 new mode 100755 index c6e162cfb0..609c6b00c5 --- a/scripts/gen-i18n.js +++ b/scripts/gen-i18n.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + /* Copyright 2017 New Vector Ltd