Skip to content

Commit 01570c2

Browse files
authored
Merge pull request #984 from WatWowMap/locales-editing-page
feat: locales editing page
2 parents 6a9eec6 + b259e42 commit 01570c2

File tree

21 files changed

+462
-29
lines changed

21 files changed

+462
-29
lines changed

packages/locales/lib/human/en.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,5 +765,19 @@
765765
"reset_spawnpoints": "Reset Spawnpoints",
766766
"reset_submission_cells": "Reset Submission Cells",
767767
"hisuian": "Hisuian",
768-
"spacial_rend_range": "Spacial Rend Range"
768+
"spacial_rend_range": "Spacial Rend Range",
769+
"key": "Key",
770+
"ai": "AI",
771+
"human": "Human",
772+
"locales": "Locales",
773+
"instructions": "Instructions",
774+
"locale_instructions_1": "Select a language from the dropdown",
775+
"locale_instructions_2": "Enter the desired translations in the \"Human\" column",
776+
"locale_instructions_3": "Click the \"$t(download)\" button to download a JSON file",
777+
"locale_instructions_4": "Fork the GitHub repo link below",
778+
"locale_instructions_5": "Create a new branch and name it the language you are translating",
779+
"locale_instructions_6": "Replace the contents of \"packages/locales/lib/human/{{lng}}.json\" with the file you downloaded",
780+
"locale_instructions_7": "Create a pull request",
781+
"locale_instructions_8": "Wait for the pull request to be reviewed and merged",
782+
"enter_translation": "Enter Translation"
769783
}

packages/locales/lib/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
const { create } = require('./create')
22
const { missing } = require('./missing')
33
const { generate } = require('./generate')
4-
const { readLocaleDirectory, writeAll, getStatus } = require('./utils')
4+
const {
5+
readLocaleDirectory,
6+
writeAll,
7+
getStatus,
8+
readAndParseJson,
9+
} = require('./utils')
510

611
const locales = readLocaleDirectory(true).map((x) => x.replace('.json', ''))
712
const status = getStatus()
@@ -12,3 +17,4 @@ module.exports.create = create
1217
module.exports.missing = missing
1318
module.exports.generate = generate
1419
module.exports.writeAll = writeAll
20+
module.exports.readAndParseJson = readAndParseJson

packages/locales/lib/missing.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,34 @@ const { resolve } = require('path')
55
const { log, HELPERS } = require('@rm/logger')
66
const { readAndParseJson, readLocaleDirectory } = require('./utils')
77

