aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu installer newt locale)
  #:use-module (gnu installer locale)
  #:use-module (gnu installer steps)
  #:use-module (gnu installer newt page)
  #:use-module (guix i18n)
  #:use-module (newt)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-35)
  #:use-module (ice-9 match)
  #:export (run-locale-page))

(define (run-language-page languages language->text)
  (define result
    (run-listbox-selection-page
     #:title (G_ "Locale language")
     #:info-text (G_ "Choose the language to use for the \
installation process and for the installed system.")
     #:info-textbox-width 70
     #:listbox-items languages
     #:listbox-item->text language->text
     #:sort-listbox-items? #f
     #:button-text (G_ "Exit")
     #:button-callback-procedure
     (lambda _
       (abort-to-prompt 'installer-step 'abort))))

  ;; Immediately install the chosen language so that the territory page that
  ;; comes after (optionally) is displayed in the chosen language.
  (setenv "LANGUAGE" result)

  result)

(define (run-territory-page territories territory->text)
  (let ((title (G_ "Locale location")))
    (run-listbox-selection-page
     #:title title
     #:info-text (G_ "Choose a territory for this language.")
     #:listbox-items territories
     #:listbox-item->text territory->text
     #:button-text (G_ "Back")
     #:button-callback-procedure
     (lambda _
       (abort-to-prompt 'installer-step 'abort)))))

(define (run-codeset-page codesets)
  (let ((title (G_ "Locale codeset")))
    (run-listbox-selection-page
     #:title title
     #:info-text (G_ "Choose the locale encoding.")
     #:listbox-items codesets
     #:listbox-item->text identity
     #:listbox-default-item "UTF-8"
     #:button-text (G_ "Back")
     #:button-callback-procedure
     (lambda _
       (abort-to-prompt 'installer-step 'abort)))))

(define (run-modifier-page modifiers modifier->text)
  (let ((title (G_ "Locale modifier")))
    (run-listbox-selection-page
     #:title title
     #:info-text (G_ "Choose your locale's modifier. The most frequent \
modifier is euro. It indicates that you want to use Euro as the currency \
symbol.")
     #:listbox-items modifiers
     #:listbox-item->text modifier->text
     #:button-text (G_ "Back")
     #:button-callback-procedure
     (lambda _
       (abort-to-prompt 'installer-step 'abort)))))

