iya-sts
    Preparing search index...

    Which language a page is drawn in, and the language chooser.

    A static utility class; it holds no state.

    Index
    COOKIE: "sts_lang" = COOKIE

    The chooser's cookie name.

    ROW_CSS: string = WebLocale.ROW_CSS

    The collapsed language row's CSS (#1289), for a server-drawn page's own stylesheet: WebLocale.ROW_CSS.

    • The request this code runs inside, where there is one: audit.js's ambient request, reached LAZILY as passkey_policy.ts reaches it, so this module stays a leaf.

      Returns any

      the request, or null

    • Draws the language chooser: a form posting to the chooser endpoint, the offered locales by their own names, and a submit button.

      Parameters

      • t: WebTranslator

        the page's translator

      • base: string

        the realm's path prefix ('', or /realm/acme). NOT put on the form's action: app.js adds the realm's prefix to every root-relative action in a page drawn inside a realm, so prefixing it here posted to /realm/acme/realm/acme/authn/language. Kept so the callers did not change; the return path carries its own prefix, because a value is not rewritten.

      • returnTo: string

        the path to come back to; held to a local one

      Returns string

      the chooser as HTML

    • The admin console's language (#539 phase 5): the negotiation for the signed-in administrator and the console's own application, its catalogs as data for the browser's WebTranslator, and the locales the chooser offers. GET /admin-api/console answers it as its locale member.

      Parameters

      • req: any

        the request

      • page: PageFor

        the console's application and the administrator

      Returns { catalogs: Record<string, Record<string, string>>; negotiated: Negotiated } & {
          offered: OfferedLocale[];
      }

      { negotiated, catalogs, offered }

    • The console's language WITHOUT its catalogs (#1333): the negotiation, the offered languages, and where each catalog along the chain is. The catalogs are over a megabyte, the same for everybody, and hold no secret. In an API answer they could be neither compressed (BREACH) nor cached; as a static file they are both, at the edge too, under this build's address.

      Parameters

      • req: any

        the request

      • page: PageFor

        the application and person it is for

      Returns {
          catalogFiles: Record<string, string>;
          negotiated: Negotiated;
          offered: OfferedLocale[];
      }

      { negotiated, offered, catalogFiles: { <tag>: <path> } }

    • The Set-Cookie line for the chooser's choice: a year, the whole site, SameSite=Lax, HttpOnly, and Secure where the service is https.

      Parameters

      • tag: string

        the canonical tag chosen

      Returns string

      the header value

    • Builds the translator for a page drawn inside the AMBIENT request — for a page builder that is not handed the request, which is most of them: they are called from dozens of places, many inside a POST. The builder passes what it knows (the application, ui_locales, the person); the request's cookie and Accept-Language come from the ambient request.

      Parameters

      • Optionalpage: PageFor

        the application, ui_locales and person, where known

      Returns WebTranslator

      the translator

    • The path the chooser returns to: the caller's own, plus the listed parameters of the current GET.

      Parameters

      • path: string

        the page's own path and the query it needs

      • Optionalkeep: string[]

        the request's parameters to carry as well, on a GET

      Returns string

      the path

    • The attributes of a page's <html> element: lang and dir.

      Parameters

      • t: WebTranslator

        the page's translator

      Returns string

      lang="…" dir="…", escaped

    • Lists a request's language preferences, best first, in #539's order — everything but the policy's default, which is the last resort.

      Parameters

      • req: any

        the request

      • Optionalpage: PageFor

        what the caller knows about the page

      Returns string[]

      canonical tags, best first, each once

    • Holds a return path to a local path: one that starts with a single /, names no scheme or host, and carries no control character or backslash. Anything else is /.

      Parameters

      • value: unknown

        the path the chooser posted

      Returns string

      a safe local path

    • The language attributes a static surface's shell carries on its <html> (#570), for its runtime to choose the page's language in the browser: the version, the chooser's choice (the cookie is HttpOnly, so the browser cannot read it), the locale policy's default for the surface's application and, where known, its person, and the build the catalogs are keyed by. Each value is canonical or this build's own, so nothing a request sent is drawn back as it arrived.

      Parameters

      • req: any

        the request for the shell

      • application: string

        the surface's application, for the policy

      • Optionalperson: string

        the person the shell is drawn for, where the route serving it already holds one (#1238: their groups may name the profile); '' where nobody is known yet

      Returns [string, string][]

      [[name, value], ...], for ShellDocument.document()

    • Builds the translator a page is drawn with.

      Parameters

      • req: any

        the request

      • Optionalpage: PageFor

        the application, ui_locales and person, where known

      Returns WebTranslator

      the translator