Skip to content

Commit

Permalink
Merge pull request #1 from OskarAhl/i18n_index
Browse files Browse the repository at this point in the history
I18n index
  • Loading branch information
msamprz committed Jun 11, 2019
2 parents eccfadd + 9baf47a commit 1776a00
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 61 deletions.
7 changes: 3 additions & 4 deletions build/webpack/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const SWPrecachedWebpackPlugin = require('sw-precache-webpack-plugin');
const webpack = require('webpack');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const PATHS = require('./paths');
const languages = require('../../scripts/common').languages;

const getPlugins = (app, grunt) => ([
new CircularDependencyPlugin({
Expand All @@ -25,12 +24,12 @@ const getPlugins = (app, grunt) => ([
fileName: 'asset-manifest.json',
}),

...(languages.map(lang => new SWPrecachedWebpackPlugin({
new SWPrecachedWebpackPlugin({
cachedId : 'app',
dontCacheBustUrlsMatching : /\.\w{8}\./,
minify : false,
navigateFallback : '',
filepath : path.resolve(PATHS.DIST, `${lang.toLowerCase()}/service-worker.js`),
filepath : path.resolve(PATHS.DIST, 'service-worker.js'),
// TODO Uncomment below lines when changing the release process order to execute `js` task after `render`
// staticFileGlobs : [
// path.resolve(PATHS.DIST, `${lang.toLowerCase()}/index.html`),
Expand All @@ -46,7 +45,7 @@ const getPlugins = (app, grunt) => ([
// eslint-disable-next-line no-console
console.log(message);
},
}))),
}),
]
: []
),
Expand Down
1 change: 0 additions & 1 deletion scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ exports.sections_config = {
path : '',
js_files : ['vendor', 'react_mobx', 'binary_common', 'binary'],
css_files: ['app.min', 'smartcharts'],
has_pjax : false,
},
};

Expand Down
3 changes: 1 addition & 2 deletions src/javascript/app/App/app.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import getBaseName from 'Utils/URL/base-name';
import { MobxProvider } from 'Stores/connect';
import ErrorBoundary from './Components/Elements/Errors/error-boundary.jsx';
import PushNotification from './Containers/push-notification.jsx';
Expand All @@ -19,7 +18,7 @@ import './i18n';
const isTouchDevice = 'ontouchstart' in document.documentElement;

const App = ({ root_store }) => (
<Router basename={getBaseName()}>
<Router>
<MobxProvider store={root_store}>
{
root_store.ui.is_mobile || (root_store.ui.is_tablet && isTouchDevice) ?
Expand Down
17 changes: 0 additions & 17 deletions src/javascript/app/Utils/URL/__tests__/base-name.spec.js

This file was deleted.

19 changes: 0 additions & 19 deletions src/javascript/app/Utils/URL/base-name.js

This file was deleted.

34 changes: 16 additions & 18 deletions src/root_files/_common/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,27 @@
function redirectToReactRoute(lang) {
// Converts the path and query strings into just query strings and
// then redirects the browser to the new url with query strings and hash fragment.
// https://deriv.app/en/statement -> https://deriv.app/en?p=/statement

// https://deriv.app/reports/positions -> https://deriv.app/?p=reports::positions
var pathname = location.pathname.toLowerCase().replace(/\/index(\.html)?/, '');
var base = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
var regex = new RegExp('^((\/[A-Za-z0-9-_]+){0,2})(\/('+ all_languages.join('|') +'))((\/[A-Za-z0-9-_]+)+)', 'i');
var result = regex.exec(pathname);
// Sensible defaults
var prefix = '';
var default_lang = 'en';
var routes = '';
if (result && result.length) {
prefix = result[1] || '';
default_lang = result[4].toLowerCase() || 'en';
routes = result[5] ? result[5].substr(1).replace('/', '::') : '';
var base = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
var br_regex = new RegExp('\/br_[A-Za-z0-9-_]+\/')
var result = br_regex.exec(pathname);
var pathname_has_br_path = result && result.length;
var br_branch_name = '';
var routes;
if (pathname_has_br_path) {
br_branch_name = result[0].substring(0, result[0].length - 1);
routes = pathname.substring(br_branch_name.length);
} else {
routes = pathname;
}

var default_lang = 'EN'; // TODO remove this when i18n is ready.
location.replace(
base
+ prefix // /br_branch_name
+ br_branch_name // /br_branch_name
+ '/' // https://deriv.app/
+ default_lang.toLowerCase() + '?from_404=true&p=' // en?p=
+ routes // statement
// + default_lang.toLowerCase() TODO: add language to querystring instead
+ '?from_404=true&p=' // en?p=
+ routes.substr(1).replace('/', '::') // statement
+ (
location.search ? '&q=' + location.search.slice(1).replace(/&/g, '~and~') : ''
) + location.hash
Expand Down

0 comments on commit 1776a00

Please sign in to comment.