From d1b15c007730b43c3b701ca2f4491596c887bf3f Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 21 Dec 2020 16:14:26 -0500 Subject: [PATCH] Translated some plugins --- plugins/lightning/public/CostEstimateItem.jsx | 7 ++-- plugins/lightning/public/Dashboard.jsx | 33 ++++++++++--------- plugins/lightning/public/Login.jsx | 15 +++++---- plugins/lightning/public/app.jsx | 9 +++-- plugins/measure/api.py | 3 +- plugins/measure/public/MeasurePopup.jsx | 15 +++++---- plugins/measure/public/app.jsx | 7 ++-- 7 files changed, 49 insertions(+), 40 deletions(-) diff --git a/plugins/lightning/public/CostEstimateItem.jsx b/plugins/lightning/public/CostEstimateItem.jsx index 4ddd0c93..6c762eb7 100644 --- a/plugins/lightning/public/CostEstimateItem.jsx +++ b/plugins/lightning/public/CostEstimateItem.jsx @@ -3,6 +3,7 @@ import './CostEstimateItem.scss'; import ResizeModes from 'webodm/classes/ResizeModes'; import PropTypes from 'prop-types'; import $ from 'jquery'; +import { _ } from 'webodm/classes/gettext'; export default class CostEstimateItem extends React.Component { static defaultProps = { @@ -99,10 +100,10 @@ export default class CostEstimateItem extends React.Component { if (json.credits_estimate === 0) json.credits_estimate += " (Free)"; this.setState({credits: json.credits_estimate}) }else{ - this.setState({credits: "Cannot retrieve estimate. Try again later."}); + this.setState({credits: _("Cannot retrieve estimate. Try again later.")}); } }).fail(e => { - this.setState({credits: `Cannot retrieve estimate. Check parameters or try again later.`}); + this.setState({credits: _("Cannot retrieve estimate. Check parameters or try again later.")}); }).always(() => { this.setState({loading: false}); this.estimateRequest = null; @@ -135,7 +136,7 @@ export default class CostEstimateItem extends React.Component { return (
- +
{loading ? : diff --git a/plugins/lightning/public/Dashboard.jsx b/plugins/lightning/public/Dashboard.jsx index c67f6498..2c4b03d2 100644 --- a/plugins/lightning/public/Dashboard.jsx +++ b/plugins/lightning/public/Dashboard.jsx @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'; import './Dashboard.scss'; import $ from 'jquery'; import { _ } from 'webodm/classes/gettext'; +import Trans from 'webodm/components/Trans'; export default class Dashboard extends React.Component { static defaultProps = { @@ -44,11 +45,11 @@ export default class Dashboard extends React.Component { }else if (json.message === "Unauthorized"){ this.props.onLogout(); }else{ - this.setState({ loading: false, error: `Cannot load lightning dashboard. Server responded: ${JSON.stringify(json)}. Are you running the latest version of WebODM?` }); + this.setState({ loading: false, error: _('Cannot load lightning dashboard. Are you running the latest version of WebODM?') }); } }) .fail(() => { - this.setState({ loading: false, error: `Cannot load lightning dashboard. Please make sure you are connected to the internet, or try again in an hour.`}); + this.setState({ loading: false, error: _('Cannot load lightning dashboard. Please make sure you are connected to the internet, or try again in an hour.')}); }); } @@ -71,7 +72,7 @@ export default class Dashboard extends React.Component { } }) .fail(e => { - this.setState({error: `Cannot sync nodes: ${JSON.stringify(e)}. Are you connected to the internet?`}); + this.setState({error: _('Cannot sync nodes. Are you connected to the internet?')}); }) .always(() => { this.setState({syncingNodes: false}); @@ -79,18 +80,18 @@ export default class Dashboard extends React.Component { } handeLogout = () => { - this.setState({loading: true, loadingMessage: "Logging out..."}); + this.setState({loading: true, loadingMessage: _('Logging out…')}); $.post("save_api_key", { api_key: "" }).done(json => { if (!json.success){ - this.setState({error: `Cannot logout: ${JSON.stringify(json)}`}); + this.setState({error: `${_("Cannot logout:")} ${JSON.stringify(json)}`}); } this.setState({loading: false}); this.props.onLogout(); }).fail(e => { - this.setState({loading: false, error: `Cannot logout: ${JSON.stringify(e)}`}); + this.setState({loading: false, error: `${_("Cannot logout:")} ${JSON.stringify(e)}`}); }); } @@ -111,9 +112,9 @@ export default class Dashboard extends React.Component { let balance = ""; if (user){ - balance = ({ user.balance } credits); + balance = ({ user.balance } {_("credits")}); if (user.plan !== null){ - balance = (Unlimited); + balance = ({_("Unlimited")}); } } @@ -126,15 +127,15 @@ export default class Dashboard extends React.Component { { user ?
- Balance: { balance } - - + {_("Balance:")} { balance } + +
-

Hello, { user.email }

+

{_("Hello,")} { user.email }

-
Synced Nodes
+
{_("Synced Nodes")}
{ syncingNodes ? :
    @@ -142,14 +143,14 @@ export default class Dashboard extends React.Component {
  • {n.label}
  • )}
- +
}
{nodes.length > 0 ?
-
- You are all set! When creating a new task from the Dashboard, select {nodes[0].label} from the Processing Node drop-down instead of Auto. +
+ ${_("Dashboard")}`, name: `${nodes[0].label}`, node: `${_("Processing Node")}`}}>You are all set! When creating a new task from the %(dashboard)s, select %(name)s from the %(node)s drop-down instead of Auto.
: ""}
diff --git a/plugins/lightning/public/Login.jsx b/plugins/lightning/public/Login.jsx index 708172fd..9c14ad31 100644 --- a/plugins/lightning/public/Login.jsx +++ b/plugins/lightning/public/Login.jsx @@ -3,6 +3,7 @@ import './Login.scss'; import ErrorMessage from 'webodm/components/ErrorMessage'; import PropTypes from 'prop-types'; import $ from 'jquery'; +import { _ } from 'webodm/classes/gettext'; export default class Login extends React.Component { static defaultProps = { @@ -52,11 +53,11 @@ export default class Login extends React.Component { }else if (json.message){ this.setState({ loggingIn: false, error: json.message }); }else{ - this.setState({ loggingIn: false, error: "Cannot login. Invalid response: " + JSON.stringify(json)}); + this.setState({ loggingIn: false, error: _("Cannot login. Invalid response:") + " " + JSON.stringify(json)}); } }) .fail(() => { - this.setState({loggingIn: false, error: "Cannot login. Please make sure you are connected to the internet, or try again in an hour."}); + this.setState({loggingIn: false, error: _("Cannot login. Please make sure you are connected to the internet, or try again in an hour.")}); }); } @@ -86,27 +87,27 @@ export default class Login extends React.Component {

- +

- +

diff --git a/plugins/lightning/public/app.jsx b/plugins/lightning/public/app.jsx index 0d027f41..1f602426 100644 --- a/plugins/lightning/public/app.jsx +++ b/plugins/lightning/public/app.jsx @@ -2,6 +2,8 @@ import React from 'react'; import PropTypes from 'prop-types'; import Login from './Login'; import Dashboard from './Dashboard'; +import { _ } from 'webodm/classes/gettext'; +import Trans from 'webodm/components/Trans'; export default class LightningPanel extends React.Component { static defaultProps = { @@ -34,9 +36,10 @@ export default class LightningPanel extends React.Component { return (
{ !apiKey ?
-

Lightning Network

- Lightning is a service that allows you to quickly process small and large datasets using high performance servers in the cloud. - Below you can enter your webodm.net credentials to sync your account and automatically setup a new processing node. If you don't have an account, you can register for free. +

{_("Lightning Network")}

+ {_("Lightning is a service that allows you to quickly process small and large datasets using high performance servers in the cloud.")} + webodm.net', register: `${_("register")}`}}> + {_("Below you can enter your %(link)s credentials to sync your account and automatically setup a new processing node. If you don't have an account, you can %(register)s for free.")}
:
diff --git a/plugins/measure/api.py b/plugins/measure/api.py index a58ed41d..acfd4161 100644 --- a/plugins/measure/api.py +++ b/plugins/measure/api.py @@ -14,6 +14,7 @@ from worker.tasks import execute_grass_script from app.plugins.grass_engine import grass, GrassEngineException, cleanup_grass_context from geojson import Feature, Point, FeatureCollection +from django.utils.translation import gettext_lazy as _ class GeoJSONSerializer(serializers.Serializer): area = serializers.JSONField(help_text="Polygon contour defining the volume area to compute") @@ -23,7 +24,7 @@ class TaskVolume(TaskView): def post(self, request, pk=None): task = self.get_and_check_task(request, pk) if task.dsm_extent is None: - return Response({'error': 'No surface model available. From the Dashboard, select this task, press Edit, from the options make sure to check "dsm", then press Restart --> From DEM.'}) + return Response({'error': _('No surface model available. From the Dashboard, select this task, press Edit, from the options make sure to check "dsm", then press Restart --> From DEM.')}) serializer = GeoJSONSerializer(data=request.data) serializer.is_valid(raise_exception=True) diff --git a/plugins/measure/public/MeasurePopup.jsx b/plugins/measure/public/MeasurePopup.jsx index e5424664..14e61805 100644 --- a/plugins/measure/public/MeasurePopup.jsx +++ b/plugins/measure/public/MeasurePopup.jsx @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import './MeasurePopup.scss'; import Utils from 'webodm/classes/Utils'; import Workers from 'webodm/classes/Workers'; +import { _, interpolate } from 'webodm/classes/gettext'; import $ from 'jquery'; import L from 'leaflet'; @@ -101,7 +102,7 @@ export default class MeasurePopup extends React.Component { }else if (result.error){ this.setState({error: result.error}); }else{ - this.setState({error: "Invalid response: " + result}); + this.setState({error: interpolate(_("Invalid response: %(error)s"), { error: result})}); } }).fail(error => { this.setState({error}); @@ -138,12 +139,12 @@ export default class MeasurePopup extends React.Component { const { volume, error } = this.state; return (
-

Area: {this.props.model.areaDisplay}

-

Perimeter: {this.props.model.lengthDisplay}

- {volume === null && !error &&

Volume: computing...

} - {typeof volume === "number" &&

Volume: {volume.toFixed("2")} Cubic Meters ({(volume * 35.3147).toFixed(2)} Cubic Feet)

} - {error &&

Volume: 200 ? 'long' : '')}>{error}

} - Export to GeoJSON +

{_("Area:")} {this.props.model.areaDisplay}

+

{_("Perimeter:")} {this.props.model.lengthDisplay}

+ {volume === null && !error &&

{_("Volume:")} {_("computing…")}

} + {typeof volume === "number" &&

{_("Volume:")} {volume.toFixed("2")} {_("Cubic Meters")} ({(volume * 35.3147).toFixed(2)} {_("Cubic Feet")})

} + {error &&

{_("Volume:")} 200 ? 'long' : '')}>{error}

} + {_("Export to GeoJSON")}
); } } \ No newline at end of file diff --git a/plugins/measure/public/app.jsx b/plugins/measure/public/app.jsx index 3ec7348e..2d76736e 100644 --- a/plugins/measure/public/app.jsx +++ b/plugins/measure/public/app.jsx @@ -7,6 +7,7 @@ import Utils from 'webodm/classes/Utils'; import ReactDOM from 'ReactDOM'; import React from 'React'; import $ from 'jquery'; +import { _ } from 'webodm/classes/gettext'; export default class App{ constructor(map){ @@ -14,8 +15,8 @@ export default class App{ const measure = L.control.measure({ labels:{ - measureDistancesAndAreas: 'Measure volume, area and length', - areaMeasurement: 'Measurement' + measureDistancesAndAreas: _('Measure volume, area and length'), + areaMeasurement: _('Measurement') }, primaryLengthUnit: 'meters', secondaryLengthUnit: 'feet', @@ -23,7 +24,7 @@ export default class App{ secondaryAreaUnit: 'acres' }).addTo(map); - const $btnExport = $("
Export Measurements"); + const $btnExport = $(`
${_("Export Measurements")}`); $btnExport.appendTo($(measure.$startPrompt).children("ul.tasks")); $btnExport.on('click', () => { const features = [];