emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob 8b7b102ad15e11aeeff49110dd6c76376c30c802 16089 bytes (raw)
name: lisp/ox-i18n.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
 
;;; ox-i18n.el --- Internationalization Bindings for Org Export Framework

;; Copyright (C) 2013  Free Software Foundation, Inc.

;; Author: Nicolas Goaziou <n.goaziou gmail dot com>
;; 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 <http://www.gnu.org/licenses/>.

;;; Commentary:

;; This library introduces variables and functions for
;; internationalization of Org mode buffer during export.  It
;; comprises two parts: "Translations" and "Smart Quotes".

;;; Code:

\f
;;; 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&nbsp;%n&nbsp;: %c"))
    ("Author"
     ("ca" :default "Autor")
     ("cs" :default "Autor")
     ("da" :default "Ophavsmand")
     ("de" :default "Autor")
     ("eo" :html "A&#365;toro")
     ("es" :default "Autor")
     ("fi" :html "Tekij&auml;")
     ("fr" :default "Auteur")
     ("hu" :default "Szerz&otilde;")
     ("is" :html "H&ouml;fundur")
     ("it" :default "Autore")
     ("ja" :html "&#33879;&#32773;" :utf-8 "著者")
     ("nl" :default "Auteur")
     ("no" :default "Forfatter")
     ("nb" :default "Forfatter")
     ("nn" :default "Forfattar")
     ("pl" :default "Autor")
     ("ru" :html "&#1040;&#1074;&#1090;&#1086;&#1088;" :utf-8 "Автор")
     ("sv" :html "F&ouml;rfattare")
     ("uk" :html "&#1040;&#1074;&#1090;&#1086;&#1088;" :utf-8 "Автор")
     ("zh-CN" :html "&#20316;&#32773;" :utf-8 "作者")
     ("zh-TW" :html "&#20316;&#32773;" :utf-8 "作者"))
    ("Date"
     ("ca" :default "Data")
     ("cs" :default "Datum")
     ("da" :default "Dato")
     ("de" :default "Datum")
     ("eo" :default "Dato")
     ("es" :default "Fecha")
     ("fi" :html "P&auml;iv&auml;m&auml;&auml;r&auml;")
     ("hu" :html "D&aacute;tum")
     ("is" :default "Dagsetning")
     ("it" :default "Data")
     ("ja" :html "&#26085;&#20184;" :utf-8 "日付")
     ("nl" :default "Datum")
     ("no" :default "Dato")
     ("nb" :default "Dato")
     ("nn" :default "Dato")
     ("pl" :default "Data")
     ("ru" :html "&#1044;&#1072;&#1090;&#1072;" :utf-8 "Дата")
     ("sv" :default "Datum")
     ("uk" :html "&#1044;&#1072;&#1090;&#1072;" :utf-8 "Дата")
     ("zh-CN" :html "&#26085;&#26399;" :utf-8 "日期")
     ("zh-TW" :html "&#26085;&#26399;" :utf-8 "日期"))
    ("Equation"
     ("de" :default "Gleichung")
     ("es" :html "Ecuaci&oacute;n" :default "Ecuación")
     ("fr" :ascii "Equation" :default "Équation"))
    ("Figure"
     ("de" :default "Abbildung")
     ("es" :default "Figura")
     ("ja" :html "&#22259;" :utf-8 "図"))
    ("Figure %d:"
     ("de" :default "Abbildung %d:")
     ("es" :default "Figura %d:")
     ("fr" :default "Figure %d :" :html "Figure&nbsp;%d&nbsp;:")
     ("ja" :html "&#22259;%d:" :utf-8 "図%d:"))
    ("Footnotes"
     ("ca" :html "Peus de p&agrave;gina")
     ("cs" :default "Pozn\xe1mky pod carou")
     ("da" :default "Fodnoter")
     ("de" :html "Fu&szlig;noten" :default "Fußnoten")
     ("eo" :default "Piednotoj")
     ("es" :html "Nota al pie de p&aacute;gina" :default "Nota al pie de página")
     ("fi" :default "Alaviitteet")
     ("fr" :default "Notes de bas de page")
     ("hu" :html "L&aacute;bjegyzet")
     ("is" :html "Aftanm&aacute;lsgreinar")
     ("it" :html "Note a pi&egrave; di pagina")
     ("ja" :html "&#33050;&#27880;" :utf-8 "脚注")
     ("nl" :default "Voetnoten")
     ("no" :default "Fotnoter")
     ("nb" :default "Fotnoter")
     ("nn" :default "Fotnotar")
     ("pl" :default "Przypis")
     ("ru" :html "&#1057;&#1085;&#1086;&#1089;&#1082;&#1080;" :utf-8 "Сноски")
     ("sv" :default "Fotnoter")
     ("uk" :html "&#1055;&#1088;&#1080;&#1084;&#1110;&#1090;&#1082;&#1080;"
      :utf-8 "Примітки")
     ("zh-CN" :html "&#33050;&#27880;" :utf-8 "脚注")
     ("zh-TW" :html "&#33139;&#35387;" :utf-8 "腳註"))
    ("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&nbsp;%d&nbsp;:"))
    ("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 "&#34920;" :utf-8 "表"))
    ("Table %d:"
     ("de" :default "Tabelle %d")
     ("es" :default "Tabla %d")
     ("fr" :default "Tableau %d :")
     ("ja" :html "&#34920;%d:" :utf-8 "表%d:"))
    ("Table of Contents"
     ("ca" :html "&Iacute;ndex")
     ("cs" :default "Obsah")
     ("da" :default "Indhold")
     ("de" :default "Inhaltsverzeichnis")
     ("eo" :default "Enhavo")
     ("es" :html "&Iacute;ndice")
     ("fi" :html "Sis&auml;llysluettelo")
     ("fr" :ascii "Sommaire" :default "Table des matières")
     ("hu" :html "Tartalomjegyz&eacute;k")
     ("is" :default "Efnisyfirlit")
     ("it" :default "Indice")
     ("ja" :html "&#30446;&#27425;" :utf-8 "目次")
     ("nl" :default "Inhoudsopgave")
     ("no" :default "Innhold")
     ("nb" :default "Innhold")
     ("nn" :default "Innhald")
     ("pl" :html "Spis tre&#x015b;ci")
     ("ru" :html "&#1057;&#1086;&#1076;&#1077;&#1088;&#1078;&#1072;&#1085;&#1080;&#1077;"
      :utf-8 "Содержание")
     ("sv" :html "Inneh&aring;ll")
     ("uk" :html "&#1047;&#1084;&#1110;&#1089;&#1090;" :utf-8 "Зміст")
     ("zh-CN" :html "&#30446;&#24405;" :utf-8 "目录")
     ("zh-TW" :html "&#30446;&#37636;" :utf-8 "目錄"))
    ("Unknown reference"
     ("de" :default "Unbekannter Verweis")
     ("es" :default "referencia desconocida")
     ("fr" :ascii "Destination inconnue" :default "Référence inconnue")))
  "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)))


