mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-20 14:06:27 +00:00
c5765bbf15
The apps ship only an address screen now. Once a server is picked, the native side points the WebView at it: TrekBridgeViewController on iOS and a config copy with server.url on Android. The UI then comes from that server, in the version it runs and on its own origin, so the session cookie, uploads, /ws and plugins work exactly as in a browser and no app release has to keep pace with the servers out there. The address screen (native-shell/, built into native-dist/) probes /api/health/features through native HTTP, tries https before http when no scheme was typed, and refuses servers without the nativeApp flag. It also serves as the error page when the remembered server does not load: retry, change server, or on iOS the stored copy of the server's start page. TrekShell is the app's own plugin for all of that: remember, change and reload the server, sign in through ASWebAuthenticationSession or a Custom Tab, and on iOS keep and open the offline copy of the start page, because WKWebView runs no service worker for a domain the app does not list. Plugins the frame does not use are gone (push, camera, geolocation, calendar, file transfer, in-app browser and more): the WebView covers the camera and location itself, and push needs a relay before it is worth shipping. With them go the push entitlement, the calendar usage strings and the Firebase bits. The iOS scheme falls back to capacitor://, since Capacitor drops an iosScheme of https, and the arm64 capability replaces armv7.
35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { SUPPORTED_LANGUAGE_CODES } from '@trek/shared/i18n'
|
|
import type { TranslationStrings } from '@trek/shared/i18n'
|
|
|
|
// Only the native strings of every locale, not the whole UI: this page ships
|
|
// inside the app binary and shows three screens.
|
|
const bundles = import.meta.glob<TranslationStrings>('../../shared/src/i18n/*/native.ts', { eager: true, import: 'default' })
|
|
|
|
function bundleFor(code: string): TranslationStrings | undefined {
|
|
return bundles[`../../shared/src/i18n/${code}/native.ts`]
|
|
}
|
|
|
|
export function pickLocale(preferred: readonly string[]): string {
|
|
for (const lang of preferred) {
|
|
const lower = lang.toLowerCase()
|
|
if (lower === 'pt-br') return 'br'
|
|
if (lower.startsWith('zh-tw') || lower.startsWith('zh-hk') || lower.startsWith('zh-hant')) return 'zh-TW'
|
|
if (lower.startsWith('el')) return 'gr'
|
|
const prefix = lower.split('-')[0]
|
|
const match = SUPPORTED_LANGUAGE_CODES.find((code) => code.toLowerCase() === lower || code === prefix)
|
|
if (match) return match
|
|
}
|
|
return 'en'
|
|
}
|
|
|
|
export function translator(code: string) {
|
|
const strings = bundleFor(code) ?? {}
|
|
const fallback = bundleFor('en') ?? {}
|
|
return (key: string, params: Record<string, string> = {}): string => {
|
|
const template = strings[key] ?? fallback[key] ?? key
|
|
return typeof template === 'string'
|
|
? template.replace(/\{(\w+)\}/g, (whole, name: string) => params[name] ?? whole)
|
|
: key
|
|
}
|
|
}
|