sw: convert web-push-locales to TypeScript, load it with compileTime plugin
This commit is contained in:
parent
a9624dea9a
commit
0088d908c0
2 changed files with 9 additions and 9 deletions
|
@ -3,14 +3,14 @@ import IntlMessageFormat from 'intl-messageformat';
|
||||||
import 'intl-pluralrules';
|
import 'intl-pluralrules';
|
||||||
import unescape from 'lodash/unescape';
|
import unescape from 'lodash/unescape';
|
||||||
|
|
||||||
import locales from './web-push-locales';
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
Account as AccountEntity,
|
Account as AccountEntity,
|
||||||
Notification as NotificationEntity,
|
Notification as NotificationEntity,
|
||||||
Status as StatusEntity,
|
Status as StatusEntity,
|
||||||
} from 'soapbox/types/entities';
|
} from 'soapbox/types/entities';
|
||||||
|
|
||||||
|
const locales = import.meta.compileTime('./web-push-locales.ts');
|
||||||
|
|
||||||
/** Limit before we start grouping device notifications into a single notification. */
|
/** Limit before we start grouping device notifications into a single notification. */
|
||||||
const MAX_NOTIFICATIONS = 5;
|
const MAX_NOTIFICATIONS = 5;
|
||||||
/** Tag for the grouped notification. */
|
/** Tag for the grouped notification. */
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
/* @preval */
|
import fs from 'node:fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
const fs = require('fs');
|
const filtered: Record<string, Record<string, string>> = {};
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const filtered = {};
|
|
||||||
const filenames = fs.readdirSync(path.resolve(__dirname, '../locales'));
|
const filenames = fs.readdirSync(path.resolve(__dirname, '../locales'));
|
||||||
|
|
||||||
filenames.forEach(filename => {
|
filenames.forEach(filename => {
|
||||||
if (!filename.match(/\.json$/) || filename.match(/defaultMessages|whitelist/)) return;
|
if (!filename.match(/\.json$/) || filename.match(/defaultMessages|whitelist/)) return;
|
||||||
|
|
||||||
const content = fs.readFileSync(path.resolve(__dirname, `../locales/${filename}`), 'utf-8');
|
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];
|
const locale = filename.split('.')[0];
|
||||||
|
|
||||||
filtered[locale] = {
|
filtered[locale] = {
|
||||||
|
@ -35,4 +33,6 @@ filenames.forEach(filename => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = JSON.parse(JSON.stringify(filtered));
|
export default () => ({
|
||||||
|
data: filtered,
|
||||||
|
});
|
Loading…
Reference in a new issue