Re: How would we use BCP 47 strings in a simple way?
Lassi Kortela 02 Aug 2020 09:51 UTC
(define (bcp-47-filter alist language-tag)
(if (not language-tag)
(and (not (null? alist))
(cdar alist))
(let ((prefix (string-append language-tag "-")))
(any (lambda (pair)
(and (or (string-ci=? language-tag (car pair))
(string-prefix-ci? prefix (car pair)))
(cdr pair)))
alist))))
We could require the alist keys to be normalized to lowercase. Then we
could use lowercase the search key and use case sensitive string comparison.
But that may be overkill. The case-preserved tags (e.g. "en-US") are
nicer for display. It may be useful to dump the whole translations alist
into a REPL for example.