sw: convert web-push-locales to TypeScript, load it with compileTime plugin

This commit is contained in:
Alex Gleason 2023-09-15 14:11:45 -05:00
parent a9624dea9a
commit 0088d908c0
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 9 additions and 9 deletions

View file

@ -3,14 +3,14 @@ import IntlMessageFormat from 'intl-messageformat';
import 'intl-pluralrules';
import unescape from 'lodash/unescape';
import locales from './web-push-locales';
import type {
Account as AccountEntity,
Notification as NotificationEntity,
Status as StatusEntity,
} from 'soapbox/types/entities';
const locales = import.meta.compileTime('./web-push-locales.ts');
/** Limit before we start grouping device notifications into a single notification. */
const MAX_NOTIFICATIONS = 5;
/** Tag for the grouped notification. */

View file

@ -1,16 +1,14 @@
/* @preval */
import fs from 'node:fs';
import path from 'path';
const fs = require('fs');
const path = require('path');
const filtered = {};
const filtered: Record<string, Record<string, string>> = {};
const filenames = fs.readdirSync(path.resolve(__dirname, '../locales'));
filenames.forEach(filename => {
if (!filename.match(/\.json$/) || filename.match(/defaultMessages|whitelist/)) return;
const content = fs.readFileSync(path.resolve(__dirname, `../locales/${filename}`), 'utf-8');
const full = JSON.parse(content);
const full = JSON.parse(content) as Record<string, string>;
const locale = filename.split('.')[0];
filtered[locale] = {
@ -35,4 +33,6 @@ filenames.forEach(filename => {
};
});
module.exports = JSON.parse(JSON.stringify(filtered));
export default () => ({
data: filtered,
});