Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into mohammad/merge_ma…
Browse files Browse the repository at this point in the history
…ster
  • Loading branch information
mohammad-deriv committed Nov 15, 2018
2 parents 0ce008f + 6e933b3 commit c0cb254
Show file tree
Hide file tree
Showing 485 changed files with 35,303 additions and 80,365 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = {
'space-in-parens' : ['error', 'never'],
'space-infix-ops' : 'error',
'space-unary-ops' : 'error',
'no-multiple-empty-lines' : ['error', { 'max': 1, 'maxEOF': 1 }],

// import rules
'import/no-extraneous-dependencies' : [0, { extensions: ['.jsx'] }],
Expand Down
24 changes: 2 additions & 22 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
'de': 'de|at|li',
'es': 'ar|bo|cl|co|cr|cu|do|ec|sv|gt|hn|mx|ni|pa|py|pr|es|uy|ve',
'fr': 'fr|ad|bj|bf|cf|cg|ga|gn|ml|mc|ne|sn|tg',
'id': 'id',
'it': 'it',
'ja': 'jp',
'ko': 'kr',
'pl': 'po',
'pt': 'br|mz|ao|pt|gw|pg|cv|st',
Expand Down Expand Up @@ -49,29 +47,11 @@

var all_languages = ['en'].concat(Object.keys(langs));
function redirect() {
var alternative_pages = ['home', 'why-us', 'tour', 'terms-and-conditions', 'signup', 'get-started'];
var redirect_to;
var alt_regex = new RegExp('(' + alternative_pages.map(function(page) { return page + '.html|' + page + '-jp.html' }).join('|') + ')', 'i');
if (alt_regex.test(href)) {
href = href.replace(alt_regex, function(match) {
if (/-jp/.test(match) && !/ja/i.test(lang)) {
redirect_to = match.replace(/-jp/i, '');
} else if (!/-jp/.test(match) && /ja/i.test(lang)) {
redirect_to = match.replace(/\.html/i, '-jp.html');
}
return redirect_to || match;
});
}

// if language is wrong, we need to rebuild the url
var lang_regex = new RegExp('/(' + all_languages.join('|') + ')/', 'i');
if (!lang_regex.test(href)) {
redirect_to = redirect_to || '404';
href = getRoot() + '/' + lang.toLowerCase() + '/' + redirect_to.replace(/\.html/i, '') + '.html';
}

// if not alternate page, redirect to 404 page
if (!redirect_to) {
href = getRoot() + '/' + lang.toLowerCase() + '/' + '404.html';
} else {
href = href.replace(new RegExp('(/' + lang + '/).*', 'i'), '$1404.html');
}

Expand Down
6 changes: 6 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ module.exports = function (grunt) {
config : require('./package.json'),
scope : 'devDependencies',
},
postProcess: function(config) {
// release to translations automatically after releasing to staging, since staging release is always with 'cleanup'
if (global.release_target === 'staging') {
config.aliases.release.push('shell:release_translations');
}
},
});
};
3 changes: 3 additions & 0 deletions build/config/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const initGlobals = (grunt) => {
global.release_info = global.release_config[global.release_target];
global.branch_prefix = '';
global.branch = global.release_info.target_folder;
if (global.release_target === 'staging') {
grunt.option('cleanup', true); // always cleanup when releasing to staging
}
} else {
global.branch_prefix = Constants.config.branch_prefix;
global.branch = grunt.option('branch');
Expand Down
2 changes: 1 addition & 1 deletion build/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function (grunt) {
return {
livereload: {
options: {
hostname : '127.0.0.1',
hostname : '0.0.0.0',
port : 443,
protocol : 'https',
base : 'dist',
Expand Down
4 changes: 2 additions & 2 deletions build/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module.exports = function (grunt) {
expand: true,
src: [
'404.html',
'robots.txt',
'sitemap.xml',
'sitemap*.xml',
'robots.txt'
],
dest: 'dist'
},
Expand Down
51 changes: 33 additions & 18 deletions build/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,40 @@ module.exports = function (grunt) {
stdout: false
}
},
release_translations: {
command: [
prompt('Starting the release to \'translations\'\n'),
'git fetch origin translations:translations',
'git checkout translations',
'grunt release --translations --color',
'git checkout master',
].join(' && '),
options: {
stdout: true
}
},
reset_ghpages: {
command: grunt.option('staging') && grunt.option('reset') ?
[
ghpagesCommand(),
prompt('Resetting to the first commit...'),
'git reset $(git rev-list --max-parents=0 --abbrev-commit HEAD) --quiet',
prompt('Removing .gitignore...'),
'rm -f .gitignore',
'git add .gitignore',
prompt('Adding CNAME...'),
`echo '${global.release_config.staging.CNAME}' > CNAME`,
'git add CNAME',
'git commit -m "Add CNAME" --quiet',
prompt('Pushing to origin...'),
'git push origin gh-pages -f --quiet',
prompt('Cleaning up...'),
'git reset --hard origin/gh-pages --quiet'
].join(' && ') :
prompt('Reset runs only on staging.', 'warn'),
command: grunt.option('reset') ?
(grunt.option('staging') ?
[
ghpagesCommand(),
prompt('Resetting to the first commit...'),
'git reset $(git rev-list --max-parents=0 --abbrev-commit HEAD) --quiet',
prompt('Removing .gitignore...'),
'rm -f .gitignore',
'git add .gitignore',
prompt('Adding CNAME...'),
`echo '${global.release_config.staging.CNAME}' > CNAME`,
'git add CNAME',
'git commit -m "Add CNAME" --quiet',
prompt('Pushing to origin...'),
'git push origin gh-pages -f --quiet',
prompt('Cleaning up...'),
'git reset --hard origin/gh-pages --quiet'
].join(' && ') :
prompt('Reset runs only on staging.', 'warn')
) :
prompt('Reset did not run.'),
options: {
stdout: true
}
Expand Down
10 changes: 7 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
'de': 'de|at|li',
'es': 'ar|bo|cl|co|cr|cu|do|ec|sv|gt|hn|mx|ni|pa|py|pr|es|uy|ve',
'fr': 'fr|ad|bj|bf|cf|cg|ga|gn|ml|mc|ne|sn|tg',
'id': 'id',
'it': 'it',
'ja': 'jp',
'ko': 'kr',
'pl': 'po',
'pt': 'br|mz|ao|pt|gw|pg|cv|st',
Expand All @@ -46,11 +44,14 @@
return conLang;
}
function redirect() {
var loginid = localStorage.getItem('active_loginid');
var client_info = JSON.parse(localStorage.getItem('client.accounts') || '{}')[loginid];
var is_logged_in = client_info && client_info['token'];
window.location.href = (lang || 'en').toLowerCase() + '/' +
(
/\/app\//.test(window.location.pathname)
? ''
: (getCookieItem('loginid') ? (lang === 'ja' ? 'multi_barriers_trading' : 'trading') : 'home' + (lang === 'ja' ? '-jp' : '')) + '.html'
: (is_logged_in ? 'trading' : 'home') + '.html'
)
+ window.location.search;
}
Expand Down Expand Up @@ -84,6 +85,9 @@
}
var lang = getCookieItem('language');
if(lang) {
if (/^id$/i.test(lang)) {
lang = 'en';
}
isDelayedRedirect();
} else {
var ws = new WebSocket('wss://ws.binaryws.com/websockets/v3?app_id=1');
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,18 @@
"time-grunt": "1.4.0",
"uglifyjs-webpack-plugin": "1.3.0",
"webpack": "4.17.2",
"webpack-bundle-analyzer": "2.13.1",
"webpack-bundle-analyzer": "3.0.2",
"webpack-dev-server": "3.1.6",
"webpack-merge": "4.1.4",
"ws": "1.1.5"
},
"dependencies": {
"@binary-com/binary-document-uploader": "2.4.1",
"@binary-com/binary-style": "0.2.10",
"@binary-com/binary-document-uploader": "2.4.2",
"@binary-com/binary-style": "0.2.12",
"@binary-com/smartcharts": "0.3.3",
"@binary-com/webtrader-charts": "0.4.2",
"babel-polyfill": "6.26.0",
"canvas-toBlob": "1.0.0",
"classnames": "2.2.5",
"custom-event-polyfill": "0.3.0",
"davidshimjs-qrcodejs": "0.0.2",
Expand Down
1 change: 0 additions & 1 deletion robots.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
User-agent: *
Sitemap: https://www.binary.com/sitemap.xml
40 changes: 35 additions & 5 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## Update translations
## Updating the Translations

#### Setup
### Initial setup:
* Please make sure you have done `npm install`.
* Install `Homebrew` by `ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`
* Install `Crowdin CLI` by `brew install crowdin` or follow the instructions here: [https://support.crowdin.com/cli-tool/#installation](https://support.crowdin.com/cli-tool/#installation)
* Get [Crowdin API Key](https://crowdin.com/project/binary-static/settings#api) and add this line to your _.bash_profile_: `export CROWDIN_API_KEY='put API Key here'`<br/>
**IMPORTANT!** This key gives full access to all your Crowdin project data. Treat this just like a password and never push it to any public repo.

#### Update translations
### To update the translations:
* Simply run `./scripts/update_translations.sh` in root folder of project to do these tasks:<br/>
(It is possible to confirm/skip each task by answering y/n to questions, only first one is mandatory):
* Check out and update the translations branch
Expand All @@ -17,7 +17,37 @@
* Commit changes and push to origin
* Open github to submit the PR

## Update sitemap
### Extracting texts from js code:
Texts that are used in js code will automatically be extracted during the translation update process (3rd step above: Updating the source file).

* List of paths to include in `sitemap.xml` is here: [sitemap.js](sitemap.js)
In order to make sure that no strings are missed by the extractor code while pushing to translations, please:

1. Refactor the code so that the first argument passed to the `localize()` method is a string literal.
i.e.
```js
const text = localize(is_started ? 'Sell at market' : 'Sell');
```
would change to:
```js
const text = is_started ? localize('Sell at market') : localize('Sell');
```
2. If there is no way to have the string literal in js code (i.e. API texts which are not translated), add them to `scripts/js_texts/static_strings_app.js`.

Note: Regarding API texts, even if the string is translated automatically somewhere else we should still include it here to avoid missing it if that other string gets removed.

3. At the end, when you're sure that a string has already been taken care of, just put this comment `/* localize-ignore */` right after the first argument of `localize()` call to ignore it from tests.
### `js_texts` folder contents:
```
js_texts:
├── extracted_strings_app.js
└── static_strings_app.js
```
- `extracted_strings_app.js`: Contains extracted strings. It's for debugging purpose only and shouldn't be changed manually.
- `static_strings_app.js` to handle those strings that don't exist in js code. e.g. API texts that are not localised, etc.

During the translation update process, the source file `messages.pot` will be updated with all texts from both the above files.

## Updating the Sitemap
* List of paths to include in `sitemap.xml` is here: [config/sitemap_urls.js](config/sitemap_urls.js)
* Once the paths are updated in the above file, run `./scripts/sitemap.js` or `grunt shell:sitemap` to generate new `sitemap.xml`
7 changes: 5 additions & 2 deletions scripts/__tests__/extract_js_texts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ describe('extract_js_texts.js', () => {

before(function (done) {
this.timeout(60000);
extract.parse('app_2', true);
errors_count = extract.getErrorsCount();
errors_count = ['app', 'app_2'].reduce((acc, app) => {
extract.parse(app, true);
return acc + extract.getErrorsCount();
}, 0);
done();
});

Expand All @@ -25,6 +27,7 @@ describe('extract_js_texts.js', () => {
\t1. Please check the errors and refactor the code accordingly.
\t2. If there is no way to have the string literal in js code (i.e. API texts),
\t add them to 'scripts/js_texts/static_strings_[app/app_2].js'.
\t add them to 'scripts/js_texts/static_strings_app.js'.
\t3. At the end, when you're sure that a strings already been taken care of somewhere else,
\t just put this comment /* localize-ignore */ right after the first argument of localize() call to ignore it.`
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const color = require('cli-color');
const expect = require('chai').expect;
const texts = require('../generate-static-data').texts;
const color = require('cli-color');
const expect = require('chai').expect;
const texts_app = require('../js_texts/static_strings_app');

describe('generate-static-data.js', () => {
describe('scripts/js_texts/static_strings_app.js', () => {
const all = {};
const duplicates = {};

before(() => {
texts.forEach((str) => {
texts_app.forEach((str) => {
if (all[str]) {
duplicates[str] = (duplicates[str] || 1) + 1;
} else {
Expand Down
8 changes: 3 additions & 5 deletions scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ const util = require('util');
exports.root_path = require('app-root-path').path;

// ---------- Pages config ----------
exports.pages = require('./pages.js').map(p => ({
exports.pages = require('./config/pages.js').map(p => ({
save_as : p[0],
tpl_path : p[1],
layout : p[2],
title : p[3],
excludes : p[4],
only_ja : p[4] && /^NOT-ja,en$/.test(p[4]),
current_route: p[0].replace(/^(.+)\//, ''),
section : p[5] || '',
}));
Expand All @@ -34,7 +33,7 @@ exports.sections_config = {
};

// ---------- Languages ----------
exports.languages = ['EN', 'DE', 'ES', 'FR', 'ID', 'IT', 'JA', 'KO', 'PL', 'PT', 'RU', 'TH', 'VI', 'ZH_CN', 'ZH_TW'];
exports.languages = ['EN', 'DE', 'ES', 'FR', 'ID', 'IT', 'KO', 'PL', 'PT', 'RU', 'TH', 'VI', 'ZH_CN', 'ZH_TW'];

const affiliates_signup_language_map = { // object used instead of array to prevent accidental index changes
EN : 0,
Expand All @@ -50,7 +49,6 @@ const affiliates_signup_language_map = { // object used instead of array to prev
ZH_CN: 10,
ZH_TW: 11,
TH : 12,
JA : 13,
};
exports.getAffiliateSignupLanguage = (lang = '') => (affiliates_signup_language_map[lang.toUpperCase()] || 0);

Expand All @@ -61,7 +59,7 @@ exports.print = (text) => {
process.stdout.write(text);
};

exports.messageStart = (msg, no_pad) => `${color.cyan('>')} ${msg} ${no_pad ? '' : '.'.repeat(33 - msg.length)}`;
exports.messageStart = (msg, no_pad) => `${color.cyan('>')} ${msg} ${no_pad ? '' : '.'.repeat((this.languages.length + 18) - msg.length)}`;
exports.messageEnd = (duration, no_new_line) => (
`${color.green(' ✓ Done')}${duration ? color.blackBright(` (${duration.toLocaleString().padStart(6)} ms)`) : ''}${no_new_line ? '' : '\n'}`
);
Expand Down
Loading

0 comments on commit c0cb254

Please sign in to comment.