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
4 changes: 2 additions & 2 deletions .github/workflows/verify-hashes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ on:
paths:
- 'frontend/public/images/**'
- 'frontend/public/hashes/**'
- 'frontend/assets/cards/**'
- 'frontend/assets/cards.json'
- 'package.json'
- 'pnpm-lock.yaml'
pull_request:
paths:
- 'frontend/public/images/**'
- 'frontend/public/hashes/**'
- 'frontend/assets/cards/**'
- 'frontend/assets/cards.json'
- 'package.json'
- 'pnpm-lock.yaml'
jobs:
Expand Down
1,981 changes: 1,981 additions & 0 deletions frontend/public/hashes/de-DE/hashes.json

Large diffs are not rendered by default.

378 changes: 189 additions & 189 deletions frontend/public/hashes/en-US/hashes.json

Large diffs are not rendered by default.

214 changes: 214 additions & 0 deletions frontend/public/hashes/es-ES/hashes.json

Large diffs are not rendered by default.

184 changes: 92 additions & 92 deletions frontend/public/hashes/fr-FR/hashes.json

Large diffs are not rendered by default.

214 changes: 214 additions & 0 deletions frontend/public/hashes/it-IT/hashes.json

Large diffs are not rendered by default.

214 changes: 214 additions & 0 deletions frontend/public/hashes/pt-BR/hashes.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion frontend/src/i18n.tsx → frontend/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import LanguageDetector from 'i18next-browser-languagedetector'
import Backend from 'i18next-http-backend'
import { initReactI18next } from 'react-i18next'

export const allLocales = ['en-US', 'es-ES', 'pt-BR', 'fr-FR', 'it-IT', 'de-DE']

i18n
.use(Backend)
.use(initReactI18next)
Expand All @@ -14,7 +16,7 @@ i18n
backend: {
loadPath: '/locales/{{lng}}/{{ns}}.json',
},
supportedLngs: ['en-US', 'es-ES', 'pt-BR', 'fr-FR', 'it-IT', 'de-DE'],
supportedLngs: allLocales,
})

export default i18n
2 changes: 1 addition & 1 deletion frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Suspense } from 'react'
import { createRoot } from 'react-dom/client'
import { I18nextProvider } from 'react-i18next'
import App from './App.tsx'
import i18n from './i18n.tsx'
import i18n from './i18n'
import './index.css'
import './registerServiceWorker.js'

Expand Down
11 changes: 6 additions & 5 deletions scripts/generate-scan-hashes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'node:fs'
import path from 'node:path'
import { parseArgs } from 'node:util'
import sharp from 'sharp'
import { allLocales } from '../frontend/src/i18n'
import { allCards, getCardByInternalId } from '../frontend/src/lib/CardsDB'
import { calculatePerceptualHash, calculateSimilarity, hashSize } from '../frontend/src/lib/hash'
import { chunk } from '../frontend/src/lib/utils'
Expand All @@ -12,7 +13,6 @@ console.log(`Using libwebp ${sharp.versions.webp}`)

const imagesDir = 'frontend/public/images'
const targetDir = 'frontend/public/hashes'
const locales = ['en-US', 'es-ES', 'fr-FR', 'it-IT', 'pt-BR']

const { values } = parseArgs({
options: {
Expand Down Expand Up @@ -81,7 +81,7 @@ async function generateHash(id: number, locale: string) {

const hashes = Object.fromEntries(
await Promise.all(
locales.map(async (x) => {
allLocales.map(async (x) => {
try {
const data = await fs.promises.readFile(hashPath(x), 'utf8')
return [x, JSON.parse(data)]
Expand All @@ -98,7 +98,7 @@ function checkSimilar(hash1: ArrayBuffer | undefined, hash2: ArrayBuffer | undef
} else if (hash1 === undefined || hash2 === undefined) {
return false
} else {
return calculateSimilarity(hash1, hash2) > 0.99
return calculateSimilarity(hash1, hash2) > 0.97
}
}

Expand Down Expand Up @@ -130,16 +130,17 @@ const handleCard = async (id: number, locale: string) => {

const all_ids = [...new Set(allCards.map((c) => c.internal_id))]

for (const locale of locales) {
for (const locale of allLocales) {
console.log(`\nProcessing locale: ${locale}`)
const chunks = chunk(all_ids, 10)
let processed = 0

for (const ids of chunks) {
await Promise.all(ids.map((id) => handleCard(id, locale)))
processed += ids.length
console.log(`Progress: ${processed}/${all_ids.length} cards (${Math.round((processed / all_ids.length) * 100)}%)`)
process.stdout.write(`\rProgress: ${processed}/${all_ids.length} cards (${((100 * processed) / all_ids.length).toFixed()}%)`)
}
console.log()
}

if (values.verify) {
Expand Down