From 8c1a9a05599c1e1b45992ab14fc391f89f34e63d Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 26 Mar 2019 14:43:48 +0100 Subject: adding i18n framework --- app/client/common/header.component.js | 9 +- app/client/i18n/i18n.en.js | 99 +++++++++++++++++++ app/client/i18n/i18n.moon.js | 99 +++++++++++++++++++ app/client/i18n/index.js | 15 +++ .../modules/pix2pixhd/views/pix2pixhd.live.js | 107 +++++++++++++-------- app/client/system/system.actions.js | 5 + app/client/system/system.component.js | 9 ++ app/client/system/system.reducer.js | 17 ++++ app/client/types.js | 1 + 9 files changed, 317 insertions(+), 44 deletions(-) create mode 100644 app/client/i18n/i18n.en.js create mode 100644 app/client/i18n/i18n.moon.js create mode 100644 app/client/i18n/index.js (limited to 'app') diff --git a/app/client/common/header.component.js b/app/client/common/header.component.js index 8450e8a..d55ec51 100644 --- a/app/client/common/header.component.js +++ b/app/client/common/header.component.js @@ -18,7 +18,7 @@ function NavLink(props){ } function Header(props){ - const { site, app, fps, playing, actions, location, history } = props + const { site, app, fps, playing, actions, location, history, i18n } = props const tool_list = Object.keys(modules).map((name, i) => { const label = name.replace(/_/, " ") return @@ -26,7 +26,7 @@ function Header(props){ const tool = modules[app.tool] const links = tool.links().map((link,i) => { return ( - {link.name} + {i18n.header[link.name] || link.name} ) }) return ( @@ -45,8 +45,8 @@ function Header(props){ {tool_list} - system - dashboard + {i18n.header.system} + {i18n.header.dashboard} {links} {playing && {fps} fps} @@ -58,6 +58,7 @@ const mapStateToProps = state => ({ app: state.system.app, fps: state.live.fps, playing: state.live.playing, + i18n: state.system.i18n.strings, }) const mapDispatchToProps = (dispatch, ownProps) => ({ diff --git a/app/client/i18n/i18n.en.js b/app/client/i18n/i18n.en.js new file mode 100644 index 0000000..406afa6 --- /dev/null +++ b/app/client/i18n/i18n.en.js @@ -0,0 +1,99 @@ +export default { + header: { + system: "system", + dashboard: "dashboard", + folders: "folders", + sequences: "sequences", + checkpoints: "checkpoints", + results: "results", + uprez: "uprez", + live: "live", + pix2pixhd: "pix2pixhd", + pix2pix: "pix2pix", + pix2wav: "pix2wav", + samplernn: "samplernn", + morph: "morph", + }, + gpu: { + idle: "GPU Idle", + busy: "GPU Busy", + start: "Start", + restart: "Restart", + stop: "Stop", + interrupt: "Interrupt", + not_processing: "Not Processing", + processing: "Processing", + }, + pix2pixhd: { + live: { + network: { + title: "Network", + view_mode: "view mode", + sequence: "sequence", + checkpoint: "checkpoint", + epoch: "epoch", + }, + playback: { + title: "Playback", + position: "position", + playback_rate: "playback rate", + skip_frames: "skip frames", + fade_sequence: "fade sequence", + frame_delay: "frame delay", + }, + record: { + save_frame: "Save frame", + save: "Save", + record_video: "Record video", + video_name: "Video name", + }, + transition: { + title: "Transition", + period: "period", + min: "min", + max: "max", + }, + recursion: { + title: "Recursion", + frac: "recursive amount", + roll: "roll amount", + axis: "roll axis", + }, + sequence: { + title: "Sequence", + frac: "sequence frac", + process_frac: "process frac", + }, + transform: { + title: "Transform", + rotate: "rotate", + scale: "scale", + }, + clahe: { + title: "Clahe", + clip_limit: "clip limit", + }, + posterize: { + title: "Posterize", + spatial_window: "spatial window", + color_window: "color window", + }, + blur: { + title: "Blur", + radius: "radius", + sigma: "sigma", + }, + canny: { + title: "Canny Edge Detection", + lo: "lower bound", + hi: "upper bound", + }, + hsl: { + title: "Hue / Saturation", + hue: "hue", + saturation: "saturation", + luminosity: "luminosity", + } + } + } +} diff --git a/app/client/i18n/i18n.moon.js b/app/client/i18n/i18n.moon.js new file mode 100644 index 0000000..930c831 --- /dev/null +++ b/app/client/i18n/i18n.moon.js @@ -0,0 +1,99 @@ +export default { + header: { + system: "system", + dashboard: "dashboard", + folders: "folders", + sequences: "sequences", + checkpoints: "checkpoints", + results: "results", + uprez: "uprez", + live: "live", + pix2pixhd: "pix2pixhd", + pix2pix: "pix2pix", + pix2wav: "pix2wav", + samplernn: "samplernn", + morph: "morph", + }, + gpu: { + idle: "GPU Idle", + busy: "GPU Busy", + start: "Start", + restart: "Restart", + stop: "Stop", + interrupt: "Interrupt", + not_processing: "Not Processing", + processing: "Processing", + }, + pix2pixhd: { + live: { + network: { + title: "Mumbo Jumbo", + view_mode: "bollocks", + sequence: "mess", + checkpoint: "skew", + epoch: "REACTIONARY REGRESSION", + }, + playback: { + title: "Divine", + position: "accelerationism", + playback_rate: "apocalypticism", + skip_frames: "pretend there is an emergent phenomenon", + fade_sequence: "speaking in tongues", + frame_delay: "babble", + }, + record: { + save_frame: "PYROMANCE DISCOUNT", + save: "Save", + record_video: "Pyromance Premium", + video_name: "Video name", + }, + transition: { + title: "Enlightenment", + period: "endarkenment", + min: "MONTECARLOCASINO", + max: "RANDOM STUMBLE", + }, + recursion: { + title: "Proprietary button", + frac: "pay $5M to change this", + roll: "pay $5M and still nothing happens", + axis: "When will I die?", + }, + sequence: { + title: "Political thermometer", + frac: "ignition", + process_frac: "wealth coefficient", + }, + transform: { + title: "Hate", + rotate: "0,14 factor", + scale: "Ariernachweis", + }, + clahe: { + title: "Clahe", + clip_limit: "clip limit", + }, + posterize: { + title: "Posterize", + spatial_window: "spatial window", + color_window: "color window", + }, + blur: { + title: "Blur", + radius: "radius", + sigma: "sigma", + }, + canny: { + title: "Canny Edge Detection", + lo: "lower bound", + hi: "upper bound", + }, + hsl: { + title: "Hue / Saturation", + hue: "hue", + saturation: "saturation", + luminosity: "luminosity", + } + } + } +} diff --git a/app/client/i18n/index.js b/app/client/i18n/index.js new file mode 100644 index 0000000..2bdde02 --- /dev/null +++ b/app/client/i18n/index.js @@ -0,0 +1,15 @@ +import en from './i18n.en' +import moon from './i18n.moon' + +const strings = lang => { + switch (lang) { + case 'moon': + return moon + default: + return en + } +} + +const languages = ['en', 'moon'] + +export { strings, languages } diff --git a/app/client/modules/pix2pixhd/views/pix2pixhd.live.js b/app/client/modules/pix2pixhd/views/pix2pixhd.live.js index 52b4b61..ee7ece7 100644 --- a/app/client/modules/pix2pixhd/views/pix2pixhd.live.js +++ b/app/client/modules/pix2pixhd/views/pix2pixhd.live.js @@ -14,6 +14,8 @@ import * as queueActions from '../../../queue/queue.actions' import * as pix2pixhdTasks from '../pix2pixhd.tasks' import * as pix2pixhdActions from '../pix2pixhd.actions' +import i18n from '../../../i18n' + class Pix2PixHDLive extends Component { constructor(props){ super() @@ -99,10 +101,11 @@ class Pix2PixHDLive extends Component { } render(){ // console.log(this.props) - if (this.props.pix2pixhd.loading) { - return + const { pix2pixhd, i18n } = this.props + if (pix2pixhd.loading) { + return } - const { folderLookup, datasetLookup, sequences } = this.props.pix2pixhd.data + const { folderLookup, datasetLookup, sequences } = pix2pixhd.data const sequenceLookup = sequences.reduce((a,b) => { a[b.name] = true @@ -110,7 +113,7 @@ class Pix2PixHDLive extends Component { }, {}) const sequenceGroups = Object.keys(folderLookup).map(id => { - const folder = this.props.pix2pixhd.data.folderLookup[id] + const folder = folderLookup[id] if (folder.name === 'results') return const datasets = folder.datasets.map(name => { const sequence = sequenceLookup[name] @@ -126,7 +129,7 @@ class Pix2PixHDLive extends Component { }).filter(n => !!n && !!n.options.length).sort((a,b) => a.name.localeCompare(b.name)) const checkpointGroups = Object.keys(folderLookup).map(id => { - const folder = this.props.pix2pixhd.data.folderLookup[id] + const folder = folderLookup[id] if (folder.name === 'results') return const datasets = folder.datasets.map(name => { const dataset = datasetLookup[name] @@ -147,61 +150,62 @@ class Pix2PixHDLive extends Component {
@@ -217,64 +221,74 @@ class Pix2PixHDLive extends Component {
@@ -283,70 +297,80 @@ class Pix2PixHDLive extends Component {
@@ -359,46 +383,47 @@ class Pix2PixHDLive extends Component { } renderRestartButton(){ // console.log(this.props.runner.gpu) + const { i18n } = this.props if (this.props.runner.gpu.status === 'IDLE') { return ( + >{i18n.gpu.start} ) } if (this.props.runner.gpu.task.module !== 'pix2pixhd') { return ( + >{i18n.gpu.interrupt} ) } if (! this.props.opt.processing) { return (
+ >{i18n.gpu.restart} + >{i18n.gpu.interrupt}
) } return (
+ >{i18n.gpu.stop} + >{i18n.gpu.interrupt}
) } @@ -420,16 +445,17 @@ class Pix2PixHDLive extends Component { // ) } renderLiveButtons(){ + const { i18n } = this.props return (
{ @@ -437,7 +463,7 @@ class Pix2PixHDLive extends Component { }} > { @@ -461,6 +487,7 @@ const mapStateToProps = state => ({ epochs: state.live.epochs, sequences: state.live.sequences, runner: state.system.runner, + i18n: state.system.i18n.strings, pix2pixhd: state.module.pix2pixhd, }) diff --git a/app/client/system/system.actions.js b/app/client/system/system.actions.js index ccd9acd..73cea28 100644 --- a/app/client/system/system.actions.js +++ b/app/client/system/system.actions.js @@ -41,6 +41,11 @@ export const changeTool = (tool) => { return { type: types.app.change_tool, tool } } +export const changeLanguage = (language) => { + localStorage.setItem('cortex.i18n.language', language) + return { type: types.system.change_language, language } +} + export const enqueue_test_task = (dataset) => dispatch => { const task = { module: 'test', diff --git a/app/client/system/system.component.js b/app/client/system/system.component.js index 3783862..69a6270 100644 --- a/app/client/system/system.component.js +++ b/app/client/system/system.component.js @@ -10,6 +10,8 @@ import * as liveActions from '../live/live.actions' import * as queueActions from '../queue/queue.actions' import * as authActions from '../auth/auth.actions' +import * as i18n from '../i18n' + const cpu_test_task = { activity: 'cpu', module: 'test', @@ -122,6 +124,13 @@ class System extends Component { + + + {i18n.languages.map(language => ( + + ))} + +
{this.renderCommandOutput()}
diff --git a/app/client/system/system.reducer.js b/app/client/system/system.reducer.js index 5f9e4ac..f232da3 100644 --- a/app/client/system/system.reducer.js +++ b/app/client/system/system.reducer.js @@ -1,7 +1,11 @@ import types from '../types' import moment from 'moment/min/moment.min' +import * as i18n from '../i18n' + let FileSaver = require('file-saver') +const initialLanguage = localStorage.getItem('cortex.i18n.language') || process.env.I18N_LANGUAGE || 'en' + const systemInitialState = { loading: false, error: null, @@ -14,6 +18,10 @@ const systemInitialState = { production: process.env.NODE_ENV === 'production', development: process.env.NODE_ENV !== 'production', }, + i18n: { + language: initialLanguage, + strings: i18n.strings(initialLanguage), + }, app: { tool: localStorage.getItem('system.last_tool') || 'pix2pixhd', }, @@ -246,6 +254,15 @@ const systemReducer = (state = systemInitialState, action) => { last_message: action.data.data, stderr: state.stderr + action.data.data, } + case types.system.change_language: + return { + ...state, + i18n: { + language: action.language, + strings: i18n.strings(action.language), + } + } + default: return state } diff --git a/app/client/types.js b/app/client/types.js index d00ade5..cd82334 100644 --- a/app/client/types.js +++ b/app/client/types.js @@ -15,6 +15,7 @@ export default { counting_directory: 'SYSTEM_COUNTING_DIRECTORY', stdout: 'SYSTEM_STDOUT', stderr: 'SYSTEM_STDERR', + change_language: 'SYSTEM_CHANGE_LANGUAGE', }, app: { change_tool: "APP_CHANGE_TOOL", -- cgit v1.2.3-70-g09d2