diff --git a/chronogram-cldr-parser.lisp b/chronogram-cldr-parser.lisp index 9af6ead..04b2ec3 100644 --- a/chronogram-cldr-parser.lisp +++ b/chronogram-cldr-parser.lisp @@ -115,10 +115,12 @@ (territory (when territory-node (plump:get-attribute territory-node "type"))) (calendars (funcall parse-calendar root))) - `((language . ,language) - ,@(when territory - `((territory . ,territory))) - ,@(when calendars - `((calendars . ,calendars))))))) + (values `((language . ,language) + ,@(when territory + `((territory . ,territory))) + ,@(when calendars + `((calendars . ,calendars)))) + language + territory)))) ;; (parse-cldr (uiop:read-file-string "cldr-staging/production/common/main/en_GB.xml")) diff --git a/chronogram-dist.lisp b/chronogram-dist.lisp index ffb0c50..d2f0781 100644 --- a/chronogram-dist.lisp +++ b/chronogram-dist.lisp @@ -2,69 +2,46 @@ (defpackage #:chronogram-dist (:use #:cl) + (:local-nicknames (:p :chronogram-cldr-parser)) (:export #:make-dist)) (in-package #:chronogram-dist) -(defun get-cldr-release-tag (system) - (string-trim '(#\linefeed #\return #\space) - (uiop:read-file-string - (asdf:system-relative-pathname system "CLDR_RELEASE")))) +(defun make-chronogram-info (contents dist-dir) + (multiple-value-bind (info language territory) + (chronogram-cldr-parser:parse-cldr contents) + (with-open-file (stream (if territory + (format nil "~a~a_~a.lisp" + dist-dir + language + territory) + (format nil "~a~a.lisp" + dist-dir + language)) + :direction :output + :if-exists :supersede + :if-does-not-exist :create) + (let ((*package* (find-package 'chronogram-cldr-parser))) + (format stream "~s~%" info))))) -(defun get-archive-url (tag) - (format nil - "https://github.com/unicode-org/cldr-staging/archive/refs/tags/~a.zip" - tag)) - -(defun make-chronogram-info (contents dist-dir name) - (with-open-file (stream (format nil "~a~a.lisp" dist-dir name) - :direction :output - :if-exists :supersede - :if-does-not-exist :create) - (let ((*package* (find-package 'chronogram-cldr-parser))) - (format stream "~s~%" (chronogram-cldr-parser:parse-cldr contents))))) - -(defun make-dist (&optional force-download) +(defun make-dist () (let* ((system (asdf:find-system 'chronogram t)) (dist-dir (asdf:system-relative-pathname system "chronogram-dist/")) (cldr-submodule-available (uiop:file-exists-p (asdf:system-relative-pathname system "cldr-staging/LICENSE.txt"))) - (tag (when (or force-download (not cldr-submodule-available)) - (get-cldr-release-tag system))) - (names '("en" "de" "hu" "ko"))) + (cldr-dir (asdf:system-relative-pathname system "cldr-staging")) + (paths (uiop:directory-files (format nil "~a/production/common/main/" + cldr-dir)))) + (unless cldr-submodule-available + (error "cldr-staging submodule not checked out")) (ensure-directories-exist dist-dir) - (if tag - (uiop:with-temporary-file (:stream s) - (format t "Downloading cldr release ~a... " tag) - (force-output) - (let ((bytes (dex:get (get-archive-url tag)))) - (write-sequence bytes s) - (finish-output s)) - (format t "DONE~%") - (zip:with-zipfile (f s) - (loop :for name :in names - :for entry := (zip:get-zipfile-entry - (format nil "cldr-~a/~a" tag name) f) - :do (format t "Writing ~a~a.lisp... " dist-dir name) - :do (force-output) - :do (make-chronogram-info - (babel:octets-to-string (zip:zipfile-entry-contents entry) - :encoding :utf-8) - dist-dir - name) - :do (format t "DONE~%")))) - (loop :with cldr-dir - := (asdf:system-relative-pathname system "cldr-staging/") - :for name :in names - :do (format t "Writing ~a~a.lisp... " dist-dir name) - :do (force-output) - :do (make-chronogram-info - (uiop:read-file-string - (format nil "~a/production/common/main/~a.xml" - cldr-dir - name)) - dist-dir - name) - :do (format t "DONE~%"))))) + (loop :with cldr-dir + := (asdf:system-relative-pathname system "cldr-staging/") + :for path :in paths + :do (format t "Parsing ~a... " path) + :do (force-output) + :do (make-chronogram-info (uiop:read-file-string path) + dist-dir) + :do (format t "DONE~%"))))