feat(i18n): language foundation with en and pt-BR
Nothing in the project was translatable — every string sat inline in English. en.ts is the source dictionary and its type is derived from it, so a typo or a missing key fails typecheck instead of rendering the raw key at runtime. pt-BR.ts is deliberately Partial: translation proceeds one system per update and anything absent falls back to English, so a half-migrated interface is never broken, only partly English. Locale is persisted, guessed from the browser on first run, and kept in sync with <html lang> through a subscription — persisted state rehydrates after first paint, so a one-off assignment would miss it. Translates the voice input panel (including the mic test shipped earlier today) and the profile card as this round's system. Language options are labelled in the active language, so a wrong pick can always be undone.
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import type { Activity } from '@backspace/shared';
|
||||
import { getPrimaryActivity } from '@backspace/shared/src/activities.js';
|
||||
import { useT, type TranslationKey } from '../../i18n';
|
||||
|
||||
interface ProfileActivityProps {
|
||||
activities: Activity[];
|
||||
}
|
||||
|
||||
const VERB: Record<Activity['type'], string> = {
|
||||
playing: 'Playing',
|
||||
listening: 'Listening to',
|
||||
watching: 'Watching',
|
||||
streaming: 'Streaming',
|
||||
custom: '',
|
||||
const VERB_KEY: Record<Exclude<Activity['type'], 'custom'>, TranslationKey> = {
|
||||
playing: 'profile.activity.playing',
|
||||
listening: 'profile.activity.listening',
|
||||
watching: 'profile.activity.watching',
|
||||
streaming: 'profile.activity.streaming',
|
||||
};
|
||||
|
||||
function formatClock(ms: number): string {
|
||||
@@ -34,6 +34,7 @@ function formatClock(ms: number): string {
|
||||
* producer would fill in.
|
||||
*/
|
||||
export function ProfileActivity({ activities }: ProfileActivityProps) {
|
||||
const t = useT();
|
||||
const primary = getPrimaryActivity(activities);
|
||||
const start = primary?.timestamps?.start;
|
||||
const end = primary?.timestamps?.end;
|
||||
@@ -60,7 +61,7 @@ export function ProfileActivity({ activities }: ProfileActivityProps) {
|
||||
return (
|
||||
<div>
|
||||
<span className="text-[11px] uppercase tracking-wide font-semibold text-txt-tertiary">
|
||||
{VERB[primary.type]} {primary.name}
|
||||
{t(VERB_KEY[primary.type])} {primary.name}
|
||||
</span>
|
||||
<div className="mt-2 flex gap-3 rounded-lg bg-surface-elevated/40 p-2.5">
|
||||
{artSrc && (
|
||||
@@ -96,7 +97,7 @@ export function ProfileActivity({ activities }: ProfileActivityProps) {
|
||||
</div>
|
||||
) : start ? (
|
||||
<div className="text-[11px] text-txt-tertiary mt-1 tabular-nums">
|
||||
{formatClock(elapsed)} elapsed
|
||||
{t('profile.activity.elapsed', { time: formatClock(elapsed) })}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user