(define* (run-locale-page #:key
                          supported-locales
                          iso639-languages
                          iso3166-territories)
  "Run a page asking the user to select a locale language and possibly
territory, codeset and modifier. Use SUPPORTED-LOCALES as the list of glibc
available locales. ISO639-LANGUAGES is an association list associating a
locale code to a locale name. ISO3166-TERRITORIES is an association list
associating a territory code with a territory name. The formatted locale, under
glibc format is returned."

  (define (break-on-locale-found locales)
    "Break to the installer step if LOCALES contains exactly one
element."
    (and (= (length locales) 1)
         (abort-to-prompt 'installer-step 'break)))

  (define (filter-locales locales result)
    "Filter the list of locale records LOCALES using the RESULT returned by
the installer-steps defined below."
    (filter
     (lambda (locale)
       (and-map identity
                `(,(string=? (locale-language locale)
                             (result-step result 'language))
                  ,@(if (result-step-done? result 'territory)
                        (list (equal? (locale-territory locale)
                                      (result-step result 'territory)))
                        '())
                  ,@(if (result-step-done? result 'codeset)
                        (list (equal? (locale-codeset locale)
                                      (result-step result 'codeset)))
                        '())
                  ,@(if (result-step-done? result 'modifier)
                        (list (equal? (locale-modifier locale)
                                      (result-step result 'modifier)))
                        '()))))
     locales))

  (define (result->locale-string locales result)
    "Supposing that LOCALES contains exactly one locale record, turn it into a
glibc locale string and return it."
    (match (filter-locales locales result)
      ((locale)
       (locale->locale-string locale))))

  (define (sort-languages languages)
    "Extract some languages from LANGUAGES list and place them ahead."
    (let* ((first-languages '("en"))
           (other-languages (lset-difference equal?
                                             languages
                                             first-languages)))
      `(,@first-languages ,@other-languages)))

  (define locale-steps
    (list
     (installer-step
      (id 'language)
      (compute
       (lambda _
         (run-language-page
          (sort-languages
           (delete-duplicates (map locale-language supported-locales)))
          (lambda (language)
            (let ((english (language-code->language-name iso639-languages
                                                         language)))
              (setenv "LANGUAGE" language)
              (let ((native (gettext english "iso_639-3")))
                (unsetenv "LANGUAGE")
                native)))))))
     (installer-step
      (id 'territory)
      (compute
       (lambda (result _)
         (let ((locales (filter-locales supported-locales result)))
           ;; Stop the process if the language returned by the previous step
           ;; is matching one and only one supported locale.
           (break-on-locale-found locales)

           ;; Otherwise, ask the user to select a territory among those
           ;; supported by the previously selected language.
           (run-territory-page
            (delete-duplicates (map locale-territory locales))
            (lambda (territory)
              (if territory
                  (let ((english (territory-code->territory-name
                                  iso3166-territories territory)))
                    (gettext english "iso_3166-1"))
                  (G_ "No location"))))))))
     (installer-step
      (id 'codeset)
      (compute
       (lambda (result _)
         (let ((locales (filter-locales supported-locales result)))
           ;; Same as above but we now have a language and a territory to
           ;; narrow down the search of a locale.
           (break-on-locale-found locales)

           ;; Otherwise, choose a codeset.
           (let ((codesets (delete-duplicates (map locale-codeset locales))))
             (if (member "UTF-8" codesets)
                 "UTF-8"                          ;don't even ask
                 (run-codeset-page codesets)))))))
     (installer-step
      (id 'modifier)
      (compute
       (lambda (result _)
         (let ((locales (filter-locales supported-locales result)))
           ;; Same thing with a language, a territory and a codeset this time.
           (break-on-locale-found locales)

           ;; Otherwise, ask for a modifier.
           (run-modifier-page
            (delete-duplicates (map locale-modifier locales))
            (lambda (modifier)
              (or modifier (G_ "No modifier"))))))))))

  ;; If run-installer-steps returns locally, it means that the user had to go
  ;; through all steps (language, territory, codeset and modifier) to select a
  ;; locale. In that case, like if we exited by breaking to the installer
  ;; step, turn the result into a glibc locale string and return it.
  (result->locale-string
   supported-locales
   (run-installer-steps #:steps locale-steps)))
042ff890e5d306d0a2a736e891d'>doc: Add Guix Cookbook....* .gitignore: Update ignore list. * Makefile.am (assert-no-store-file-names): Exclude the cookbook. * bootstrap: Generate po files for cookbook translations. * doc/guix-cookbook.texi: New file. * doc/local.mk (info_TEXINFOS): Add it; add a rule to build cookbook translations. * po/doc/local.mk (DOC_COOKBOOK_PO_FILES): New variable. (EXTRA_DIST): Add cookbook pot file and po files. (doc-po-update-cookbook-%): New target. (doc-pot-update): Also update cookbook pot file. (doc-po-update): Also update cookbook po files. Ricardo Wurmus 2019-05-13doc: Add Russian translation....* doc/local.mk (info_TEXINFOS): Add guix.ru.texi. (TRANSLATED_INFO): Add {guix,contributing}.ru.texi. * po/doc/local.mk (DOC_PO_FILES): Add guix-manual.ru.po. * po/doc/guix-manual.ru.po: New file. Ludovic Courtès 2019-04-30build: 'guix-manual.*.po' no longer depends on 'guix-manual.pot'....That dependency was causing a failure when building from a fresh checkout since commit d60225d5caabfb6409e3277c0512cd4c0fa63d72 because 'guix-manual.pot' was no longer around and there's no rule to make it. This commit replaces the 'guix-manual.%.po' target by a phony target, 'doc-po-update-%', without any dependency. * po/doc/local.mk ($(srcdir)/po/doc/guix-manual.%.po): Rename to... (doc-po-update-%): ... this. Remove dependencies. Change how 'lang' is computed; compute $output and $input, and replace occurrences of $@ and $< with those. (doc-po-update): Adjust accordingly. Ludovic Courtès 2019-04-29maint: Mark 'doc-pot-update' and 'doc-po-update' as phony....* po/doc/local.mk (doc-pot-update, doc-pot-update): Mark as phony. Ludovic Courtès 2019-04-24doc: Add Simplified Chinese translation....* doc/local.mk (info_TEXINFOS): Add guix.zh_CN.texi. (TRANSLATED_INFO): Add guix.zh_CN.texi and contributing.zh_CN.texi. * po/doc/local.mk (DOC_PO_FILES): Add guix-manual.zh_CN.po. * doc/contributing.zh_CN.texi, doc/guix.zh_CN.texi: New files. Ludovic Courtès 2019-04-23doc: Add Spanish translation....* doc/local.mk (info_TEXINFOS): Add guix.es.texi. (TRANSLATED_INFO): Add guix.es.texi and contributing.es.texi. * po/doc/guix-manual.es.po: New file. * po/doc/local.mk: Add guix-manual.es.po. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Miguel Ángel Arruga Vivas 2018-11-28nls: Update documentation po and pot with `make dist`....* Makefile.am: dist-hook depends on doc-po-update. * po/doc/local.mk (doc-po-update): New target. Julien Lepiller 2018-11-01doc: Add German translation....* doc/contributing.de.texi: New file. * doc/guix.de.texi: New file * doc/local.mk (TRANSLATED_INFO): Add them. (info_TEXINFOS): Add guix.de.texi. * po/doc/guix-manual.de.po: New file. * po/doc/local.mk (EXTRA_DIST): Add it. * doc/guix.texi: Document the German translation. Julien Lepiller 2018-04-29build: Use only one domain for guix-manual....* Makefile.am (assert-no-store-file-names): Exclude guix-manual. * po/doc/guix.pot po/doc/contributing.pot: Merge into... * po/doc/guix-manual.pot: ...this. * po/doc/guix.fr.po po/doc/contributing.fr.po: Merge into... * po/doc/guix-manual.fr.po: ...this. * doc/local.mk: Replace old file names. * po/doc/local.mk: Replace old file names. Julien Lepiller 2018-04-19gnu: doc: Add French documentation....* doc/contributing.fr.texi: New file. * doc/guix.fr.texi: New file. * doc/local.mk (TRANSLATED_INFO): Add them. (info_TEXINFOS): Add guix.fr.texi. * po/doc/contributing.fr.po: New file. * po/doc/guix.fr.po: New file. * po/doc/local.mk (EXTRA_DIST): Add them. Julien Lepiller 2018-04-19gnu: doc: Allow documentation to be translated....* po/doc/contributing.pot: New file. * po/doc/guix.pot: New file. * po/doc/local.mk: New file. * Makefile.am: Include it. Add gettext command. Add silent rules for po4a. * configure.ac: Look for po4a-translate and po4a-updatepo. * doc/local.mk: Add rules to generate translated texi files. (TRANSLATED_INFO): New variable. (BUILT_SOURCES, EXTRA_DIST, MAINTAINERCLEANFILES): Add it. * .gitignore: Add generated files. Julien Lepiller