From 9b32c764ac65fc9da8ca59b301e9741be0fdf24c Mon Sep 17 00:00:00 2001 From: Mayesters Date: Mon, 12 Jun 2017 12:20:50 +0200 Subject: [PATCH 1/8] Extract Locals script basic setup --- ui/extractLocals.js | 78 +++++++++++++++++++++++++++++++++++++++++++++ ui/package.json | 4 ++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 ui/extractLocals.js diff --git a/ui/extractLocals.js b/ui/extractLocals.js new file mode 100644 index 000000000..542b6806a --- /dev/null +++ b/ui/extractLocals.js @@ -0,0 +1,78 @@ +var fs = require('fs'); +var path = require('path'); +var extract = require('i18n-extract'); +var enLocale = require('../app/dist/locales/en.json'); + +var walk = function(dir, done) { + var results = []; + fs.readdir(dir, function(err, list) { + if (err) return done(err); + var pending = list.length; + if (!pending) return done(null, results); + list.forEach(function(file) { + file = path.resolve(dir, file); + fs.stat(file, function(err, stat) { + if (stat && stat.isDirectory()) { + results.push(file + "/*.js"); + results.push(file + "/*.jsx"); + walk(file, function(err, res) { + results = results.concat(res); + if (!--pending) done(null, results); + }); + } else { + // results.push(file); + if (!--pending) done(null, results); + } + }); + }); + }); +}; + +walk('js/', function(err, results) { + if (err) throw err; + results.push('js/*.js') + results.push('js/*.jsx') + const keys = extract.extractFromFiles(results, { + marker: '__', + }); + + let reports = []; + reports = reports.concat(extract.findMissing(enLocale, keys)); + reports = reports.concat(extract.findUnused(enLocale, keys)); + reports = reports.concat(extract.findDuplicated(enLocale, keys)); + + if (reports.length > 0) { + fs.readFile('../app/dist/locales/en.json', 'utf8', function readFileCallback(err, data){ + if (err){ + console.log(err); + } else { + localeObj = JSON.parse(data); + + for (var i = 0; i < reports.length; i++) { + if (reports[i].type === 'MISSING') { + localeObj[reports[i].key] = reports[i].key; + } else if (reports[i].type === 'UNUSED') { + console.log("Found unused String in en.json, but beware: This may be a String from api.lbry.io, do not blindly delete!") + console.log(reports[i]); + } else if (reports[i].type == "DUPLICATED") { + console.log("Found duplicated String in en.json!") + console.log(reports[i]); + } else { + console.log("Found unknown type of String in en.json!") + console.log(reports[i]); + } + } + + var json = JSON.stringify(localeObj, null, '\t'); //convert it back to json + fs.writeFile('../app/dist/locales/en.json', json, 'utf8', function callback(err) { + if (err) throw err; + console.log('It\'s saved!'); + }); + } + }); + } +}); + + + + diff --git a/ui/package.json b/ui/package.json index 9c4907ba4..b78304ff6 100644 --- a/ui/package.json +++ b/ui/package.json @@ -6,7 +6,8 @@ "test": "echo \"Error: no test specified\" && exit 1", "dev": "webpack-dev-server --devtool eval --progress --colors --inline", "precommit": "lint-staged", - "prettier": "prettier --trailing-comma es5 --write js/**/*.{js,jsx}" + "prettier": "prettier --trailing-comma es5 --write js/**/*.{js,jsx}", + "extract-langs": "node extractLocals.js" }, "keywords": [ "lbry" @@ -55,6 +56,7 @@ "eslint-plugin-jsx-a11y": "^2.2.3", "eslint-plugin-react": "^6.7.1", "husky": "^0.13.4", + "i18n-extract": "^0.4.4", "json-loader": "^0.5.4", "lint-staged": "^3.6.0", "node-sass": "^3.13.0", From ef568ef816fd85bd34470fd91842bf55bfaab27f Mon Sep 17 00:00:00 2001 From: Mayesters Date: Mon, 12 Jun 2017 12:34:40 +0200 Subject: [PATCH 2/8] made script easier --- ui/extractLocals.js | 50 ++++++++++++++------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/ui/extractLocals.js b/ui/extractLocals.js index 542b6806a..aa0de1eb3 100644 --- a/ui/extractLocals.js +++ b/ui/extractLocals.js @@ -1,38 +1,15 @@ -var fs = require('fs'); -var path = require('path'); var extract = require('i18n-extract'); -var enLocale = require('../app/dist/locales/en.json'); +const fs = require('fs'); -var walk = function(dir, done) { - var results = []; - fs.readdir(dir, function(err, list) { - if (err) return done(err); - var pending = list.length; - if (!pending) return done(null, results); - list.forEach(function(file) { - file = path.resolve(dir, file); - fs.stat(file, function(err, stat) { - if (stat && stat.isDirectory()) { - results.push(file + "/*.js"); - results.push(file + "/*.jsx"); - walk(file, function(err, res) { - results = results.concat(res); - if (!--pending) done(null, results); - }); - } else { - // results.push(file); - if (!--pending) done(null, results); - } - }); - }); - }); -}; +var path = '../app/dist/locales/en.json'; -walk('js/', function(err, results) { - if (err) throw err; - results.push('js/*.js') - results.push('js/*.jsx') - const keys = extract.extractFromFiles(results, { +fs.writeFile(path, '{}', 'utf8', function(err) { + if(err) { + return console.log(err); + } + var enLocale = require(path); + + const keys = extract.extractFromFiles(['js/**/*.{js,jsx}'], { marker: '__', }); @@ -42,7 +19,7 @@ walk('js/', function(err, results) { reports = reports.concat(extract.findDuplicated(enLocale, keys)); if (reports.length > 0) { - fs.readFile('../app/dist/locales/en.json', 'utf8', function readFileCallback(err, data){ + fs.readFile(path, 'utf8', function readFileCallback(err, data){ if (err){ console.log(err); } else { @@ -64,14 +41,17 @@ walk('js/', function(err, results) { } var json = JSON.stringify(localeObj, null, '\t'); //convert it back to json - fs.writeFile('../app/dist/locales/en.json', json, 'utf8', function callback(err) { + fs.writeFile(path, json, 'utf8', function callback(err) { if (err) throw err; console.log('It\'s saved!'); }); } }); } -}); +}); + + + From 148392d49a8c7c32b77f0a68c43a6d8ec296a730 Mon Sep 17 00:00:00 2001 From: Mayesters Date: Mon, 12 Jun 2017 21:18:20 +0200 Subject: [PATCH 3/8] update script again --- ui/extractLocals.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/ui/extractLocals.js b/ui/extractLocals.js index aa0de1eb3..f67d123e2 100644 --- a/ui/extractLocals.js +++ b/ui/extractLocals.js @@ -15,8 +15,6 @@ fs.writeFile(path, '{}', 'utf8', function(err) { let reports = []; reports = reports.concat(extract.findMissing(enLocale, keys)); - reports = reports.concat(extract.findUnused(enLocale, keys)); - reports = reports.concat(extract.findDuplicated(enLocale, keys)); if (reports.length > 0) { fs.readFile(path, 'utf8', function readFileCallback(err, data){ @@ -26,24 +24,16 @@ fs.writeFile(path, '{}', 'utf8', function(err) { localeObj = JSON.parse(data); for (var i = 0; i < reports.length; i++) { + // no need to care for other types than MISSING because starting file will always be empty if (reports[i].type === 'MISSING') { localeObj[reports[i].key] = reports[i].key; - } else if (reports[i].type === 'UNUSED') { - console.log("Found unused String in en.json, but beware: This may be a String from api.lbry.io, do not blindly delete!") - console.log(reports[i]); - } else if (reports[i].type == "DUPLICATED") { - console.log("Found duplicated String in en.json!") - console.log(reports[i]); - } else { - console.log("Found unknown type of String in en.json!") - console.log(reports[i]); - } + } } - var json = JSON.stringify(localeObj, null, '\t'); //convert it back to json + var json = JSON.stringify(localeObj, null, '\t'); //convert it back to json-string fs.writeFile(path, json, 'utf8', function callback(err) { if (err) throw err; - console.log('It\'s saved!'); + console.log('Extracted all strings!'); }); } }); From df19708a5cfe43cb41dd2daadd537665a8490b89 Mon Sep 17 00:00:00 2001 From: Mayesters Date: Mon, 19 Jun 2017 14:42:24 +0200 Subject: [PATCH 4/8] fix components --- ui/js/component/rewardLink/view.jsx | 2 +- ui/js/component/userEmailVerify/view.jsx | 8 ++--- ui/js/component/walletSend/view.jsx | 2 +- ui/js/component/welcomeModal/view.jsx | 37 ++++++++++-------------- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/ui/js/component/rewardLink/view.jsx b/ui/js/component/rewardLink/view.jsx index 6ebd50a20..be3a72f35 100644 --- a/ui/js/component/rewardLink/view.jsx +++ b/ui/js/component/rewardLink/view.jsx @@ -21,7 +21,7 @@ const RewardLink = props => { : { claimReward(reward); }} diff --git a/ui/js/component/userEmailVerify/view.jsx b/ui/js/component/userEmailVerify/view.jsx index c6cc65f34..c8ac03636 100644 --- a/ui/js/component/userEmailVerify/view.jsx +++ b/ui/js/component/userEmailVerify/view.jsx @@ -34,7 +34,7 @@ class UserEmailVerify extends React.PureComponent { >

- Email if - you did not receive or are having trouble with your code. + {{__("Email")} {__("if + you did not receive or are having trouble with your code."})

{ this.handleSubmit(event); diff --git a/ui/js/component/walletSend/view.jsx b/ui/js/component/walletSend/view.jsx index 31fd7d911..4d4de0fd6 100644 --- a/ui/js/component/walletSend/view.jsx +++ b/ui/js/component/walletSend/view.jsx @@ -23,7 +23,7 @@ const WalletSend = props => {
-

Welcome to LBRY.

+

{__("Welcome to LBRY.")}

- Using LBRY is like dating a centaur. Totally normal up top, and - {" "}way different underneath. + {__("Using LBRY is like dating a centaur. Totally normal up top, and")} + {" "}{__"way different")} {__("underneath.")}

-

Up top, LBRY is similar to popular media sites.

+

{__("Up top, LBRY is similar to popular media sites.")}

- Below, LBRY is controlled by users -- you -- via blockchain and - decentralization. + {__("Below, LBRY is controlled by users -- you -- via blockchain and decentralization.")}

- Thank you for making content freedom possible! + {__("Thank you for making content freedom possible!")} {" "}{isRewardApproved ? __("Here's a nickel, kid.") : ""}

@@ -31,7 +30,7 @@ class WelcomeModal extends React.PureComponent { : }
@@ -40,32 +39,28 @@ class WelcomeModal extends React.PureComponent { type="alert" overlayClassName="modal-overlay modal-overlay--clear" isOpen={true} - contentLabel="Welcome to LBRY" + contentLabel={__("Welcome to LBRY")} onConfirmed={closeModal} >
-

About Your Reward

+

{__("About Your Reward")}

- You earned a reward of + {__("You earned a reward of")} {" "} - {" "}LBRY - credits, or LBC. + {" "}{__("LBRY")} + {__("credits, or")} {__("LBC")}.

- This reward will show in your Wallet momentarily, probably while - you are reading this message. + {__("This reward will show in your Wallet momentarily, probably while you are reading this message.")}

- LBC is used to compensate creators, to publish, and to have say in - how the network works. + {__("LBC is used to compensate creators, to publish, and to have say in how the network works.")}

- No need to understand it all just yet! Try watching or downloading - something next. + {__("No need to understand it all just yet! Try watching or downloading something next.")}

- Finally, know that LBRY is an early beta and that it earns the - name. + {__("Finally, know that LBRY is an early beta and that it earns the name.")}

; From 95a37e3f8883b21cdad6b2562d73d0fcfed53a52 Mon Sep 17 00:00:00 2001 From: Mayesters Date: Mon, 19 Jun 2017 14:58:39 +0200 Subject: [PATCH 5/8] fix components + pages --- ui/js/component/userEmailVerify/view.jsx | 3 +-- ui/js/component/welcomeModal/view.jsx | 2 +- ui/js/page/discover/view.jsx | 8 +++---- ui/js/page/publish/view.jsx | 30 ++++++++++++++---------- ui/js/page/rewards/view.jsx | 9 ++++--- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/ui/js/component/userEmailVerify/view.jsx b/ui/js/component/userEmailVerify/view.jsx index c8ac03636..bf6e9605e 100644 --- a/ui/js/component/userEmailVerify/view.jsx +++ b/ui/js/component/userEmailVerify/view.jsx @@ -46,8 +46,7 @@ class UserEmailVerify extends React.PureComponent { {/* render help separately so it always shows */}

- {{__("Email")} {__("if - you did not receive or are having trouble with your code."}) + {__("Email")} {__("if you did not receive or are having trouble with your code.")}

diff --git a/ui/js/component/welcomeModal/view.jsx b/ui/js/component/welcomeModal/view.jsx index 5e0a0aae6..19f32b080 100644 --- a/ui/js/component/welcomeModal/view.jsx +++ b/ui/js/component/welcomeModal/view.jsx @@ -14,7 +14,7 @@ class WelcomeModal extends React.PureComponent {

{__("Welcome to LBRY.")}

{__("Using LBRY is like dating a centaur. Totally normal up top, and")} - {" "}{__"way different")} {__("underneath.")} + {" "}{__("way different")} {__("underneath.")}

{__("Up top, LBRY is similar to popular media sites.")}

diff --git a/ui/js/page/discover/view.jsx b/ui/js/page/discover/view.jsx index ea51972eb..a37611cc7 100644 --- a/ui/js/page/discover/view.jsx +++ b/ui/js/page/discover/view.jsx @@ -5,10 +5,8 @@ import FileCard from "component/fileCard"; import { BusyMessage } from "component/common.js"; import ToolTip from "component/tooltip.js"; -const communityCategoryToolTipText = - "Community Content is a public space where anyone can share content with the " + - 'rest of the LBRY community. Bid on the names "one," "two," "three," "four" and ' + - '"five" to put your content here!'; + + const FeaturedCategory = props => { const { category, names } = props; @@ -21,7 +19,7 @@ const FeaturedCategory = props => { category.match(/^community/i) && } diff --git a/ui/js/page/publish/view.jsx b/ui/js/page/publish/view.jsx index 2628e01e8..ecfc34066 100644 --- a/ui/js/page/publish/view.jsx +++ b/ui/js/page/publish/view.jsx @@ -433,17 +433,23 @@ class PublishPage extends React.PureComponent { "You have already used this URL. Publishing to it again will update your previous publish." ); } else if (this.state.topClaimValue) { - return ( - - {__n( - 'A deposit of at least "%s" credit is required to win "%s". However, you can still get a permanent URL for any amount.', - 'A deposit of at least "%s" credits is required to win "%s". However, you can still get a permanent URL for any amount.', - this.state.topClaimValue /*pluralization param*/, - this.state.topClaimValue, - this.state.name /*regular params*/ - )} - - ); + if (this.state.topClaimValue === 1) { + return ( + + {__( + 'A deposit of at least "%s" credit is required to win "%s". However, you can still get a permanent URL for any amount.' + )} + + ); + } else { + return ( + + {__( + 'A deposit of at least "%s" credits is required to win "%s". However, you can still get a permanent URL for any amount.' + )} + + ); + } } else { return ""; } @@ -752,7 +758,7 @@ class PublishPage extends React.PureComponent { /> {

{claimed - ? Reward claimed. + ? {__("Reward claimed.")} : }
{reward.reward_description}
@@ -59,14 +59,13 @@ const RewardsPage = props => {

{__("You are not eligible to claim rewards.")}

- To become eligible, email - {" "} with a - link to a public social media profile. + {__("To become eligible, email")} + {" "} {__("with a link to a public social media profile.")}

); } else if (fetching) { - content = ; + content = ; } else if (rewards.length > 0) { content = rewards.map(reward => From 51ea169329d9efb539d2e97803434a27ebe8f767 Mon Sep 17 00:00:00 2001 From: Mayesters Date: Mon, 19 Jun 2017 15:49:26 +0200 Subject: [PATCH 6/8] fix publish page --- ui/js/page/publish/view.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/js/page/publish/view.jsx b/ui/js/page/publish/view.jsx index ecfc34066..ed1f399ae 100644 --- a/ui/js/page/publish/view.jsx +++ b/ui/js/page/publish/view.jsx @@ -437,7 +437,7 @@ class PublishPage extends React.PureComponent { return ( {__( - 'A deposit of at least "%s" credit is required to win "%s". However, you can still get a permanent URL for any amount.' + 'A deposit of at least one credit is required to win "%s". However, you can still get a permanent URL for any amount.' )} ); @@ -445,7 +445,7 @@ class PublishPage extends React.PureComponent { return ( {__( - 'A deposit of at least "%s" credits is required to win "%s". However, you can still get a permanent URL for any amount.' + 'A deposit of at least "%s" credits is required to win "%s". However, you can still get a permanent URL for any amount.', this.state.topClaimValue )} ); From 7fd9c25af26bb6bd1cab25864e836241b1493332 Mon Sep 17 00:00:00 2001 From: Mayesters Date: Mon, 19 Jun 2017 15:50:10 +0200 Subject: [PATCH 7/8] fix publish again cuz im stupid --- ui/js/page/publish/view.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/js/page/publish/view.jsx b/ui/js/page/publish/view.jsx index ed1f399ae..ce2cc6551 100644 --- a/ui/js/page/publish/view.jsx +++ b/ui/js/page/publish/view.jsx @@ -437,7 +437,7 @@ class PublishPage extends React.PureComponent { return ( {__( - 'A deposit of at least one credit is required to win "%s". However, you can still get a permanent URL for any amount.' + 'A deposit of at least one credit is required to win "%s". However, you can still get a permanent URL for any amount.', this.state.name )} ); @@ -445,7 +445,7 @@ class PublishPage extends React.PureComponent { return ( {__( - 'A deposit of at least "%s" credits is required to win "%s". However, you can still get a permanent URL for any amount.', this.state.topClaimValue + 'A deposit of at least "%s" credits is required to win "%s". However, you can still get a permanent URL for any amount.', this.state.topClaimValue, this.state.name )} ); From 0540b3d3b8677bf8c30e6632ac0c764b64c6714b Mon Sep 17 00:00:00 2001 From: Mayesters Date: Mon, 19 Jun 2017 15:51:28 +0200 Subject: [PATCH 8/8] welcome modal i18n simplification --- ui/js/component/welcomeModal/view.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/js/component/welcomeModal/view.jsx b/ui/js/component/welcomeModal/view.jsx index 19f32b080..2e71f9e3e 100644 --- a/ui/js/component/welcomeModal/view.jsx +++ b/ui/js/component/welcomeModal/view.jsx @@ -47,8 +47,7 @@ class WelcomeModal extends React.PureComponent {

{__("You earned a reward of")} {" "} - {" "}{__("LBRY")} - {__("credits, or")} {__("LBC")}. + {" "}{__("LBRY credits, or")} {__("LBC")}.

{__("This reward will show in your Wallet momentarily, probably while you are reading this message.")}