Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ static/locales/*

# No docker-compose.yml files
docker-compose.yml

# Ignore Masterfile
masterfile.json
6 changes: 1 addition & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"scripts": {
"convert": "node src/geofenceToGeoJSON.js",
"convert-poracle": "node src/poracleToGeoJSON.js",
"create-locales": "node src/createLocales.js",
"create-locales": "node -e 'require(\"./src/createLocales\").locales()'",
"generate": "node -e 'require(\"./src/generateMasterfile\").generate()'",
"start": "node src/index.js",
"test": "npx eslint src/ --ext .js,.jsx,.ts,.tsx",
"test-fix": "npx eslint src/ --ext .js,.jsx,.ts,.tsx --fix",
"update": "npm install && npm update pogo-translations && npm run create-locales"
"update": "npm install && npm run generate && npm run create-locales"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -39,7 +40,6 @@
"mustache-express": "^1.3.0",
"mysql": "^2.18.1",
"nodes2ts": "^2.0.0",
"pogo-translations": "git+https://github.com/bschultz/pogo-translations.git",
"require-from-string": "^2.0.2",
"sanitizer": "^0.1.3"
}
Expand Down
80 changes: 36 additions & 44 deletions src/createLocales.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,44 @@

const fs = require('fs');
const path = require('path');
const axios = require('axios');

const appLocalesFolder = path.resolve(__dirname, '../static/locales');
const pogoLocalesFolder = path.resolve(__dirname, '../node_modules/pogo-translations/static/locales');

fs.readdir(appLocalesFolder, (err, files) => {
let pogoLocalesFiles = [];

if (fs.existsSync(pogoLocalesFolder)) {
pogoLocalesFiles = fs.readdirSync(pogoLocalesFolder);
}

files.filter(file => { return file.startsWith('_'); }).forEach(file => {
const locale = path.basename(file, '.json').replace('_', '');
const localeFile = locale + '.json';
let translations = {};

console.log('Creating locale', locale);

if (pogoLocalesFiles.includes(localeFile)) {
console.log('Found pogo-translations for locale', locale);

const pogoTranslations = fs.readFileSync(
path.resolve(pogoLocalesFolder, localeFile),
{ encoding: 'utf8', flag: 'r' }
module.exports.locales = async function locales() {
const localTranslations = await fs.promises.readdir(appLocalesFolder);
const englishRef = fs.readFileSync(path.resolve(appLocalesFolder, '_en.json'), { encoding: 'utf8', flag: 'r' });

await Promise.all(localTranslations.map(async locale => {
if (locale.startsWith('_')) {
const mapJsTranslations = fs.readFileSync(path.resolve(appLocalesFolder, locale), { encoding: 'utf8', flag: 'r' });
const baseName = locale.replace('.json', '').replace('_', '');
const trimmedRemoteFiles = {};

try {
const { data } = await axios.get(`https://raw.githubusercontent.com/WatWowMap/pogo-translations/master/static/locales/${baseName}.json`);

Object.keys(data).forEach(key => {
if (!key.startsWith('desc_') && !key.startsWith('pokemon_category_')) {
trimmedRemoteFiles[key] = data[key];
}
});
} catch (e) {
console.warn(e, '\n', locale);
}

const finalTranslations = {
...JSON.parse(englishRef),
...JSON.parse(mapJsTranslations),
...trimmedRemoteFiles,
};
fs.writeFile(
path.resolve(appLocalesFolder, `${baseName}.json`),
JSON.stringify(finalTranslations, null, 2),
'utf8',
() => { },
);
translations = JSON.parse(pogoTranslations.toString());
console.log('localeFile', 'file saved.');
}

if (locale !== 'en') {
// include en as fallback first
const appTransFallback = fs.readFileSync(
path.resolve(appLocalesFolder, '_en.json'),
{ encoding: 'utf8', flag: 'r' }
);
translations = Object.assign(translations, JSON.parse(appTransFallback.toString()));
}

const appTranslations = fs.readFileSync(path.resolve(appLocalesFolder, file), { encoding: 'utf8', flag: 'r' });
translations = Object.assign(translations, JSON.parse(appTranslations.toString()));

fs.writeFile(
path.resolve(appLocalesFolder, localeFile),
JSON.stringify(translations, null, 2),
'utf8',
() => {}
);
console.log(localeFile, 'file saved.');
});
});
}));
};
18 changes: 18 additions & 0 deletions src/generateMasterfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require('fs');
const axios = require('axios');

module.exports.generate = async function generate() {
try {
const { data } = await axios.get('https://raw.githubusercontent.com/WatWowMap/Masterfile-Generator/master/master-latest.json');

fs.writeFile(
'static/data/masterfile.json',
JSON.stringify(data, null, 2),
'utf8',
() => { },
);
console.log('New masterfile generated');
} catch (e) {
console.warn('Unable to generate new masterfile, using existing.');
}
};
Loading