8-
async function missing() {
9-
const localTranslations = readLocaleDirectory(true)
8+
/**
9+
*
10+
* @param {string} fileName
11+
* @returns {Promise<import('./generate').I18nObject>}
12+
*/
13+
async function missing(fileName) {
1014
const englishRef = await readAndParseJson('en.json', true)
15+
const humanLocales = await readAndParseJson(fileName, true)
16+
/** @type {import('./generate').I18nObject} */
17+
const missingKeys = {}
1118

12-
await Promise.allSettled(
13-
localTranslations.map(async (fileName) => {
14-
const humanLocales = await readAndParseJson(fileName, true)
15-
const aiLocales = await readAndParseJson(fileName, false)
16-
const combined = {
17-
...aiLocales,
18-
...humanLocales,
19+
Object.keys(englishRef)
20+
.sort()
21+
.forEach((key) => {
22+
if (!humanLocales[key] && !key.startsWith('locale_selection_')) {
23+
missingKeys[key] = process.argv.includes('--ally')
24+
? `t('${key}')`
25+
: englishRef[key]
1926
}
20-
const missingKeys = {}
27+
})
28+
return missingKeys
29+
}
2130

22-
Object.keys(englishRef).forEach((key) => {
23-
if (!combined[key] && !key.startsWith('locale_selection_')) {
24-
missingKeys[key] = process.argv.includes('--ally')
25-
? `t('${key}')`
26-
: englishRef[key]
27-
}
28-
})
31+
async function missingAll() {
32+
const localTranslations = readLocaleDirectory(true)
33+
await Promise.allSettled(
34+
localTranslations.map(async (fileName) => {
35+
const missingKeys = await missing(fileName)
2936
await fs.writeFile(
3037
resolve(
3138
__dirname,
@@ -44,5 +51,5 @@ async function missing() {
4451
module.exports.missing = missing
4552

4653
if (require.main === module) {
47-
missing().then(() => process.exit(0))
54+
missingAll().then(() => process.exit(0))
4855
}

packages/locales/lib/utils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ function getStatus() {
132132
),
133133
)
134134
const mergedSize = Object.keys({ ...aiJson, ...humanJson }).length
135-
const human = +(humanHas / total).toFixed(2) * 100
136-
const localeTotal = Math.min(1, +(mergedSize / total).toFixed(2)) * 100
135+
const human = (humanHas / total) * 100
136+
const localeTotal = (mergedSize / total) * 100
137137
return [
138138
locale.replace('.json', ''),
139139
{
140-
human,
141-
ai: localeTotal - human,
142-
total: localeTotal,
140+
human: Math.round(human),
141+
ai: Math.round(localeTotal - human),
142+
total: Math.round(localeTotal),
143143
},
144144
]
145145
}),

server/src/graphql/resolvers.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { resolve } = require('path')
33
const { GraphQLJSON } = require('graphql-type-json')
44
const { S2LatLng, S2RegionCoverer, S2LatLngRect } = require('nodes2ts')
55
const config = require('@rm/config')
6+
const { missing, readAndParseJson } = require('@rm/locales')
67

78
const buildDefaultFilters = require('../services/filters/builder/base')
89
const filterComponents = require('../services/functions/filterComponents')
@@ -198,6 +199,16 @@ const resolvers = {
198199
}
199200
return {}
200201
},
202+
locales: async (_, { locale }) => {
203+
const missingLocales = await missing(`${locale}.json`)
204+
return locale
205+
? {
206+
missing: Object.keys(missingLocales),
207+
human: await readAndParseJson(`${locale}.json`, true),
208+
ai: await readAndParseJson(`${locale}.json`, false),
209+
}
210+
: { missing: null, human: null, ai: null }
211+
},
201212
motdCheck: (_, { clientIndex }, { req, perms }) => {
202213
const motd = config.getMapConfig(req).messageOfTheDay
203214
return (

server/src/graphql/typeDefs/index.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Query {
2323
filters: JSON
2424
): [Gym]
2525
gymsSingle(id: ID, perm: String): Gym
26+
locales(locale: String): Locales
2627
motdCheck(clientIndex: Int): Boolean
2728
nests(
2829
minLat: Float

server/src/graphql/typeDefs/map.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,9 @@ type ValidUserObj {
216216
loggedIn: Boolean
217217
admin: Boolean
218218
}
219+
220+
type Locales {
221+
human: JSON
222+
ai: JSON
223+
missing: JSON
224+
}

server/src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,13 @@ startApollo(httpServer).then((server) => {
244244
const definition = parse(req.body.query).definitions.find(
245245
(d) => d.kind === 'OperationDefinition',
246246
)
247+
const endpoint = definition?.name?.value || ''
247248
const errorCtx = {
248249
id,
249250
user,
250251
clientV,
251252
serverV,
252-
endpoint: definition.name?.value || '',
253+
endpoint,
253254
}
254255

255256
if (clientV && serverV && clientV !== serverV) {
@@ -262,7 +263,7 @@ startApollo(httpServer).then((server) => {
262263
})
263264
}
264265

265-
if (!perms) {
266+
if (!perms && endpoint !== 'Locales') {
266267
throw new GraphQLError('session_expired', {
267268
extensions: {
268269
...errorCtx,
@@ -275,7 +276,7 @@ startApollo(httpServer).then((server) => {
275276
if (
276277
definition?.operation === 'mutation' &&
277278
!id &&
278-
definition?.name?.value !== 'SetTutorial'
279+
endpoint !== 'SetTutorial'
279280
) {
280281
throw new GraphQLError('unauthenticated', {
281282
extensions: {

server/src/routes/clientRouter.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const CLIENT_ROUTES = [
1515
'/500',
1616
'/reset',
1717
'/playground',
18+
'/locales',
19+
'/data-management',
1820
]
1921

2022
router.get(CLIENT_ROUTES, (req, res) => {

src/assets/css/main.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,9 @@ input[type='time']::-webkit-calendar-picker-indicator {
554554
opacity: 90%;
555555
z-index: 9;
556556
}
557+
558+
.locales-layout {
559+
display: grid;
560+
grid-template-rows: auto 1fr auto; /* Header, table, footer */
561+
min-height: 100svh;
562+
}

0 commit comments

Comments
 (0)