Files
xenia-pos-local/packages/i18n/src/latin.js
T
bonaminandClaude Opus 5.5 e09056a7a4 feat(manager): Media page, photo field for products and categories (platform-v2 step 5.2)
- Management → Media (src/pages/media/): every picture and video, search,
  pictures / videos, batch upload (many files or drop on the page) with a
  result per file, details (preview, display name, kind, resolution, length,
  file size, uploaded file, when / who, the sizes made, what uses it, delete
  off while used).
- MediaField: upload on the spot (into the library and set at once), pick
  from the library (MediaPicker, which can also upload), remove; after an
  upload on the spot "Name it after the product / category" renames it in
  Latin letters. Used by the product editor and the category dialog.
- nav: `anyPerm` (any of the keys that manage pictures); the route guard uses
  the same rule. Product rows have test ids.
- @xenia/i18n: latin() (Greek to Latin, the way venues write it) + tests.
- tests: manager media.test.mjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 15:57:50 +02:00

33 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Greek → Latin letters ("Greeklish"), for names that must be plain English characters, e.g. a
// media item named after its product ("Γύρος χοιρινός" → "Gyros xoirinos", plan step 5.2).
// The style follows how Greek venues write it themselves: χ → x, ξ → ks, η → i, υ → y,
// ου → ou, αυ / ευ → av / ev. Accents go; anything that still isn't plain ASCII is dropped.
const ONE = {
α: 'a', β: 'v', γ: 'g', δ: 'd', ε: 'e', ζ: 'z', η: 'i', θ: 'th', ι: 'i', κ: 'k', λ: 'l', μ: 'm',
ν: 'n', ξ: 'ks', ο: 'o', π: 'p', ρ: 'r', σ: 's', ς: 's', τ: 't', υ: 'y', φ: 'f', χ: 'x', ψ: 'ps', ω: 'o',
}
const TWO = { ου: 'ou', αυ: 'av', ευ: 'ev', γγ: 'ng', ει: 'ei', οι: 'oi', αι: 'ai' }
function matchCase(src, out) {
return src === src.toLowerCase() ? out : out[0].toUpperCase() + out.slice(1)
}
function word(w) {
let out = ''
for (let i = 0; i < w.length; i++) {
const two = TWO[w.slice(i, i + 2).toLowerCase()]
if (two) { out += matchCase(w[i], two); i++; continue }
const one = ONE[w[i].toLowerCase()]
out += one ? matchCase(w[i], one) : w[i]
}
// an all-caps word stays all caps ("ΘΕΑ" → "THEA", not "ThEA")
const letters = w.replace(/[^\p{L}]/gu, '')
return letters.length > 1 && letters === letters.toUpperCase() ? out.toUpperCase() : out
}
/** Latin letters for Greek text; other text passes through (accents removed). */
export function latin(text) {
const s = String(text ?? '').normalize('NFD').replace(/[\u0300-\u036f]/g, '').normalize('NFC')
return s.split(/(\s+)/).map(word).join('').replace(/[^\x20-\x7e]/g, '').replace(/\s+/g, ' ').trim()
}