On this page:
current-locale-specifier
current-locales
load-locales!
translate
wrap-browser-locale

15 Localization

 (require koyo/l10n) package: koyo-lib

This module provides a middleware and facilities for localizing messages.

parameter

(current-locale-specifier)  symbol?

(current-locale-specifier spec)  void?
  spec : symbol?
A parameter that holds the locale specifier for the current application. This value must be a symbol that uniquely identifies the current application among the set of installed packages.

parameter

(current-locales)  (listof (cons/c symbol? symbol?))

(current-locales locales)  void?
  locales : (listof (cons/c symbol? symbol?))
A parameter that holds the current set of locales that translations exist for.

procedure

(load-locales! path)  void?

  path : path-string?
Traverses the directory at path to read the translation files within it.

The directory must have one subdirectory per language and each language subdirectory must contain one translation file per region.

For example, for English, one might define the following structure:

Each translation file must contain a list of pairs where the first element is a symbol and the second is the translation format string for that symbol. For example:

((title    . "Bogdan's Blog")
 (subtitle . "Just another one of these things")
 (hello    . "Hi, ~a!"))

procedure

(translate message-name arg ...)  string?

  message-name : symbol?
  arg : any/c
Looks up the translation format string named message-name for the current-language, current-country and current-locale-specifier and proceeds to format it using the specified args.

If there is no translation named message-name then message-name is converted to a string and the args are ignored.

(translate 'title)
(translate 'hello "Jim")

procedure

((wrap-browser-locale sessions) handler)

  (-> request? can-be-response?)
  sessions : session-manager?
  handler : (-> request? can-be-response?)
A middleware that parameterizes the current-language, current-country and current-locale based on the Accept-Language header. If the value of the header refers to a locale that isn’t in the list of current-locales, then it falls back to en-US.

If 'l10n.lang is present in the current user’s session then that value takes precedence over the value of the Accept-Language header.