Files
ipal-kit/src/modules/lightbox/texts.ts
T
Radosław SmolińskiandClaude Fable 5.2 0a4f001797 IAPL rename, scripted: preferred names in src, bin, scripts, services, tests; bin files and skill folders moved
Replaced by an explicit list of forms only (ten exported names, runtime env names, project file
names and marks, commands, skill names, the log prefix, the brand in prose). Package name, import
paths, routes, CSS tokens, data attributes, custom keys, context flags, the cookie and kv keys are
not touched. package.json keeps the five old bin names beside the five new ones.
The old names stop working in this commit and come back as aliases in the next; docs follow.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-25 17:24:21 +01:00

57 lines
2.0 KiB
TypeScript

import type { LightboxTexts } from './types.js'
/**
* English fallbacks, per field — the same philosophy as NOTIFICATION_FALLBACK.
* Editors translate them in Form messages → Image viewer (iapl `lightbox: true`).
*/
export const LIGHTBOX_FALLBACK: LightboxTexts = {
close: 'Close',
counter: '{current} / {total}',
dialog: 'Image viewer',
next: 'Next image',
open: 'Enlarge image',
previous: 'Previous image',
}
/** Polish fallbacks — used on a page whose locale is Polish. */
export const LIGHTBOX_FALLBACK_PL: LightboxTexts = {
close: 'Zamknij',
counter: '{current} / {total}',
dialog: 'Podgląd zdjęcia',
next: 'Następne zdjęcie',
open: 'Powiększ zdjęcie',
previous: 'Poprzednie zdjęcie',
}
/** Fallbacks for a page language: Polish for 'pl' / 'pl-PL', English for anything else. */
export const lightboxFallback = (locale?: string): LightboxTexts =>
locale?.toLowerCase().startsWith('pl') ? LIGHTBOX_FALLBACK_PL : LIGHTBOX_FALLBACK
/** Merges partial texts over the fallback for `locale` (English when omitted); empty strings fall back too. */
export function resolveLightboxTexts(
texts?: null | Partial<Record<keyof LightboxTexts, null | string>>,
locale?: string,
): LightboxTexts {
const out = { ...lightboxFallback(locale) }
for (const key of Object.keys(out) as (keyof LightboxTexts)[]) {
const value = texts?.[key]
if (typeof value === 'string' && value.trim()) {out[key] = value}
}
return out
}
/** "{current} / {total}" → "2 / 5". */
export const formatLightboxCounter = (template: string, current: number, total: number): string =>
template.replace('{current}', String(current)).replace('{total}', String(total))
/**
* The index after a step of `delta`. `loop` wraps around the ends; without it
* the index stops at the first and last image.
*/
export function lightboxIndex(index: number, delta: number, total: number, loop = true): number {
if (total <= 0) {return 0}
const next = index + delta
if (loop) {return ((next % total) + total) % total}
return Math.min(Math.max(next, 0), total - 1)
}