setup i18n
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Potentially Dangerous Link": "Potentially Dangerous Link",
|
||||
"Blocked Link": "Blocked Link",
|
||||
"This link may be malicious. You should proceed at your own risk.": "This link may be malicious. You should proceed at your own risk.",
|
||||
"This link has been identified as malicious and has blocked for your safety.": "This link has been identified as malicious and has blocked for your safety.",
|
||||
"Continue Anyway": "Continue Anyway",
|
||||
"Return to Bluesky": "Return to Bluesky"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Potentially Dangerous Link": "Enlace Potencialmente Peligroso",
|
||||
"Blocked Link": "Enlace Bloqueado",
|
||||
"This link may be malicious. You should proceed at your own risk.": "Este enlace puede ser malicioso. Debes proceder bajo tu propio riesgo.",
|
||||
"This link has been identified as malicious and has blocked for your safety.": "Este enlace ha sido identificado como malicioso y ha sido bloqueado por tu seguridad.",
|
||||
"Continue Anyway": "Continuar de Todos Modos",
|
||||
"Return to Bluesky": "Regresar a Bluesky"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Potentially Dangerous Link": "Lien Potentiellement Dangereux",
|
||||
"Blocked Link": "Lien Bloqué",
|
||||
"This link may be malicious. You should proceed at your own risk.": "Ce lien peut être malveillant. Vous devriez procéder à vos propres risques.",
|
||||
"This link has been identified as malicious and has blocked for your safety.": "Ce lien a été identifié comme malveillant et a été bloqué pour votre sécurité.",
|
||||
"Continue Anyway": "Continuer Quand Même",
|
||||
"Return to Bluesky": "Retourner à Bluesky"
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
"escape-html": "^1.0.3",
|
||||
"express": "^4.19.2",
|
||||
"http-terminator": "^3.2.0",
|
||||
"i18n": "^0.15.1",
|
||||
"kysely": "^0.27.3",
|
||||
"pg": "^8.12.0",
|
||||
"pino": "^9.2.0",
|
||||
@@ -23,6 +24,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cors": "^2.8.17",
|
||||
"@types/i18n": "^0.13.12",
|
||||
"@types/pg": "^8.11.6",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
|
||||
@@ -1,19 +1,29 @@
|
||||
import escapeHTML from 'escape-html'
|
||||
import {type Request} from 'express'
|
||||
import {type Hole, html} from 'uhtml'
|
||||
|
||||
export function linkWarningContents(opts: {
|
||||
type: 'warn' | 'block'
|
||||
link: string
|
||||
}): Hole {
|
||||
export function linkWarningContents(
|
||||
req: Request,
|
||||
opts: {
|
||||
type: 'warn' | 'block'
|
||||
link: string
|
||||
},
|
||||
): Hole {
|
||||
return html`
|
||||
<div class="warning-icon">⚠️</div>
|
||||
<h1>
|
||||
${opts.type === 'warn' ? 'Potentially Dangerous Link' : 'Blocked Link'}
|
||||
${opts.type === 'warn'
|
||||
? req.__('Potentially Dangerous Link')
|
||||
: req.__('Blocked Link')}
|
||||
</h1>
|
||||
<p class="warning-text">
|
||||
${opts.type === 'warn'
|
||||
? 'This link may be malicious. You should proceed at your own risk.'
|
||||
: 'This link has been identified as malicious and has blocked for your safety.'}
|
||||
? req.__(
|
||||
'This link may be malicious. You should proceed at your own risk.',
|
||||
)
|
||||
: req.__(
|
||||
'This link has been identified as malicious and has blocked for your safety.',
|
||||
)}
|
||||
</p>
|
||||
<div class="blocked-site">
|
||||
<p class="site-url">${escapeHTML(opts.link)}</p>
|
||||
@@ -21,10 +31,12 @@ export function linkWarningContents(opts: {
|
||||
<div class="button-group">
|
||||
${opts.type === 'warn'
|
||||
? html`<a class="button secondary" href="${escapeHTML(opts.link)}"
|
||||
>Continue Anyway</a
|
||||
>${req.__('Continue Anyway')}</a
|
||||
>`
|
||||
: null}
|
||||
<a class="button primary" href="https://bsky.app">Return to Bluesky</a>
|
||||
<a class="button primary" href="https://bsky.app"
|
||||
>${req.__('Return to Bluesky')}</a
|
||||
>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import path from 'node:path'
|
||||
import {fileURLToPath} from 'node:url'
|
||||
|
||||
import i18n from 'i18n'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
|
||||
i18n.configure({
|
||||
locales: ['en', 'es', 'fr'],
|
||||
defaultLocale: 'en',
|
||||
directory: path.join(__dirname, '../locales'),
|
||||
})
|
||||
|
||||
export default i18n
|
||||
@@ -7,6 +7,7 @@ import {createHttpTerminator, type HttpTerminator} from 'http-terminator'
|
||||
|
||||
import {type Config} from './config.js'
|
||||
import {AppContext} from './context.js'
|
||||
import i18n from './i18n.js'
|
||||
import {default as routes, errorHandler} from './routes/index.js'
|
||||
|
||||
export * from './config.js'
|
||||
@@ -17,11 +18,15 @@ export class LinkService {
|
||||
public server?: http.Server
|
||||
private terminator?: HttpTerminator
|
||||
|
||||
constructor(public app: express.Application, public ctx: AppContext) {}
|
||||
constructor(
|
||||
public app: express.Application,
|
||||
public ctx: AppContext,
|
||||
) {}
|
||||
|
||||
static async create(cfg: Config): Promise<LinkService> {
|
||||
let app = express()
|
||||
app.use(cors())
|
||||
app.use(i18n.init)
|
||||
|
||||
const ctx = await AppContext.fromConfig(cfg)
|
||||
app = routes(ctx, app)
|
||||
|
||||
@@ -68,7 +68,7 @@ export default function (ctx: AppContext, app: Express) {
|
||||
case ToolsOzoneSafelinkDefs.BLOCK:
|
||||
hole = linkWarningLayout(
|
||||
'Blocked Link Warning',
|
||||
linkWarningContents({
|
||||
linkWarningContents(req, {
|
||||
type: 'block',
|
||||
link: url.href,
|
||||
}),
|
||||
@@ -79,7 +79,7 @@ export default function (ctx: AppContext, app: Express) {
|
||||
case ToolsOzoneSafelinkDefs.WARN:
|
||||
hole = linkWarningLayout(
|
||||
'Malicious Link Warning',
|
||||
linkWarningContents({
|
||||
linkWarningContents(req, {
|
||||
type: 'warn',
|
||||
link: url.href,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user