fork
Configure Feed
Select the types of activity you want to include in your feed.
the browser-facing portion of osu!
fork
Configure Feed
Select the types of activity you want to include in your feed.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
2// See the LICENCE file in the repository root for full licence text.
3
4'use strict';
5
6/* eslint no-console: "off" */
7const { spawnSync } = require('child_process');
8const fs = require('fs');
9const path = require('path');
10const glob = require('glob');
11
12// project root directory
13const rootPath = path.resolve(__dirname, '../../..');
14const buildPath = path.resolve(rootPath, 'resources/builds');
15const localesPath = path.resolve(buildPath, 'locales');
16const messagesPath = path.resolve(buildPath, 'messages.json');
17
18function extractLanguages() {
19 console.log('Extracting localizations...');
20 const messages = getAllMesssages();
21
22 const languages = new Map();
23 for (const key of Object.keys(messages)) {
24 const index = key.indexOf('.');
25 const language = key.substring(0, index);
26 if (!languages.has(language)) {
27 languages.set(language, {});
28 }
29 languages.get(language)[key] = messages[key];
30 }
31
32 return languages;
33}
34
35function getAllMesssages() {
36 const content = fs.readFileSync(messagesPath);
37
38 return JSON.parse(content);
39}
40
41function generateTranslations() {
42 spawnSync('php', [path.resolve(rootPath, 'artisan'), 'lang:js', '--json', messagesPath], { stdio: 'inherit' });
43}
44
45function writeTranslations(languages) {
46 process.stdout.write(`Creating at ${localesPath} for locale:`);
47 for (const lang of languages.keys()) {
48 const json = languages.get(lang);
49 delete json[`${lang}.mail`];
50 const jsonString = JSON.stringify(json);
51 const filename = path.resolve(localesPath, `${lang}.js`);
52 const script = `(function() { 'use strict'; if (window.LangMessages === undefined) window.LangMessages = { messages: {}}; Object.assign(LangMessages, ${jsonString}); })();`;
53
54 fs.writeFileSync(filename, script);
55 process.stdout.write(` ${lang}`);
56 }
57 console.log(' ...all done');
58}
59
60function generateLocalizations() {
61 // Remove previous existing files and ensure directory exists.
62 glob.sync(path.resolve(localesPath, '*.js')).forEach(fs.unlinkSync);
63 fs.mkdirSync(localesPath, { recursive: true });
64
65 generateTranslations();
66 writeTranslations(extractLanguages());
67
68 // cleanup
69 fs.unlinkSync(messagesPath);
70 console.log(`Removed: ${messagesPath}`);
71}
72
73module.exports = generateLocalizations;