Files
gooseek/services/localization-svc/src/lib/resolveLocale.ts
home cd6b7857ba feat: default locale Russian, geo determines language for other countries
- localization-svc: defaultLocale ru, resolveLocale only by geo
- web-svc: DEFAULT_LOCALE ru, layout lang=ru, embeddedTranslations fallback ru
- countryToLocale: default ru when no country or unknown country

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-23 15:10:38 +03:00

41 lines
1.2 KiB
TypeScript
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.
import type { GeoDeviceContext, LocalizationContext } from '../types.js';
import {
resolveLocaleFromCountry,
getDefaultLocale,
} from './countryToLocale.js';
/**
* Определяет locale на основе geo-контекста.
* По умолчанию — русский. Только если геопозиция из другой страны — язык этой страны.
*/
export function resolveLocale(ctx: GeoDeviceContext | null): LocalizationContext {
const fallback: LocalizationContext = {
locale: getDefaultLocale(),
language: getDefaultLocale(),
region: null,
countryCode: null,
timezone: null,
source: 'fallback',
};
if (!ctx) return fallback;
const geo = ctx.geo;
// Геопозиция (countryCode) — если есть, используем язык страны
if (geo?.countryCode) {
const locale = resolveLocaleFromCountry(geo.countryCode);
return {
locale,
language: locale,
region: geo.region ?? null,
countryCode: geo.countryCode,
timezone: geo.timezone ?? null,
source: 'geo',
};
}
// Нет гео — по умолчанию русский
return fallback;
}