\f
;;; 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 "„" :html "&bdquo;" :latex "\"`"
			   :texinfo "@quotedblbase{}")
     (closing-double-quote :utf-8 "“" :html "&ldquo;" :latex "\"'"
			   :texinfo "@quotedblleft{}")
     (opening-single-quote :utf-8 "‚" :html "&sbquo;" :latex "\\glq{}"
			   :texinfo "@quotesinglbase{}")
     (closing-single-quote :utf-8 "‘" :html "&lsquo;" :latex "\\grq{}"
			   :texinfo "@quoteleft{}")
     (apostrophe :utf-8 "’" :html "&rsquo;"))
    ("en"
     (opening-double-quote :utf-8 "“" :html "&ldquo;" :latex "``" :texinfo "``")
     (closing-double-quote :utf-8 "”" :html "&rdquo;" :latex "''" :texinfo "''")
     (opening-single-quote :utf-8 "‘" :html "&lsquo;" :latex "`" :texinfo "`")
     (closing-single-quote :utf-8 "’" :html "&rsquo;" :latex "'" :texinfo "'")
     (apostrophe :utf-8 "’" :html "&rsquo;"))
    ("es"
     (opening-double-quote :utf-8 "«" :html "&laquo;" :latex "\\guillemotleft{}"
			   :texinfo "@guillemetleft{}")
     (closing-double-quote :utf-8 "»" :html "&raquo;" :latex "\\guillemotright{}"
			   :texinfo "@guillemetright{}")
     (opening-single-quote :utf-8 "“" :html "&ldquo;" :latex "``" :texinfo "``")
     (closing-single-quote :utf-8 "”" :html "&rdquo;" :latex "''" :texinfo "''")
     (apostrophe :utf-8 "’" :html "&rsquo;"))
    ("fr"
     (opening-double-quote :utf-8 "« " :html "&laquo;&nbsp;" :latex "\\og "
			   :texinfo "@guillemetleft{}@tie{}")
     (closing-double-quote :utf-8 " »" :html "&nbsp;&raquo;" :latex "\\fg{}"
			   :texinfo "@tie{}@guillemetright{}")
     (opening-single-quote :utf-8 "« " :html "&laquo;&nbsp;" :latex "\\og "
			   :texinfo "@guillemetleft{}@tie{}")
     (closing-single-quote :utf-8 " »" :html "&nbsp;&raquo;" :latex "\\fg{}"
			   :texinfo "@tie{}@guillemetright{}")
     (apostrophe :utf-8 "’" :html "&rsquo;")))
  "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 &optional n))
(declare-function org-export-get-previous-element "org-export" (blob info &optional n))
(defun org-export-activate-smart-quotes (s encoding info &optional original)
  "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

debug log:

solving 8b7b102 ...
found 8b7b102 in https://list.orgmode.org/orgmode/87fvw1ovtm.fsf@gmail.com/

applying [1/1] https://list.orgmode.org/orgmode/87fvw1ovtm.fsf@gmail.com/
diff --git a/lisp/ox-i18n.el b/lisp/ox-i18n.el
new file mode 100644
index 0000000..8b7b102

Checking patch lisp/ox-i18n.el...
Applied patch lisp/ox-i18n.el cleanly.

index at:
100644 8b7b102ad15e11aeeff49110dd6c76376c30c802	lisp/ox-i18n.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).