Re: How would we use BCP 47 strings in a simple way? Lassi Kortela 02 Aug 2020 09:36 UTC

[Accidentally pasted the same code twice in the last mail.)

> (define (bcp-47-filter alist language-tag)
>    (any (lambda (pair)
>           (and (or (not language-tag)
>                    (string=? language-tag (car pair))
>                    (string-prefix? language-tag
>                                    (string-append (car pair) "-")))
>                (cdr pair)))
>         alist))

That should probably be:

(define (bcp-47-filter alist language-tag)
   (any (lambda (pair)
          (and (or (not language-tag)
                   (string=? language-tag (car pair))
                   (string-prefix? (string-append language-tag "-")  ; !
                                   (car pair)))                      ; !
               (cdr pair)))
        alist))

With this new version (foreign-error-ref e 'message "e")) returns #f and
not one of the "en-*" messages, which is right.