Created
July 30, 2012 12:54
-
-
Save dmj/3206700 to your computer and use it in GitHub Desktop.
Lexvo language code tables to alist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun dmaus/lexvo/language-code-pairs (lexvo-file) | |
"Return alist of language codes in LEXVO FILE. | |
LEXVO-FILE is the path to a lexvo data file. | |
Each element of the alist is a cons with the ISO639-3 language | |
code in car and the file-specific language code in cdr." | |
(let (code-pairs) | |
(with-current-buffer (find-file-noselect lexvo-file) | |
(save-excursion | |
(goto-char (point-min)) | |
(while (re-search-forward "^\\([a-z]+\\)\\s http://lexvo.org/id/iso639-3/\\([a-z]+\\)$" nil t) | |
(setq code-pairs (cons (cons (match-string 2) (match-string 1)) code-pairs))))) | |
code-pairs)) | |
(defun dmaus/lexvo/language-code-alist (datadir) | |
"Return alist of language codes defined in DATADIR. | |
DATADIR is the path to the lexvo data files. | |
Each element is a list with the ISO639-3 language code in car and | |
a plist with the properties :iso639-2 and :iso639-1 and the | |
respective language codes in cdr." | |
(let ((language-file-map '(("lexvo-iso639-1.tsv" . :iso639-1) | |
("lexvo-iso639-2.tsv" . :iso639-2))) | |
language-code-alist) | |
(dolist (file-pair language-file-map) | |
(dolist (code-pair (dmaus/lexvo/language-code-pairs (expand-file-name (car file-pair) datadir))) | |
(let ((code-plist (cdr (assoc (car code-pair) language-code-alist)))) | |
(if code-plist | |
(plist-put code-plist (cdr file-pair) (cdr code-pair)) | |
(setq language-code-alist (cons (cons (car code-pair) (list (cdr file-pair) (cdr code-pair)) ) language-code-alist)))))) | |
language-code-alist)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment