From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: [RFC] Introduce ox-i18n.el Date: Sat, 29 Jun 2013 16:06:29 +0200 Message-ID: <87fvw1ovtm.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34809) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsvrO-0007OG-EW for emacs-orgmode@gnu.org; Sat, 29 Jun 2013 10:10:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Usvn9-00009J-MX for emacs-orgmode@gnu.org; Sat, 29 Jun 2013 10:06:35 -0400 Received: from mail-we0-x231.google.com ([2a00:1450:400c:c03::231]:44069) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Usvn8-00008F-KV for emacs-orgmode@gnu.org; Sat, 29 Jun 2013 10:06:19 -0400 Received: by mail-we0-f177.google.com with SMTP id m19so1951748wev.8 for ; Sat, 29 Jun 2013 07:06:17 -0700 (PDT) Received: from selenimh ([91.224.148.150]) by mx.google.com with ESMTPSA id z6sm4150769wiv.11.2013.06.29.07.06.16 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 29 Jun 2013 07:06:17 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org Mode List --=-=-= Content-Type: text/plain Hello, I would like to move every variable and function related to internationalization (i.e smart quotes and translations) in a dedicated file ("ox-i18n.el") instead of "ox.el". Considering "ox.el" is 6k lines long, I think it can be a bit tedious to locate and modify internationalization entries. And since we are missing quite a few translations, every little bit can help. Patch follows. Any objection? Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0001-ox-Move-internationalization-variables-and-functions.patch Content-Transfer-Encoding: quoted-printable >From b78ba32530c8f45ad89fd4515a0f91bddb1b9017 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 29 Jun 2013 15:55:45 +0200 Subject: [PATCH] ox: Move internationalization variables and functions to a dedicated library * lisp/ox-i18n.el: New file. * lisp/ox.el (org-export-smart-quotes-alist, org-export-smart-quotes-regexps, org-export-dictionary): Remove variables. (org-export-activate-smart-quotes, org-export-translate): Remove functions. --- lisp/ox-i18n.el | 411 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ lisp/ox.el | 375 +-------------------------------------------------- 2 files changed, 412 insertions(+), 374 deletions(-) create mode 100644 lisp/ox-i18n.el diff --git a/lisp/ox-i18n.el b/lisp/ox-i18n.el new file mode 100644 index 0000000..8b7b102 --- /dev/null +++ b/lisp/ox-i18n.el @@ -0,0 +1,411 @@ +;;; ox-i18n.el --- Internationalization Bindings for Org Export Framework + +;; Copyright (C) 2013 Free Software Foundation, Inc. + +;; Author: Nicolas Goaziou +;; Keywords: outlines, hypermedia, calendar, wp + +;; This program 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. + +;; This program 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 this program. If not, see . + +;;; Commentary: + +;; This library introduces variables and functions for +;; internationalization of Org mode buffer during export. It +;; comprises two parts: "Translations" and "Smart Quotes". + +;;; Code: + + +;;; Translations +;; +;; `org-export-translate' translates a string according to language +;; specified by LANGUAGE keyword or `org-export-language-setup' +;; variable and a specified charset. `org-export-dictionary' contains +;; the dictionary used for the translation. + +(defconst org-export-dictionary + '(("%e %n: %c" + ("fr" :default "%e %n : %c" :html "%e %n : %c")) + ("Author" + ("ca" :default "Autor") + ("cs" :default "Autor") + ("da" :default "Ophavsmand") + ("de" :default "Autor") + ("eo" :html "Aŭtoro") + ("es" :default "Autor") + ("fi" :html "Tekijä") + ("fr" :default "Auteur") + ("hu" :default "Szerzõ") + ("is" :html "Höfundur") + ("it" :default "Autore") + ("ja" :html "著者" :utf-8 "=E8=91=97=E8=80=85") + ("nl" :default "Auteur") + ("no" :default "Forfatter") + ("nb" :default "Forfatter") + ("nn" :default "Forfattar") + ("pl" :default "Autor") + ("ru" :html "Автор" :utf-8 "=D0=90=D0= =B2=D1=82=D0=BE=D1=80") + ("sv" :html "Författare") + ("uk" :html "Автор" :utf-8 "=D0=90=D0= =B2=D1=82=D0=BE=D1=80") + ("zh-CN" :html "作者" :utf-8 "=E4=BD=9C=E8=80=85") + ("zh-TW" :html "作者" :utf-8 "=E4=BD=9C=E8=80=85")) + ("Date" + ("ca" :default "Data") + ("cs" :default "Datum") + ("da" :default "Dato") + ("de" :default "Datum") + ("eo" :default "Dato") + ("es" :default "Fecha") + ("fi" :html "Päivämäärä") + ("hu" :html "Dátum") + ("is" :default "Dagsetning") + ("it" :default "Data") + ("ja" :html "日付" :utf-8 "=E6=97=A5=E4=BB=98") + ("nl" :default "Datum") + ("no" :default "Dato") + ("nb" :default "Dato") + ("nn" :default "Dato") + ("pl" :default "Data") + ("ru" :html "Дата" :utf-8 "=D0=94=D0=B0=D1=82= =D0=B0") + ("sv" :default "Datum") + ("uk" :html "Дата" :utf-8 "=D0=94=D0=B0=D1=82= =D0=B0") + ("zh-CN" :html "日期" :utf-8 "=E6=97=A5=E6=9C=9F") + ("zh-TW" :html "日期" :utf-8 "=E6=97=A5=E6=9C=9F")) + ("Equation" + ("de" :default "Gleichung") + ("es" :html "Ecuación" :default "Ecuaci=C3=B3n") + ("fr" :ascii "Equation" :default "=C3=89quation")) + ("Figure" + ("de" :default "Abbildung") + ("es" :default "Figura") + ("ja" :html "図" :utf-8 "=E5=9B=B3")) + ("Figure %d:" + ("de" :default "Abbildung %d:") + ("es" :default "Figura %d:") + ("fr" :default "Figure %d :" :html "Figure %d :") + ("ja" :html "図%d:" :utf-8 "=E5=9B=B3%d:")) + ("Footnotes" + ("ca" :html "Peus de pàgina") + ("cs" :default "Pozn\xe1mky pod carou") + ("da" :default "Fodnoter") + ("de" :html "Fußnoten" :default "Fu=C3=9Fnoten") + ("eo" :default "Piednotoj") + ("es" :html "Nota al pie de página" :default "Nota al pie de p= =C3=A1gina") + ("fi" :default "Alaviitteet") + ("fr" :default "Notes de bas de page") + ("hu" :html "Lábjegyzet") + ("is" :html "Aftanmálsgreinar") + ("it" :html "Note a piè di pagina") + ("ja" :html "脚注" :utf-8 "=E8=84=9A=E6=B3=A8") + ("nl" :default "Voetnoten") + ("no" :default "Fotnoter") + ("nb" :default "Fotnoter") + ("nn" :default "Fotnotar") + ("pl" :default "Przypis") + ("ru" :html "Сноски" :utf-8 "=D0= =A1=D0=BD=D0=BE=D1=81=D0=BA=D0=B8") + ("sv" :default "Fotnoter") + ("uk" :html "Примітки" + :utf-8 "=D0=9F=D1=80=D0=B8=D0=BC=D1=96=D1=82=D0=BA=D0=B8") + ("zh-CN" :html "脚注" :utf-8 "=E8=84=9A=E6=B3=A8") + ("zh-TW" :html "腳註" :utf-8 "=E8=85=B3=E8=A8=BB")) + ("List of Listings" + ("de" :default "Programmauflistungsverzeichnis") + ("es" :default "Indice de Listados de programas") + ("fr" :default "Liste des programmes")) + ("List of Tables" + ("de" :default "Tabellenverzeichnis") + ("es" :default "Indice de tablas") + ("fr" :default "Liste des tableaux")) + ("Listing %d:" + ("de" :default "Programmlisting %d") + ("es" :default "Listado de programa %d") + ("fr" :default "Programme %d :" :html "Programme %d :")) + ("See section %s" + ("de" :default "siehe Abschnitt %s") + ("es" :default "vea seccion %s") + ("fr" :default "cf. section %s")) + ("Table" + ("de" :default "Tabelle") + ("es" :default "Tabla") + ("fr" :default "Tableau") + ("ja" :html "表" :utf-8 "=E8=A1=A8")) + ("Table %d:" + ("de" :default "Tabelle %d") + ("es" :default "Tabla %d") + ("fr" :default "Tableau %d :") + ("ja" :html "表%d:" :utf-8 "=E8=A1=A8%d:")) + ("Table of Contents" + ("ca" :html "Índex") + ("cs" :default "Obsah") + ("da" :default "Indhold") + ("de" :default "Inhaltsverzeichnis") + ("eo" :default "Enhavo") + ("es" :html "Índice") + ("fi" :html "Sisällysluettelo") + ("fr" :ascii "Sommaire" :default "Table des mati=C3=A8res") + ("hu" :html "Tartalomjegyzék") + ("is" :default "Efnisyfirlit") + ("it" :default "Indice") + ("ja" :html "目次" :utf-8 "=E7=9B=AE=E6=AC=A1") + ("nl" :default "Inhoudsopgave") + ("no" :default "Innhold") + ("nb" :default "Innhold") + ("nn" :default "Innhald") + ("pl" :html "Spis treści") + ("ru" :html "Содержан= ие" + :utf-8 "=D0=A1=D0=BE=D0=B4=D0=B5=D1=80=D0=B6=D0=B0=D0=BD=D0=B8=D0=B5= ") + ("sv" :html "Innehåll") + ("uk" :html "Зміст" :utf-8 "=D0=97=D0= =BC=D1=96=D1=81=D1=82") + ("zh-CN" :html "目录" :utf-8 "=E7=9B=AE=E5=BD=95") + ("zh-TW" :html "目錄" :utf-8 "=E7=9B=AE=E9=8C=84")) + ("Unknown reference" + ("de" :default "Unbekannter Verweis") + ("es" :default "referencia desconocida") + ("fr" :ascii "Destination inconnue" :default "R=C3=A9f=C3=A9rence inc= onnue"))) + "Dictionary for export engine. + +Alist whose CAR is the string to translate and CDR is an alist +whose CAR is the language string and CDR is a plist whose +properties are possible charsets and values translated terms. + +It is used as a database for `org-export-translate'. Since this +function returns the string as-is if no translation was found, +the variable only needs to record values different from the +entry.") + +(defun org-export-translate (s encoding info) + "Translate string S according to language specification. + +ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1' +and `:utf-8'. INFO is a plist used as a communication channel. + +Translation depends on `:language' property. Return the +translated string. If no translation is found, try to fall back +to `:default' encoding. If it fails, return S." + (let* ((lang (plist-get info :language)) + (translations (cdr (assoc lang + (cdr (assoc s org-export-dictionary)))))) + (or (plist-get translations encoding) + (plist-get translations :default) + s))) + + + +;;; Smart Quotes +;; +;; The main function for the smart quotes sub-system is +;; `org-export-activate-smart-quotes', which replaces every quote in +;; a given string from the parse tree with its "smart" counterpart. +;; +;; Dictionary for smart quotes is stored in +;; `org-export-smart-quotes-alist'. +;; +;; Internally, regexps matching potential smart quotes (checks at +;; string boundaries are also necessary) are defined in +;; `org-export-smart-quotes-regexps'. + +(defconst org-export-smart-quotes-alist + '(("de" + (opening-double-quote :utf-8 "=E2=80=9E" :html "„" :latex "\"`" + :texinfo "@quotedblbase{}") + (closing-double-quote :utf-8 "=E2=80=9C" :html "“" :latex "\"'" + :texinfo "@quotedblleft{}") + (opening-single-quote :utf-8 "=E2=80=9A" :html "‚" :latex "\\gl= q{}" + :texinfo "@quotesinglbase{}") + (closing-single-quote :utf-8 "=E2=80=98" :html "‘" :latex "\\gr= q{}" + :texinfo "@quoteleft{}") + (apostrophe :utf-8 "=E2=80=99" :html "’")) + ("en" + (opening-double-quote :utf-8 "=E2=80=9C" :html "“" :latex "``" = :texinfo "``") + (closing-double-quote :utf-8 "=E2=80=9D" :html "”" :latex "''" = :texinfo "''") + (opening-single-quote :utf-8 "=E2=80=98" :html "‘" :latex "`" := texinfo "`") + (closing-single-quote :utf-8 "=E2=80=99" :html "’" :latex "'" := texinfo "'") + (apostrophe :utf-8 "=E2=80=99" :html "’")) + ("es" + (opening-double-quote :utf-8 "=C2=AB" :html "«" :latex "\\guill= emotleft{}" + :texinfo "@guillemetleft{}") + (closing-double-quote :utf-8 "=C2=BB" :html "»" :latex "\\guill= emotright{}" + :texinfo "@guillemetright{}") + (opening-single-quote :utf-8 "=E2=80=9C" :html "“" :latex "``" = :texinfo "``") + (closing-single-quote :utf-8 "=E2=80=9D" :html "”" :latex "''" = :texinfo "''") + (apostrophe :utf-8 "=E2=80=99" :html "’")) + ("fr" + (opening-double-quote :utf-8 "=C2=AB=C2=A0" :html "« " :la= tex "\\og " + :texinfo "@guillemetleft{}@tie{}") + (closing-double-quote :utf-8 "=C2=A0=C2=BB" :html " »" :la= tex "\\fg{}" + :texinfo "@tie{}@guillemetright{}") + (opening-single-quote :utf-8 "=C2=AB=C2=A0" :html "« " :la= tex "\\og " + :texinfo "@guillemetleft{}@tie{}") + (closing-single-quote :utf-8 "=C2=A0=C2=BB" :html " »" :la= tex "\\fg{}" + :texinfo "@tie{}@guillemetright{}") + (apostrophe :utf-8 "=E2=80=99" :html "’"))) + "Smart quotes translations. + +Alist whose CAR is a language string and CDR is an alist with +quote type as key and a plist associating various encodings to +their translation as value. + +A quote type can be any symbol among `opening-double-quote', +`closing-double-quote', `opening-single-quote', +`closing-single-quote' and `apostrophe'. + +Valid encodings include `:utf-8', `:html', `:latex' and +`:texinfo'. + +If no translation is found, the quote character is left as-is.") + +(defconst org-export-smart-quotes-regexps + (list + ;; Possible opening quote at beginning of string. + "\\`\\([\"']\\)\\(\\w\\|\\s.\\|\\s_\\)" + ;; Possible closing quote at beginning of string. + "\\`\\([\"']\\)\\(\\s-\\|\\s)\\|\\s.\\)" + ;; Possible apostrophe at beginning of string. + "\\`\\('\\)\\S-" + ;; Opening single and double quotes. + "\\(?:\\s-\\|\\s(\\)\\([\"']\\)\\(?:\\w\\|\\s.\\|\\s_\\)" + ;; Closing single and double quotes. + "\\(?:\\w\\|\\s.\\|\\s_\\)\\([\"']\\)\\(?:\\s-\\|\\s)\\|\\s.\\)" + ;; Apostrophe. + "\\S-\\('\\)\\S-" + ;; Possible opening quote at end of string. + "\\(?:\\s-\\|\\s(\\)\\([\"']\\)\\'" + ;; Possible closing quote at end of string. + "\\(?:\\w\\|\\s.\\|\\s_\\)\\([\"']\\)\\'" + ;; Possible apostrophe at end of string. + "\\S-\\('\\)\\'") + "List of regexps matching a quote or an apostrophe. +In every regexp, quote or apostrophe matched is put in group 1.") + +(declare-function org-export-get-next-element "org-export" (blob info &opt= ional n)) +(declare-function org-export-get-previous-element "org-export" (blob info = &optional n)) +(defun org-export-activate-smart-quotes (s encoding info &optional origina= l) + "Replace regular quotes with \"smart\" quotes in string S. + +ENCODING is a symbol among `:html', `:latex', `:texinfo' and +`:utf-8'. INFO is a plist used as a communication channel. + +The function has to retrieve information about string +surroundings in parse tree. It can only happen with an +unmodified string. Thus, if S has already been through another +process, a non-nil ORIGINAL optional argument will provide that +original string. + +Return the new string." + (if (equal s "") "" + (let* ((prev (org-export-get-previous-element (or original s) info)) + ;; Try to be flexible when computing number of blanks + ;; before object. The previous object may be a string + ;; introduced by the back-end and not completely parsed. + (pre-blank (and prev + (or (org-element-property :post-blank prev) + ;; A string with missing `:post-blank' + ;; property. + (and (stringp prev) + (string-match " *\\'" prev) + (length (match-string 0 prev))) + ;; Fallback value. + 0))) + (next (org-export-get-next-element (or original s) info)) + (get-smart-quote + (lambda (q type) + ;; Return smart quote associated to a give quote Q, as + ;; a string. TYPE is a symbol among `open', `close' and + ;; `apostrophe'. + (let ((key (case type + (apostrophe 'apostrophe) + (open (if (equal "'" q) 'opening-single-quote + 'opening-double-quote)) + (otherwise (if (equal "'" q) 'closing-single-quote + 'closing-double-quote))))) + (or (plist-get + (cdr (assq key + (cdr (assoc (plist-get info :language) + org-export-smart-quotes-alist)))) + encoding) + q))))) + (if (or (equal "\"" s) (equal "'" s)) + ;; Only a quote: no regexp can match. We have to check both + ;; sides and decide what to do. + (cond ((and (not prev) (not next)) s) + ((not prev) (funcall get-smart-quote s 'open)) + ((and (not next) (zerop pre-blank)) + (funcall get-smart-quote s 'close)) + ((not next) s) + ((zerop pre-blank) (funcall get-smart-quote s 'apostrophe)) + (t (funcall get-smart-quote 'open))) + ;; 1. Replace quote character at the beginning of S. + (cond + ;; Apostrophe? + ((and prev (zerop pre-blank) + (string-match (nth 2 org-export-smart-quotes-regexps) s)) + (setq s (replace-match + (funcall get-smart-quote (match-string 1 s) 'apostrophe) + nil t s 1))) + ;; Closing quote? + ((and prev (zerop pre-blank) + (string-match (nth 1 org-export-smart-quotes-regexps) s)) + (setq s (replace-match + (funcall get-smart-quote (match-string 1 s) 'close) + nil t s 1))) + ;; Opening quote? + ((and (or (not prev) (> pre-blank 0)) + (string-match (nth 0 org-export-smart-quotes-regexps) s)) + (setq s (replace-match + (funcall get-smart-quote (match-string 1 s) 'open) + nil t s 1)))) + ;; 2. Replace quotes in the middle of the string. + (setq s (replace-regexp-in-string + ;; Opening quotes. + (nth 3 org-export-smart-quotes-regexps) + (lambda (text) + (funcall get-smart-quote (match-string 1 text) 'open)) + s nil t 1)) + (setq s (replace-regexp-in-string + ;; Closing quotes. + (nth 4 org-export-smart-quotes-regexps) + (lambda (text) + (funcall get-smart-quote (match-string 1 text) 'close)) + s nil t 1)) + (setq s (replace-regexp-in-string + ;; Apostrophes. + (nth 5 org-export-smart-quotes-regexps) + (lambda (text) + (funcall get-smart-quote (match-string 1 text) 'apostrophe)) + s nil t 1)) + ;; 3. Replace quote character at the end of S. + (cond + ;; Apostrophe? + ((and next (string-match (nth 8 org-export-smart-quotes-regexps) s)) + (setq s (replace-match + (funcall get-smart-quote (match-string 1 s) 'apostrophe) + nil t s 1))) + ;; Closing quote? + ((and (not next) + (string-match (nth 7 org-export-smart-quotes-regexps) s)) + (setq s (replace-match + (funcall get-smart-quote (match-string 1 s) 'close) + nil t s 1))) + ;; Opening quote? + ((and next (string-match (nth 6 org-export-smart-quotes-regexps) s)) + (setq s (replace-match + (funcall get-smart-quote (match-string 1 s) 'open) + nil t s 1)))) + ;; Return string with smart quotes. + s)))) + + + +(provide 'ox-i18n) +;;; ox-i18n.el ends here diff --git a/lisp/ox.el b/lisp/ox.el index 08fbddd..ea4f7c1 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -80,6 +80,7 @@ (require 'org-element) (require 'org-macro) (require 'ob-exp) +(require 'ox-i18n) =20 (declare-function org-publish "ox-publish" (project &optional force async)) (declare-function org-publish-all "ox-publish" (&optional force async)) @@ -4878,207 +4879,6 @@ Return a list of src-block elements with a caption." (org-export-collect-elements 'src-block info)) =20 =20 -;;;; Smart Quotes -;; -;; The main function for the smart quotes sub-system is -;; `org-export-activate-smart-quotes', which replaces every quote in -;; a given string from the parse tree with its "smart" counterpart. -;; -;; Dictionary for smart quotes is stored in -;; `org-export-smart-quotes-alist'. -;; -;; Internally, regexps matching potential smart quotes (checks at -;; string boundaries are also necessary) are defined in -;; `org-export-smart-quotes-regexps'. - -(defconst org-export-smart-quotes-alist - '(("de" - (opening-double-quote :utf-8 "=E2=80=9E" :html "„" :latex "\"`" - :texinfo "@quotedblbase{}") - (closing-double-quote :utf-8 "=E2=80=9C" :html "“" :latex "\"'" - :texinfo "@quotedblleft{}") - (opening-single-quote :utf-8 "=E2=80=9A" :html "‚" :latex "\\gl= q{}" - :texinfo "@quotesinglbase{}") - (closing-single-quote :utf-8 "=E2=80=98" :html "‘" :latex "\\gr= q{}" - :texinfo "@quoteleft{}") - (apostrophe :utf-8 "=E2=80=99" :html "’")) - ("en" - (opening-double-quote :utf-8 "=E2=80=9C" :html "“" :latex "``" = :texinfo "``") - (closing-double-quote :utf-8 "=E2=80=9D" :html "”" :latex "''" = :texinfo "''") - (opening-single-quote :utf-8 "=E2=80=98" :html "‘" :latex "`" := texinfo "`") - (closing-single-quote :utf-8 "=E2=80=99" :html "’" :latex "'" := texinfo "'") - (apostrophe :utf-8 "=E2=80=99" :html "’")) - ("es" - (opening-double-quote :utf-8 "=C2=AB" :html "«" :latex "\\guill= emotleft{}" - :texinfo "@guillemetleft{}") - (closing-double-quote :utf-8 "=C2=BB" :html "»" :latex "\\guill= emotright{}" - :texinfo "@guillemetright{}") - (opening-single-quote :utf-8 "=E2=80=9C" :html "“" :latex "``" = :texinfo "``") - (closing-single-quote :utf-8 "=E2=80=9D" :html "”" :latex "''" = :texinfo "''") - (apostrophe :utf-8 "=E2=80=99" :html "’")) - ("fr" - (opening-double-quote :utf-8 "=C2=AB=C2=A0" :html "« " :la= tex "\\og " - :texinfo "@guillemetleft{}@tie{}") - (closing-double-quote :utf-8 "=C2=A0=C2=BB" :html " »" :la= tex "\\fg{}" - :texinfo "@tie{}@guillemetright{}") - (opening-single-quote :utf-8 "=C2=AB=C2=A0" :html "« " :la= tex "\\og " - :texinfo "@guillemetleft{}@tie{}") - (closing-single-quote :utf-8 "=C2=A0=C2=BB" :html " »" :la= tex "\\fg{}" - :texinfo "@tie{}@guillemetright{}") - (apostrophe :utf-8 "=E2=80=99" :html "’"))) - "Smart quotes translations. - -Alist whose CAR is a language string and CDR is an alist with -quote type as key and a plist associating various encodings to -their translation as value. - -A quote type can be any symbol among `opening-double-quote', -`closing-double-quote', `opening-single-quote', -`closing-single-quote' and `apostrophe'. - -Valid encodings include `:utf-8', `:html', `:latex' and -`:texinfo'. - -If no translation is found, the quote character is left as-is.") - -(defconst org-export-smart-quotes-regexps - (list - ;; Possible opening quote at beginning of string. - "\\`\\([\"']\\)\\(\\w\\|\\s.\\|\\s_\\)" - ;; Possible closing quote at beginning of string. - "\\`\\([\"']\\)\\(\\s-\\|\\s)\\|\\s.\\)" - ;; Possible apostrophe at beginning of string. - "\\`\\('\\)\\S-" - ;; Opening single and double quotes. - "\\(?:\\s-\\|\\s(\\)\\([\"']\\)\\(?:\\w\\|\\s.\\|\\s_\\)" - ;; Closing single and double quotes. - "\\(?:\\w\\|\\s.\\|\\s_\\)\\([\"']\\)\\(?:\\s-\\|\\s)\\|\\s.\\)" - ;; Apostrophe. - "\\S-\\('\\)\\S-" - ;; Possible opening quote at end of string. - "\\(?:\\s-\\|\\s(\\)\\([\"']\\)\\'" - ;; Possible closing quote at end of string. - "\\(?:\\w\\|\\s.\\|\\s_\\)\\([\"']\\)\\'" - ;; Possible apostrophe at end of string. - "\\S-\\('\\)\\'") - "List of regexps matching a quote or an apostrophe. -In every regexp, quote or apostrophe matched is put in group 1.") - -(defun org-export-activate-smart-quotes (s encoding info &optional origina= l) - "Replace regular quotes with \"smart\" quotes in string S. - -ENCODING is a symbol among `:html', `:latex', `:texinfo' and -`:utf-8'. INFO is a plist used as a communication channel. - -The function has to retrieve information about string -surroundings in parse tree. It can only happen with an -unmodified string. Thus, if S has already been through another -process, a non-nil ORIGINAL optional argument will provide that -original string. - -Return the new string." - (if (equal s "") "" - (let* ((prev (org-export-get-previous-element (or original s) info)) - ;; Try to be flexible when computing number of blanks - ;; before object. The previous object may be a string - ;; introduced by the back-end and not completely parsed. - (pre-blank (and prev - (or (org-element-property :post-blank prev) - ;; A string with missing `:post-blank' - ;; property. - (and (stringp prev) - (string-match " *\\'" prev) - (length (match-string 0 prev))) - ;; Fallback value. - 0))) - (next (org-export-get-next-element (or original s) info)) - (get-smart-quote - (lambda (q type) - ;; Return smart quote associated to a give quote Q, as - ;; a string. TYPE is a symbol among `open', `close' and - ;; `apostrophe'. - (let ((key (case type - (apostrophe 'apostrophe) - (open (if (equal "'" q) 'opening-single-quote - 'opening-double-quote)) - (otherwise (if (equal "'" q) 'closing-single-quote - 'closing-double-quote))))) - (or (plist-get - (cdr (assq key - (cdr (assoc (plist-get info :language) - org-export-smart-quotes-alist)))) - encoding) - q))))) - (if (or (equal "\"" s) (equal "'" s)) - ;; Only a quote: no regexp can match. We have to check both - ;; sides and decide what to do. - (cond ((and (not prev) (not next)) s) - ((not prev) (funcall get-smart-quote s 'open)) - ((and (not next) (zerop pre-blank)) - (funcall get-smart-quote s 'close)) - ((not next) s) - ((zerop pre-blank) (funcall get-smart-quote s 'apostrophe)) - (t (funcall get-smart-quote 'open))) - ;; 1. Replace quote character at the beginning of S. - (cond - ;; Apostrophe? - ((and prev (zerop pre-blank) - (string-match (nth 2 org-export-smart-quotes-regexps) s)) - (setq s (replace-match - (funcall get-smart-quote (match-string 1 s) 'apostrophe) - nil t s 1))) - ;; Closing quote? - ((and prev (zerop pre-blank) - (string-match (nth 1 org-export-smart-quotes-regexps) s)) - (setq s (replace-match - (funcall get-smart-quote (match-string 1 s) 'close) - nil t s 1))) - ;; Opening quote? - ((and (or (not prev) (> pre-blank 0)) - (string-match (nth 0 org-export-smart-quotes-regexps) s)) - (setq s (replace-match - (funcall get-smart-quote (match-string 1 s) 'open) - nil t s 1)))) - ;; 2. Replace quotes in the middle of the string. - (setq s (replace-regexp-in-string - ;; Opening quotes. - (nth 3 org-export-smart-quotes-regexps) - (lambda (text) - (funcall get-smart-quote (match-string 1 text) 'open)) - s nil t 1)) - (setq s (replace-regexp-in-string - ;; Closing quotes. - (nth 4 org-export-smart-quotes-regexps) - (lambda (text) - (funcall get-smart-quote (match-string 1 text) 'close)) - s nil t 1)) - (setq s (replace-regexp-in-string - ;; Apostrophes. - (nth 5 org-export-smart-quotes-regexps) - (lambda (text) - (funcall get-smart-quote (match-string 1 text) 'apostrophe)) - s nil t 1)) - ;; 3. Replace quote character at the end of S. - (cond - ;; Apostrophe? - ((and next (string-match (nth 8 org-export-smart-quotes-regexps) s)) - (setq s (replace-match - (funcall get-smart-quote (match-string 1 s) 'apostrophe) - nil t s 1))) - ;; Closing quote? - ((and (not next) - (string-match (nth 7 org-export-smart-quotes-regexps) s)) - (setq s (replace-match - (funcall get-smart-quote (match-string 1 s) 'close) - nil t s 1))) - ;; Opening quote? - ((and next (string-match (nth 6 org-export-smart-quotes-regexps) s)) - (setq s (replace-match - (funcall get-smart-quote (match-string 1 s) 'open) - nil t s 1)))) - ;; Return string with smart quotes. - s)))) - ;;;; Topology ;; ;; Here are various functions to retrieve information about the @@ -5206,179 +5006,6 @@ them." (nreverse next)))) =20 =20 -;;;; Translation -;; -;; `org-export-translate' translates a string according to language -;; specified by LANGUAGE keyword or `org-export-language-setup' -;; variable and a specified charset. `org-export-dictionary' contains -;; the dictionary used for the translation. - -(defconst org-export-dictionary - '(("%e %n: %c" - ("fr" :default "%e %n : %c" :html "%e %n : %c")) - ("Author" - ("ca" :default "Autor") - ("cs" :default "Autor") - ("da" :default "Ophavsmand") - ("de" :default "Autor") - ("eo" :html "Aŭtoro") - ("es" :default "Autor") - ("fi" :html "Tekijä") - ("fr" :default "Auteur") - ("hu" :default "Szerzõ") - ("is" :html "Höfundur") - ("it" :default "Autore") - ("ja" :html "著者" :utf-8 "=E8=91=97=E8=80=85") - ("nl" :default "Auteur") - ("no" :default "Forfatter") - ("nb" :default "Forfatter") - ("nn" :default "Forfattar") - ("pl" :default "Autor") - ("ru" :html "Автор" :utf-8 "=D0=90=D0= =B2=D1=82=D0=BE=D1=80") - ("sv" :html "Författare") - ("uk" :html "Автор" :utf-8 "=D0=90=D0= =B2=D1=82=D0=BE=D1=80") - ("zh-CN" :html "作者" :utf-8 "=E4=BD=9C=E8=80=85") - ("zh-TW" :html "作者" :utf-8 "=E4=BD=9C=E8=80=85")) - ("Date" - ("ca" :default "Data") - ("cs" :default "Datum") - ("da" :default "Dato") - ("de" :default "Datum") - ("eo" :default "Dato") - ("es" :default "Fecha") - ("fi" :html "Päivämäärä") - ("hu" :html "Dátum") - ("is" :default "Dagsetning") - ("it" :default "Data") - ("ja" :html "日付" :utf-8 "=E6=97=A5=E4=BB=98") - ("nl" :default "Datum") - ("no" :default "Dato") - ("nb" :default "Dato") - ("nn" :default "Dato") - ("pl" :default "Data") - ("ru" :html "Дата" :utf-8 "=D0=94=D0=B0=D1=82= =D0=B0") - ("sv" :default "Datum") - ("uk" :html "Дата" :utf-8 "=D0=94=D0=B0=D1=82= =D0=B0") - ("zh-CN" :html "日期" :utf-8 "=E6=97=A5=E6=9C=9F") - ("zh-TW" :html "日期" :utf-8 "=E6=97=A5=E6=9C=9F")) - ("Equation" - ("de" :default "Gleichung") - ("es" :html "Ecuación" :default "Ecuaci=C3=B3n") - ("fr" :ascii "Equation" :default "=C3=89quation")) - ("Figure" - ("de" :default "Abbildung") - ("es" :default "Figura") - ("ja" :html "図" :utf-8 "=E5=9B=B3")) - ("Figure %d:" - ("de" :default "Abbildung %d:") - ("es" :default "Figura %d:") - ("fr" :default "Figure %d :" :html "Figure %d :") - ("ja" :html "図%d:" :utf-8 "=E5=9B=B3%d:")) - ("Footnotes" - ("ca" :html "Peus de pàgina") - ("cs" :default "Pozn\xe1mky pod carou") - ("da" :default "Fodnoter") - ("de" :html "Fußnoten" :default "Fu=C3=9Fnoten") - ("eo" :default "Piednotoj") - ("es" :html "Nota al pie de página" :default "Nota al pie de p= =C3=A1gina") - ("fi" :default "Alaviitteet") - ("fr" :default "Notes de bas de page") - ("hu" :html "Lábjegyzet") - ("is" :html "Aftanmálsgreinar") - ("it" :html "Note a piè di pagina") - ("ja" :html "脚注" :utf-8 "=E8=84=9A=E6=B3=A8") - ("nl" :default "Voetnoten") - ("no" :default "Fotnoter") - ("nb" :default "Fotnoter") - ("nn" :default "Fotnotar") - ("pl" :default "Przypis") - ("ru" :html "Сноски" :utf-8 "=D0= =A1=D0=BD=D0=BE=D1=81=D0=BA=D0=B8") - ("sv" :default "Fotnoter") - ("uk" :html "Примітки" - :utf-8 "=D0=9F=D1=80=D0=B8=D0=BC=D1=96=D1=82=D0=BA=D0=B8") - ("zh-CN" :html "脚注" :utf-8 "=E8=84=9A=E6=B3=A8") - ("zh-TW" :html "腳註" :utf-8 "=E8=85=B3=E8=A8=BB")) - ("List of Listings" - ("de" :default "Programmauflistungsverzeichnis") - ("es" :default "Indice de Listados de programas") - ("fr" :default "Liste des programmes")) - ("List of Tables" - ("de" :default "Tabellenverzeichnis") - ("es" :default "Indice de tablas") - ("fr" :default "Liste des tableaux")) - ("Listing %d:" - ("de" :default "Programmlisting %d") - ("es" :default "Listado de programa %d") - ("fr" :default "Programme %d :" :html "Programme %d :")) - ("See section %s" - ("de" :default "siehe Abschnitt %s") - ("es" :default "vea seccion %s") - ("fr" :default "cf. section %s")) - ("Table" - ("de" :default "Tabelle") - ("es" :default "Tabla") - ("fr" :default "Tableau") - ("ja" :html "表" :utf-8 "=E8=A1=A8")) - ("Table %d:" - ("de" :default "Tabelle %d") - ("es" :default "Tabla %d") - ("fr" :default "Tableau %d :") - ("ja" :html "表%d:" :utf-8 "=E8=A1=A8%d:")) - ("Table of Contents" - ("ca" :html "Índex") - ("cs" :default "Obsah") - ("da" :default "Indhold") - ("de" :default "Inhaltsverzeichnis") - ("eo" :default "Enhavo") - ("es" :html "Índice") - ("fi" :html "Sisällysluettelo") - ("fr" :ascii "Sommaire" :default "Table des mati=C3=A8res") - ("hu" :html "Tartalomjegyzék") - ("is" :default "Efnisyfirlit") - ("it" :default "Indice") - ("ja" :html "目次" :utf-8 "=E7=9B=AE=E6=AC=A1") - ("nl" :default "Inhoudsopgave") - ("no" :default "Innhold") - ("nb" :default "Innhold") - ("nn" :default "Innhald") - ("pl" :html "Spis treści") - ("ru" :html "Содержан= ие" - :utf-8 "=D0=A1=D0=BE=D0=B4=D0=B5=D1=80=D0=B6=D0=B0=D0=BD=D0=B8=D0=B5= ") - ("sv" :html "Innehåll") - ("uk" :html "Зміст" :utf-8 "=D0=97=D0= =BC=D1=96=D1=81=D1=82") - ("zh-CN" :html "目录" :utf-8 "=E7=9B=AE=E5=BD=95") - ("zh-TW" :html "目錄" :utf-8 "=E7=9B=AE=E9=8C=84")) - ("Unknown reference" - ("de" :default "Unbekannter Verweis") - ("es" :default "referencia desconocida") - ("fr" :ascii "Destination inconnue" :default "R=C3=A9f=C3=A9rence inc= onnue"))) - "Dictionary for export engine. - -Alist whose CAR is the string to translate and CDR is an alist -whose CAR is the language string and CDR is a plist whose -properties are possible charsets and values translated terms. - -It is used as a database for `org-export-translate'. Since this -function returns the string as-is if no translation was found, -the variable only needs to record values different from the -entry.") - -(defun org-export-translate (s encoding info) - "Translate string S according to language specification. - -ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1' -and `:utf-8'. INFO is a plist used as a communication channel. - -Translation depends on `:language' property. Return the -translated string. If no translation is found, try to fall back -to `:default' encoding. If it fails, return S." - (let* ((lang (plist-get info :language)) - (translations (cdr (assoc lang - (cdr (assoc s org-export-dictionary)))))) - (or (plist-get translations encoding) - (plist-get translations :default) - s))) - =20 ;;; Asynchronous Export --=20 1.8.3.1 --=-=-=--