add more translations

move descriptions of canvases.json into .js file in oder to translate it
This commit is contained in:
HF 2021-01-30 08:02:31 +01:00
parent f595c6d2ed
commit 8475ad0c9f
8 changed files with 97 additions and 55 deletions

View File

@ -44,8 +44,7 @@
"cds": 60000, "cds": 60000,
"ranked" : true, "ranked" : true,
"req": -1, "req": -1,
"sd": "2020-01-07", "sd": "2020-01-07"
"desc": "Our main canvas, a huge map of the world. Place everywhere you like"
}, },
"1": { "1": {
"ident": "m", "ident": "m",
@ -92,8 +91,7 @@
"cds": 900000, "cds": 900000,
"ranked" : true, "ranked" : true,
"req": 20000, "req": 20000,
"sd": "2020-01-08", "sd": "2020-01-08"
"desc": "Moon canvas. Safe space for art. No flags or large text (unless part of art)"
}, },
"2": { "2": {
"ident":"v", "ident":"v",
@ -171,8 +169,7 @@
"cds": 60000, "cds": 60000,
"ranked" : false, "ranked" : false,
"req": 0, "req": 0,
"sd": "2020-01-08", "sd": "2020-01-08"
"desc": "Place Voxels on a 3D canvas with others"
}, },
"3": { "3": {
"ident": "c", "ident": "c",
@ -209,8 +206,7 @@
"cds": 60000, "cds": 60000,
"ranked" : false, "ranked" : false,
"req": 0, "req": 0,
"sd": "2020-03-15", "sd": "2020-03-15"
"desc": "Special canvas to spread awareness of SARS-CoV2"
}, },
"5": { "5": {
"ident": "y", "ident": "y",
@ -241,8 +237,7 @@
"cds": 4000, "cds": 4000,
"ranked": false, "ranked": false,
"req": -1, "req": -1,
"sd": "2020-07-05", "sd": "2020-07-05"
"desc": "Mirror of PixelZone"
}, },
"6": { "6": {
"ident": "z", "ident": "z",
@ -273,8 +268,7 @@
"cds": 10000, "cds": 10000,
"ranked": false, "ranked": false,
"req": -1, "req": -1,
"sd": "2020-07-05", "sd": "2020-07-05"
"desc": "Mirror of PixelCanvas"
}, },
"7": { "7": {
"ident": "w", "ident": "w",
@ -293,7 +287,6 @@
"cds": 1000000, "cds": 1000000,
"ranked": true, "ranked": true,
"req": 5000, "req": 5000,
"sd": "2020-11-09", "sd": "2020-11-09"
"desc": "Black and White canvas"
} }
} }

53
src/canvasesDesc.js Normal file
View File

@ -0,0 +1,53 @@
/*
* Create canvases.json with localized translated
* descriptions.
*
* @flow
*/
import canvases from './canvases.json';
import ttag from './core/ttag';
/* eslint-disable max-len */
function getCanvases(t) {
/*
* add descriptions of canvases here
* Use the t tab and right `backquotes`
*/
const canvasDesc = {
0: t`Our main canvas, a huge map of the world. Place everywhere you like`,
1: t`Moon canvas. Safe space for art. No flags or large text (unless part of art)`,
2: t`Place Voxels on a 3D canvas with others`,
3: t`Special canvas to spread awareness of SARS-CoV2`,
5: t`Mirror of PixelZone`,
6: t`Mirror of PixelCanvas`,
7: t`Black and White canvas`,
};
/*
* no edit below here needed when adding/removing canvas
*/
const localicedCanvases = { ...canvases };
const canvasKeys = Object.keys(localicedCanvases);
for (let i = 0; i < canvasKeys.length; i += 1) {
const key = canvasKeys[i];
localicedCanvases[key].desc = canvasDesc[key] || `Canvas ${key}`;
}
}
const lCanvases = {};
(() => {
const langs = Object.keys(ttag);
langs.forEach((lang) => {
lCanvases[lang] = getCanvases(ttag[lang].t);
});
})();
export function getLocalicedCanvases(lang) {
return lCanvases[lang] || lCanvases.default;
}
export default lCanvases;

View File

