refactor(frontend): rename booklore-ui to frontend

- Frontend path:
  - rename the tracked Angular app tree from `booklore-ui/` to `frontend/`
  - preserve file contents during the move so this commit stays focused on the path change itself
- Frontend docs:
  - update the moved frontend README and contribution guide where they refer to the renamed folder
  - keep those edits limited to path references introduced by the directory rename
This commit is contained in:
James Cox
2026-04-22 17:26:39 -04:00
committed by Zach Yale
parent c99aa87877
commit 874b013f75
1493 changed files with 3 additions and 3 deletions
@@ -0,0 +1,3 @@
import {environment} from '../../../environments/environment';
export const API_CONFIG = environment.API_CONFIG;
@@ -0,0 +1,38 @@
import {inject} from '@angular/core';
import {TranslocoService} from '@jsverse/transloco';
import {firstValueFrom} from 'rxjs';
import {AVAILABLE_LANGS} from './transloco-loader';
// TODO(grimmory-cleanup): Remove after the Booklore-to-Grimmory localStorage migration window closes.
export const LEGACY_LANG_STORAGE_KEY = 'booklore-lang';
export const LANG_STORAGE_KEY = 'grimmory-lang';
function detectLanguage(available: string[]): string {
const saved = localStorage.getItem(LANG_STORAGE_KEY) ?? localStorage.getItem(LEGACY_LANG_STORAGE_KEY);
if (saved && available.includes(saved)) {
localStorage.setItem(LANG_STORAGE_KEY, saved);
return saved;
}
const browserLocale = navigator.language;
if (browserLocale && available.includes(browserLocale)) {
return browserLocale;
}
const baseLang = browserLocale?.split('-')[0];
if (baseLang && available.includes(baseLang)) {
return baseLang;
}
return 'en';
}
export function initializeLanguage() {
return () => {
const translocoService = inject(TranslocoService);
const lang = detectLanguage(AVAILABLE_LANGS);
translocoService.setActiveLang(lang);
localStorage.setItem(LANG_STORAGE_KEY, lang);
return firstValueFrom(translocoService.load(lang));
};
}
@@ -0,0 +1,79 @@
import {Injectable} from '@angular/core';
import {Translation, TranslocoLoader} from '@jsverse/transloco';
import {from, of, Observable} from 'rxjs';
import en from '../../../i18n/en';
export const EN_TRANSLATIONS: Translation = en;
// To add a new language: create src/i18n/<lang>/ with domain JSONs + index.ts, then add an entry here.
const LAZY_LANG_LOADERS: Record<string, () => Promise<{default: Translation}>> = {
es: () => import('../../../i18n/es'),
it: () => import('../../../i18n/it'),
de: () => import('../../../i18n/de'),
fr: () => import('../../../i18n/fr'),
nl: () => import('../../../i18n/nl'),
pl: () => import('../../../i18n/pl'),
pt: () => import('../../../i18n/pt'),
ru: () => import('../../../i18n/ru'),
hr: () => import('../../../i18n/hr'),
sv: () => import('../../../i18n/sv'),
zh: () => import('../../../i18n/zh'),
ja: () => import('../../../i18n/ja'),
hu: () => import('../../../i18n/hu'),
sl: () => import('../../../i18n/sl'),
sk: () => import('../../../i18n/sk'),
uk: () => import('../../../i18n/uk'),
id: () => import('../../../i18n/id'),
da: () => import('../../../i18n/da'),
};
export const AVAILABLE_LANGS = ['en', ...Object.keys(LAZY_LANG_LOADERS)];
export const LANG_LABELS: Record<string, string> = {
en: 'English',
es: 'Español',
it: 'Italiano',
de: 'Deutsch',
fr: 'Français',
nl: 'Nederlands',
pl: 'Polski',
pt: 'Português',
ru: 'Русский',
hr: 'Hrvatski',
sv: 'Svenska',
zh: '中文',
ja: '日本語',
hu: 'Magyar',
sl: 'Slovenščina',
sk: 'Slovenčina',
uk: 'Українська',
id: 'Bahasa Indonesia',
da: 'Dansk',
};
function deepMerge(base: Record<string, Translation>, override: Record<string, Translation>): Record<string, Translation> {
const result = {...base};
for (const key of Object.keys(override)) {
if (override[key] && typeof override[key] === 'object' && !Array.isArray(override[key])
&& base[key] && typeof base[key] === 'object' && !Array.isArray(base[key])) {
result[key] = deepMerge(base[key], override[key]);
} else if (override[key]) {
result[key] = override[key];
}
}
return result;
}
@Injectable({providedIn: 'root'})
export class TranslocoInlineLoader implements TranslocoLoader {
getTranslation(lang: string): Observable<Translation> {
if (lang === 'en') {
return of(EN_TRANSLATIONS);
}
const loader = LAZY_LANG_LOADERS[lang];
if (loader) {
return from(loader().then(m => deepMerge(EN_TRANSLATIONS, m.default)));
}
return of(EN_TRANSLATIONS);
}
}