@ -34,7 +34,7 @@ const CoordinatesBox = ({ view, hover, notifyCopy }) => (
function mapDispatchToProps(dispatch) { function mapDispatchToProps(dispatch) {
return { return {
notifyCopy() { notifyCopy() {
dispatch(notify('Copied!')); dispatch(notify(t`Copied!`));
}, },
}; };
} }

View File

@ -2,6 +2,7 @@
* keypress actions * keypress actions
* @flow * @flow
*/ */
import { t } from 'ttag';
import store from '../ui/store'; import store from '../ui/store';
import copy from '../utils/clipboard'; import copy from '../utils/clipboard';
import { import {
@ -55,7 +56,7 @@ function onKeyPress(event: KeyboardEvent) {
const { hover } = state.gui; const { hover } = state.gui;
const text = hover.join('_'); const text = hover.join('_');
copy(text); copy(text);
store.dispatch(notify('Copied!')); store.dispatch(notify(t`Copied!`));
return; return;
} }
case 'p': case 'p':

View File

@ -6,11 +6,11 @@
* @flow * @flow
*/ */
// eslint-disable-next-line import/no-unresolved // eslint-disable-next-line import/no-unresolved
import canvases from './canvases.json'; import { getLocalicedCanvases } from '../canvasesDesc';
import chatProvider from './ChatProvider'; import chatProvider from './ChatProvider';
export default async function getMe(user) { export default async function getMe(user, lang = 'default') {
const userdata = user.getUserData(); const userdata = user.getUserData();
// sanitize data // sanitize data
const { const {
@ -30,7 +30,7 @@ export default async function getMe(user) {
delete userdata.mailVerified; delete userdata.mailVerified;
delete userdata.mcVerified; delete userdata.mcVerified;
userdata.canvases = canvases; userdata.canvases = getLocalicedCanvases(lang);
userdata.channels = { userdata.channels = {
...chatProvider.defaultChannels, ...chatProvider.defaultChannels,
...userdata.channels, ...userdata.channels,

View File

@ -13,7 +13,7 @@ const ttags = {
default: new TTag(), default: new TTag(),
}; };
function populateTTags() { (() => {
const langs = Object.keys(LOCALES); const langs = Object.keys(LOCALES);
langs.forEach((lang) => { langs.forEach((lang) => {
const ttag = new TTag(); const ttag = new TTag();
@ -21,14 +21,10 @@ function populateTTags() {
ttag.useLocale(lang); ttag.useLocale(lang);
ttags[lang] = ttag; ttags[lang] = ttag;
}); });
} })();
populateTTags();
export function getTTag(lang) { export function getTTag(lang) {
if (ttags[lang]) { return ttags[lang] || ttags.default;
return ttags[lang];
}
return ttags.default;
} }
export default ttags.default; export default ttags;

View File

@ -22,8 +22,6 @@ const styles = [{
cssText: globeCss, cssText: globeCss,
}]; }];
const title = 'PixelPlanet.fun 3DGlobe';
const description = 'pixelplanet globe';
const defaultScripts = assets.globe.js.map( const defaultScripts = assets.globe.js.map(
(s) => ASSET_SERVER + s, (s) => ASSET_SERVER + s,
); );
@ -50,8 +48,8 @@ function generateGlobePage(lang: string): string {
const html = ReactDOM.renderToStaticMarkup( const html = ReactDOM.renderToStaticMarkup(
<Html <Html
title={title} title={t`PixelPlanet.Fun 3DGlobe`}
description={description} description={t`A 3D globe of our whole map`}
scripts={scripts} scripts={scripts}
body={<Globe />} body={<Globe />}
styles={styles} styles={styles}

View File

@ -5,6 +5,7 @@
* *
* @flow * @flow
* */ * */
import { t } from 'ttag';
import { import {
notify, notify,
setPlaceAllowed, setPlaceAllowed,
@ -49,10 +50,10 @@ function requestFromQueue(store) {
pixelTimeout = null; pixelTimeout = null;
store.dispatch(setPlaceAllowed(true)); store.dispatch(setPlaceAllowed(true));
store.dispatch(sweetAlert( store.dispatch(sweetAlert(
'Error :(', t`Error :(`,
'Didn\'t get an answer from pixelplanet. Maybe try to refresh?', t`Didn't get an answer from pixelplanet. Maybe try to refresh?`,
'error', 'error',
'OK', t`OK`,
)); ));
}, 5000); }, 5000);
@ -202,36 +203,36 @@ export function receivePixelReturn(
store.dispatch(placedPixels(pxlCnt)); store.dispatch(placedPixels(pxlCnt));
break; break;
case 1: case 1:
errorTitle = 'Invalid Canvas'; errorTitle = t`Invalid Canvas`;
msg = 'This canvas doesn\'t exist'; msg = t`This canvas doesn't exist`;
break; break;
case 2: case 2:
errorTitle = 'Invalid Coordinates'; errorTitle = t`Invalid Coordinates`;
msg = 'x out of bounds'; msg = t`x out of bounds`;
break; break;
case 3: case 3:
errorTitle = 'Invalid Coordinates'; errorTitle = t`Invalid Coordinates`;
msg = 'y out of bounds'; msg = t`y out of bounds`;
break; break;
case 4: case 4:
errorTitle = 'Invalid Coordinates'; errorTitle = t`Invalid Coordinates`;
msg = 'z out of bounds'; msg = t`z out of bounds`;
break; break;
case 5: case 5:
errorTitle = 'Wrong Color'; errorTitle = t`Wrong Color`;
msg = 'Invalid color selected'; msg = t`Invalid color selected`;
break; break;
case 6: case 6:
errorTitle = 'Just for registered Users'; errorTitle = t`Just for registered Users`;
msg = 'You have to be logged in to place on this canvas'; msg = t`You have to be logged in to place on this canvas`;
break; break;
case 7: case 7:
errorTitle = 'Place more :)'; errorTitle = t`Place more :)`;
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
msg = 'You can not access this canvas yet. You need to place more pixels'; msg = t`You can not access this canvas yet. You need to place more pixels`;
break; break;
case 8: case 8:
store.dispatch(notify('Pixel protected!')); store.dispatch(notify(t`Pixel protected!`));
break; break;
case 9: case 9:
// pixestack used up // pixestack used up
@ -247,21 +248,21 @@ export function receivePixelReturn(
return; return;
case 11: case 11:
errorTitle = 'No Proxies Allowed :('; errorTitle = t`No Proxies Allowed :(`;
msg = 'You are using a Proxy.'; msg = t`You are using a Proxy.`;
break; break;
default: default:
errorTitle = 'Weird'; errorTitle = t`Weird`;
msg = 'Couldn\'t set Pixel'; msg = t`Couldn't set Pixel`;
} }
if (msg) { if (msg) {
store.dispatch(pixelFailure()); store.dispatch(pixelFailure());
store.dispatch(sweetAlert( store.dispatch(sweetAlert(
(errorTitle || `Error ${retCode}`), (errorTitle || t`Error ${retCode}`),
msg, msg,
'error', 'error',
'OK', t`OK`,
)); ));
} }