-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
po-mode.el
3430 lines (3140 loc) · 132 KB
/
po-mode.el
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; po-mode.el --- major mode for GNU gettext PO files
;; Copyright (C) 1995-2002, 2005-2008, 2010, 2013-2017, 2019 Free Software
;; Foundation, Inc.
;; Authors: François Pinard <[email protected]>
;; Greg McGary <[email protected]>
;; Keywords: i18n gettext
;; Created: 1995
;; This file is part of GNU gettext.
;; 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 <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This package provides the tools meant to help editing PO files,
;; as documented in the GNU gettext user's manual. See this manual
;; for user documentation, which is not repeated here.
;; To install, merely put this file somewhere GNU Emacs will find it,
;; then add the following lines to your .emacs file:
;;
;; (autoload 'po-mode "po-mode"
;; "Major mode for translators to edit PO files" t)
;; (setq auto-mode-alist (cons '("\\.po\\'\\|\\.po\\." . po-mode)
;; auto-mode-alist))
;;
;; To use the right coding system automatically under Emacs 20 or newer,
;; also add:
;;
;; (autoload 'po-find-file-coding-system "po-compat")
;; (modify-coding-system-alist 'file "\\.po\\'\\|\\.po\\."
;; 'po-find-file-coding-system)
;;
;; You may also adjust some variables, below, by defining them in your
;; '.emacs' file, either directly or through command 'M-x customize'.
;; TODO:
;; Plural form editing:
;; - When in edit mode, currently it highlights (in green) the msgid;
;; it should also highlight the msgid_plural string, I would say, since
;; the translator has to look at both.
;; - After the translator finished the translation of msgstr[0], it would
;; be nice if the cursor would automatically move to the beginning of the
;; msgstr[1] line, so that the translator just needs to press RET to edit
;; that.
;; - If msgstr[1] is empty but msgstr[0] is not, it would be ergonomic if the
;; contents of msgstr[0] would be copied. (Not sure if this should happen
;; at the end of the editing msgstr[0] or at the beginning of the editing
;; of msgstr[1].) Reason: These two strings are usually very similar.
;;; Code:
(defconst po-mode-version-string "2.26" "\
Version number of this version of po-mode.el.")
;;; Emacs portability matters - part I.
;;; Here is the minimum for customization to work. See part II.
;; Experiment with Emacs LISP message internationalisation.
(eval-and-compile
(or (fboundp 'set-translation-domain)
(defsubst set-translation-domain (string) nil))
(or (fboundp 'translate-string)
(defsubst translate-string (string) string)))
(defsubst _ (string) (translate-string string))
(defsubst N_ (string) string)
;; Handle missing 'customs' package.
(eval-and-compile
(condition-case ()
(require 'custom)
(error nil))
(if (and (featurep 'custom) (fboundp 'custom-declare-variable))
nil
(defmacro defgroup (&rest args)
nil)
(defmacro defcustom (var value doc &rest args)
`(defvar ,var ,value ,doc))))
;;; Customisation.
(defgroup po nil
"Major mode for editing PO files"
:group 'i18n)
(defcustom po-auto-edit-with-msgid nil
"*Automatically use msgid when editing untranslated entries."
:type 'boolean
:group 'po)
(defcustom po-auto-fuzzy-on-edit nil
"*Automatically mark entries fuzzy when being edited."
:type 'boolean
:group 'po)
(defcustom po-auto-delete-previous-msgid t
"*Automatically delete previous msgid (marked #|) when editing entry.
Value is nil, t, or ask."
:type '(choice (const nil)
(const t)
(const ask))
:group 'po)
(defcustom po-auto-select-on-unfuzzy nil
"*Automatically select some new entry while making an entry not fuzzy."
:type 'boolean
:group 'po)
(defcustom po-keep-mo-file nil
"*Set whether MO file should be kept or discarded after validation."
:type 'boolean
:group 'po)
(defcustom po-auto-update-file-header t
"*Automatically revise headers. Value is nil, t, or ask."
:type '(choice (const nil)
(const t)
(const ask))
:group 'po)
(defcustom po-auto-replace-revision-date t
"*Automatically revise date in headers. Value is nil, t, or ask."
:type '(choice (const nil)
(const t)
(const ask))
:group 'po)
(defcustom po-default-file-header "\
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Free Software Foundation, Inc.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid \"\"
msgstr \"\"
\"Project-Id-Version: PACKAGE VERSION\\n\"
\"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\\n\"
\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"
\"Language-Team: LANGUAGE <[email protected]>\\n\"
\"MIME-Version: 1.0\\n\"
\"Content-Type: text/plain; charset=CHARSET\\n\"
\"Content-Transfer-Encoding: 8bit\\n\"
"
"*Default PO file header."
:type 'string
:group 'po)
(defcustom po-translation-project-address
"*Electronic mail address of the Translation Project.
Typing \\[po-send-mail] (normally bound to `M') the user will send the PO file
to this email address."
:type 'string
:group 'po)
(defcustom po-translation-project-mail-label "TP-Robot"
"*Subject label when sending the PO file to `po-translation-project-address'."
:type 'string
:group 'po)
(defcustom po-highlighting t
"*Highlight text whenever appropriate, when non-nil.
However, on older Emacses, a yet unexplained highlighting bug causes files
to get mangled."
:type 'boolean
:group 'po)
(defcustom po-highlight-face 'highlight
"*The face used for PO mode highlighting. For Emacses with overlays.
Possible values are 'highlight', 'modeline', 'secondary-selection',
'region', and 'underline'.
This variable can be set by the user to whatever face they desire.
It's most convenient if the cursor color and highlight color are
slightly different."
:type 'face
:group 'po)
(defcustom po-team-name-to-code
;; All possible languages, a complete ISO 639 list, the inverse of
;; gettext-tools/src/lang-table.c, and a little more.
'(("LANGUAGE" . "LL")
("(Afan) Oromo" . "om")
("Abkhazian" . "ab")
("Achinese" . "ace")
("Afar" . "aa")
("Afrikaans" . "af")
("Akan" . "ak")
("Albanian" . "sq")
("Amharic" . "am")
("Arabic" . "ar")
("Aragonese" . "an")
("Argentinian" . "es_AR")
("Armenian" . "hy")
("Assamese" . "as")
("Austrian" . "de_AT")
("Avaric" . "av")
("Avestan" . "ae")
("Awadhi" . "awa")
("Aymara" . "ay")
("Azerbaijani" . "az")
("Balinese" . "ban")
("Baluchi" . "bal")
("Bambara" . "bm")
("Bashkir" . "ba")
("Basque" . "eu")
("Beja" . "bej")
("Belarusian" . "be")
("Bemba" . "bem")
("Bengali" . "bn")
("Bhojpuri" . "bho")
("Bihari" . "bh")
("Bikol" . "bik")
("Bini" . "bin")
("Bislama" . "bi")
("Bosnian" . "bs")
("Brazilian Portuguese" . "pt_BR")
("Breton" . "br")
("Buginese" . "bug")
("Bulgarian" . "bg")
("Burmese" . "my")
("Catalan" . "ca")
("Cebuano" . "ceb")
("Central Khmer" . "km")
("Chamorro" . "ch")
("Chechen" . "ce")
("Chinese" . "zh")
("Chinese (Hong Kong)" . "zh_HK")
("Chinese (simplified)" . "zh_CN")
("Chinese (traditional)" . "zh_TW")
("Church Slavic" . "cu")
("Chuvash" . "cv")
("Cornish" . "kw")
("Corsican" . "co")
("Cree" . "cr")
("Croatian" . "hr")
("Czech" . "cs")
("Danish" . "da")
("Dinka" . "din")
("Divehi" . "dv")
("Dogri" . "doi")
("Dutch" . "nl")
("Dzongkha" . "dz")
("English" . "en")
("English (British)" . "en_GB")
("Esperanto" . "eo")
("Estonian" . "et")
("Ewe" . "ee")
("Faroese" . "fo")
("Fijian" . "fj")
("Filipino" . "fil")
("Finnish" . "fi")
("Fon" . "fon")
("French" . "fr")
("Frisian" . "fy")
("Fulah" . "ff")
("Galician" . "gl")
("Ganda" . "lg")
("Georgian" . "ka")
("German" . "de")
("Gondi" . "gon")
("Greek" . "el")
("Guarani" . "gn")
("Gujarati" . "gu")
("Haitian" . "ht")
("Hausa" . "ha")
("Hebrew" . "he")
("Herero" . "hz")
("Hiligaynon" . "hil")
("Hindi" . "hi")
("Hiri Motu" . "ho")
("Hmong" . "hmn")
("Hungarian" . "hu")
("Hyam" . "jab")
("Icelandic" . "is")
("Ido" . "io")
("Igbo" . "ig")
("Iloko" . "ilo")
("Indonesian" . "id")
("Interlingua" . "ia")
("Interlingue" . "ie")
("Inuktitut" . "iu")
("Inupiak" . "ik")
("Irish" . "ga")
("Italian" . "it")
("Japanese" . "ja")
("Javanese" . "jv")
("Jju" . "kaj")
("Kabardian" . "kbd")
("Kabyle" . "kab")
("Kagoma" . "kdm")
("Kalaallisut" . "kl")
("Kamba" . "kam")
("Kannada" . "kn")
("Kanuri" . "kr")
("Kashmiri" . "ks")
("Kashubian" . "csb")
("Kazakh" . "kk")
("Khmer" . "km") ; old name
("Kikuyu" . "ki")
("Kimbundu" . "kmb")
("Kinyarwanda" . "rw")
("Kirghiz" . "ky")
("Kirundi" . "rn")
("Komi" . "kv")
("Kongo" . "kg")
("Konkani" . "kok")
("Korean" . "ko")
("Kuanyama" . "kj")
("Kurdish" . "ku")
("Kurukh" . "kru")
("Laotian" . "lo")
("Latin" . "la")
("Latvian" . "lv")
("Letzeburgesch" . "lb")
("Limburgish" . "li")
("Lingala" . "ln")
("Lithuanian" . "lt")
("Low Saxon" . "nds")
("Luba-Katanga" . "lu")
("Luba-Lulua" . "lua")
("Luo" . "luo")
("Macedonian" . "mk")
("Madurese" . "mad")
("Magahi" . "mag")
("Maithili" . "mai")
("Makasar" . "mak")
("Malagasy" . "mg")
("Malay" . "ms")
("Malayalam" . "ml")
("Maltese" . "mt")
("Mandingo" . "man")
("Manipuri" . "mni")
("Manx" . "gv")
("Maori" . "mi")
("Marathi" . "mr")
("Marshall" . "mh")
("Marshallese" . "mh")
("Marwari" . "mwr")
("Mayan" . "myn")
("Mende" . "men")
("Minangkabau" . "min")
("Moldavian" . "mo")
("Mongolian" . "mn")
("Mossi" . "mos")
("Nahuatl" . "nah")
("Nauru" . "na")
("Navajo" . "nv")
("Ndonga" . "ng")
("Neapolitan" . "nap")
("Nepali" . "ne")
("North Ndebele" . "nd")
("Northern Sami" . "se")
("Northern Sotho" . "nso")
("Norwegian Bokmal" . "nb")
("Norwegian Nynorsk" . "nn")
("Norwegian" . "no")
("Nyamwezi" . "nym")
("Nyanja" . "ny")
("Nyankole" . "nyn")
("Occitan" . "oc")
("Ojibwa" . "oj")
("Old English" . "ang")
("Oriya" . "or")
("Ossetian" . "os")
("Páez" . "pbb")
("Pali" . "pi")
("Pampanga" . "pam")
("Pangasinan" . "pag")
("Pashto" . "ps")
("Persian" . "fa")
("Polish" . "pl")
("Portuguese" . "pt")
("Punjabi" . "pa")
("Quechua" . "qu")
("Rajasthani" . "raj")
("Rhaeto-Roman" . "rm") ; old name
("Romanian" . "ro")
("Romansh" . "rm")
("Russian" . "ru")
("Samoan" . "sm")
("Sango" . "sg")
("Sanskrit" . "sa")
("Santali" . "sat")
("Sardinian" . "sc")
("Sasak" . "sas")
("Scots" . "gd") ; old name
("Scottish Gaelic" . "gd")
("Serbian" . "sr")
("Serer" . "srr")
("Sesotho" . "st")
("Setswana" . "tn")
("Shan" . "shn")
("Shona" . "sn")
("Sichuan Yi" . "ii")
("Sicilian" . "scn")
("Sidamo" . "sid")
("Sindhi" . "sd")
("Sinhala" . "si")
("Sinhalese" . "si")
("Siswati" . "ss")
("Slovak" . "sk")
("Slovenian" . "sl")
("Somali" . "so")
("Sorbian" . "wen")
("South Ndebele" . "nr")
("Spanish" . "es")
("Spanish (Canary Islands)" . "es_IC")
("Sukuma" . "suk")
("Sundanese" . "su")
("Susu" . "sus")
("Swahili" . "sw")
("Swedish" . "sv")
("Swiss German" . "gsw")
("Tagalog" . "tl")
("Tahitian" . "ty")
("Tajik" . "tg")
("Tamil" . "ta")
("Tatar" . "tt")
("Telugu" . "te")
("Tetum" . "tet")
("Thai" . "th")
("Tibetan" . "bo")
("Tigrinya" . "ti")
("Timne" . "tem")
("Tiv" . "tiv")
("Tonga" . "to")
("Tsonga" . "ts")
("Tumbuka" . "tum")
("Turkish" . "tr")
("Turkmen" . "tk")
("Twi" . "tw")
("Tyap" . "kcg")
("Uighur" . "ug")
("Ukrainian" . "uk")
("Umbundu" . "umb")
("Urdu" . "ur")
("Uzbek" . "uz")
("Venda" . "ve")
("Vietnamese" . "vi")
("Volapuk" . "vo")
("Walloon" . "wa")
("Walamo" . "wal")
("Waray" . "war")
("Welsh" . "cy")
("Western Frisian" . "fy")
("Wolof" . "wo")
("Xhosa" . "xh")
("Yao" . "yao")
("Yiddish" . "yi")
("Yoruba" . "yo")
("Zapotec" . "zap")
("Zhuang" . "za")
("Zulu" . "zu")
)
"*Association list giving team codes from team names.
This is used for generating a submission file name for the 'M' command.
If a string instead of an alist, it is a team code to use unconditionnally."
:type 'sexp
:group 'po)
(defcustom po-gzip-uuencode-command "gzip -9 | uuencode -m"
"*The filter to use for preparing a mail invoice of the PO file.
Normally \"gzip -9 | uuencode -m\", remove the -9 for lesser compression,
or remove the -m if you are not using the GNU version of 'uuencode'."
:type 'string
:group 'po)
(defvar po-subedit-mode-syntax-table
(copy-syntax-table text-mode-syntax-table)
"Syntax table used while in PO mode.")
;;; Emacs portability matters - part II.
;;; Many portability matters are addressed in this page. The few remaining
;;; cases, elsewhere, all involve 'eval-and-compile', 'boundp' or 'fboundp'.
;; Protect string comparisons from text properties if possible.
(eval-and-compile
(fset 'po-buffer-substring
(symbol-function (if (fboundp 'buffer-substring-no-properties)
'buffer-substring-no-properties
'buffer-substring)))
(if (fboundp 'match-string-no-properties)
(fset 'po-match-string (symbol-function 'match-string-no-properties))
(defun po-match-string (number)
"Return string of text matched by last search."
(po-buffer-substring (match-beginning number) (match-end number)))))
;; Handle missing 'with-temp-buffer' function.
(eval-and-compile
(if (fboundp 'with-temp-buffer)
(fset 'po-with-temp-buffer (symbol-function 'with-temp-buffer))
(defmacro po-with-temp-buffer (&rest forms)
"Create a temporary buffer, and evaluate FORMS there like 'progn'."
(let ((curr-buffer (make-symbol "curr-buffer"))
(temp-buffer (make-symbol "temp-buffer")))
`(let ((,curr-buffer (current-buffer))
(,temp-buffer (get-buffer-create
(generate-new-buffer-name " *po-temp*"))))
(unwind-protect
(progn
(set-buffer ,temp-buffer)
,@forms)
(set-buffer ,curr-buffer)
(and (buffer-name ,temp-buffer)
(kill-buffer ,temp-buffer))))))))
;; Handle missing 'kill-new' function.
(eval-and-compile
(if (fboundp 'kill-new)
(fset 'po-kill-new (symbol-function 'kill-new))
(defun po-kill-new (string)
"Push STRING onto the kill ring, for Emacs 18 where kill-new is missing."
(po-with-temp-buffer
(insert string)
(kill-region (point-min) (point-max))))))
;; Handle missing 'read-event' function.
(eval-and-compile
(fset 'po-read-event
(cond ((fboundp 'read-event)
;; GNU Emacs.
'read-event)
(t
;; Older Emacses.
'read-char))))
;; Handle missing 'force-mode-line-update' function.
(eval-and-compile
(if (fboundp 'force-mode-line-update)
(fset 'po-force-mode-line-update
(symbol-function 'force-mode-line-update))
(defun po-force-mode-line-update ()
"Force the mode-line of the current buffer to be redisplayed."
(set-buffer-modified-p (buffer-modified-p)))))
;; Handle portable highlighting. Code has been adapted (OK... stolen! :-)
;; from 'ispell.el'.
(defun po-create-overlay ()
"Create and return a deleted overlay structure.
The variable 'po-highlight-face' selects the face to use for highlighting."
(let ((overlay (make-overlay (point) (point))))
(overlay-put overlay 'face po-highlight-face)
;; The fun thing is that a deleted overlay retains its face, and is
;; movable.
(delete-overlay overlay)
overlay))
(defun po-highlight (overlay start end &optional buffer)
"Use OVERLAY to highlight the string from START to END.
If limits are not relative to the current buffer, use optional BUFFER."
(move-overlay overlay start end (or buffer (current-buffer))))
(defun po-dehighlight (overlay)
"Display normally the last string which OVERLAY highlighted.
The current buffer should be in PO mode, when this function is called."
(delete-overlay overlay))
;;; Buffer local variables.
;; The following block of declarations has the main purpose of avoiding
;; byte compiler warnings. It also introduces some documentation for
;; each of these variables, all meant to be local to PO mode buffers.
;; Flag telling that MODE-LINE-STRING should be displayed. See 'Window'
;; page below. Exceptionally, this variable is local to *all* buffers.
(defvar po-mode-flag)
;; PO buffers are kept read-only to prevent random modifications. READ-ONLY
;; holds the value of the read-only flag before PO mode was entered.
(defvar po-read-only)
;; The current entry extends from START-OF-ENTRY to END-OF-ENTRY, it
;; includes preceding whitespace and excludes following whitespace. The
;; start of keyword lines are START-OF-MSGID and START-OF-MSGSTR.
;; ENTRY-TYPE classifies the entry.
(defvar po-start-of-entry)
(defvar po-start-of-msgctxt) ; = po-start-of-msgid if there is no msgctxt
(defvar po-start-of-msgid)
(defvar po-start-of-msgid_plural) ; = nil if there is no msgid_plural
(defvar po-start-of-msgstr-block)
(defvar po-start-of-msgstr-form)
(defvar po-end-of-msgstr-form)
(defvar po-end-of-entry)
(defvar po-entry-type)
;; A few counters are usefully shown in the Emacs mode line.
(defvar po-translated-counter)
(defvar po-fuzzy-counter)
(defvar po-untranslated-counter)
(defvar po-obsolete-counter)
(defvar po-mode-line-string)
;; PO mode keeps track of fields being edited, for one given field should
;; have one editing buffer at most, and for exiting a PO buffer properly
;; should offer to close all pending edits. Variable EDITED-FIELDS holds an
;; an list of "slots" of the form: (ENTRY-MARKER EDIT-BUFFER OVERLAY-INFO).
;; To allow simultaneous edition of the comment and the msgstr of an entry,
;; ENTRY-MARKER points to the msgid line if a comment is being edited, or to
;; the msgstr line if the msgstr is being edited. EDIT-BUFFER is the
;; temporary Emacs buffer used to edit the string. OVERLAY-INFO, when not
;; nil, holds an overlay (or if overlays are not supported, a cons of two
;; markers) for this msgid string which became highlighted for the edit.
(defvar po-edited-fields)
;; We maintain a set of movable pointers for returning to entries.
(defvar po-marker-stack)
;; SEARCH path contains a list of directories where files may be found,
;; in a format suitable for read completion. Each directory includes
;; its trailing slash. PO mode starts with "./" and "../".
(defvar po-search-path)
;; The following variables are meaningful only when REFERENCE-CHECK
;; is identical to START-OF-ENTRY, else they should be recomputed.
;; REFERENCE-ALIST contains all known references for the current
;; entry, each list element is (PROMPT FILE LINE), where PROMPT may
;; be used for completing read, FILE is a string and LINE is a number.
;; REFERENCE-CURSOR is a cycling cursor into REFERENCE-ALIST.
(defvar po-reference-alist)
(defvar po-reference-cursor)
(defvar po-reference-check)
;; The following variables are for marking translatable strings in program
;; sources. KEYWORDS is the list of keywords for marking translatable
;; strings, kept in a format suitable for reading with completion.
;; STRING-CONTENTS holds the value of the most recent string found in sources,
;; and when it is not nil, then STRING-BUFFER, STRING-START and STRING-END
;; describe where it is. MARKING-OVERLAY, if not 'nil', holds the overlay
;; which highlight the last found string; for older Emacses, it holds the cons
;; of two markers around the highlighted region.
(defvar po-keywords)
(defvar po-string-contents)
(defvar po-string-buffer)
(defvar po-string-start)
(defvar po-string-end)
(defvar po-marking-overlay)
;;; PO mode variables and constants (usually not to customize).
;; The textdomain should really be "gettext", only trying it for now.
;; All this requires more thinking, we cannot just do this like that.
(set-translation-domain "po-mode")
(defun po-mode-version ()
"Show Emacs PO mode version."
(interactive)
(message (_"Emacs PO mode, version %s") po-mode-version-string))
(defconst po-help-display-string
(_"\
PO Mode Summary Next Previous Miscellaneous
*: Later, /: Docum n p Any type . Redisplay
t T Translated /v Version info
Moving around f F Fuzzy ?, h This help
< First if any o O Obsolete = Current index
> Last if any u U Untranslated 0 Other window
/SPC Auto select V Validate
Msgstr Comments M Mail officially
Modifying entries RET # Call editor _ Undo
TAB Remove fuzzy mark k K Kill to E Edit out full
DEL Fuzzy or fade out w W Copy to Q Forceful quit
LFD Init with msgid y Y Yank from q Confirm and quit
gettext Keyword Marking Position Stack
, Find next string Compendiums m Mark and push current
M-, Mark translatable *c To compendium r Pop and return
M-. Change mark, mark *M-C Select, save x Exchange current/top
Program Sources Auxiliary Files Lexicography
s Cycle reference a Cycle file *l Lookup translation
M-s Select reference C-c C-a Select file *M-l Add/edit translation
S Consider path A Consider PO file *L Consider lexicon
M-S Ignore path M-A Ignore PO file *M-L Ignore lexicon
")
"Help page for PO mode.")
(defconst po-mode-menu-layout
`("PO"
("Moving around"
["Auto select" po-auto-select-entry
:help "Jump to next interesting entry"]
"---"
;; Forward
["Any next" po-next-entry
:help "Jump to next entry"]
["Next translated" po-next-translated-entry
:help "Jump to next translated entry"]
["Next fuzzy" po-next-fuzzy-entry
:help "Jump to next fuzzy entry"]
["Next obsolete" po-next-obsolete-entry
:help "Jump to next obsolete entry"]
["Next untranslated" po-next-untranslated-entry
:help "Jump to next untranslated entry"]
["Last file entry" po-last-entry
:help "Jump to last entry"]
"---"
;; Backward
["Any previous" po-previous-entry
:help "Jump to previous entry"]
["Previous translated" po-previous-translated-entry
:help "Jump to previous translated entry"]
["Previous fuzzy" po-previous-fuzzy-entry
:help "Jump to previous fuzzy entry"]
["Previous obsolete" po-previous-obsolete-entry
:help "Jump to previous obsolete entry"]
["Previous untranslated" po-previous-untranslated-entry
:help "Jump to previous untranslated entry"]
["First file entry" po-first-entry
:help "Jump to first entry"]
"---"
;; "Position stack"
["Mark and push current" po-push-location
:help "Remember current location"]
["Pop and return" po-pop-location
:help "Jump to last remembered location and forget about it"]
["Exchange current/top" po-exchange-location
:help "Jump to last remembered location and remember current location"]
"---"
["Redisplay" po-current-entry
:help "Make current entry properly visible"]
["Current index" po-statistics
:help "Statistical info on current translation file"])
("Modifying entries"
["Undo" po-undo
:help "Revoke last changed entry"]
"---"
;; "Msgstr"
["Edit msgstr" po-edit-msgstr
:help "Edit current translation"]
["Ediff and merge msgstr" po-edit-msgstr-and-ediff
:help "Call `ediff' on current translation for merging"]
["Cut msgstr" po-kill-msgstr
:help "Cut (kill) current translation"]
["Copy msgstr" po-kill-ring-save-msgstr
:help "Copy current translation"]
["Paste msgstr" po-yank-msgstr
:help "Paste (yank) text most recently cut/copied translation"]
"---"
;; "Comments"
["Edit comment" po-edit-comment
:help "Edit current comment"]
["Ediff and merge comment" po-edit-comment-and-ediff
:help "Call `ediff' on current comment for merging"]
["Cut comment" po-kill-comment
:help "Cut (kill) current comment"]
["Copy comment" po-kill-ring-save-comment
:help "Copy current translation"]
["Paste comment" po-yank-comment
:help "Paste (yank) text most recently cut/copied"]
"---"
["Remove fuzzy mark" po-unfuzzy
:help "Remove \"#, fuzzy\""]
["Fuzzy or fade out" po-fade-out-entry
:help "Set current entry fuzzy, or if already fuzzy delete it"]
["Init with msgid" po-msgid-to-msgstr
:help "Initialize or replace current translation with the original message"])
("Other files"
["Other window" po-other-window
:help "Select other window; if necessay split current frame"]
"---"
;; "Program sources"
["Cycle reference in source file" po-cycle-source-reference t]
["Select reference" po-select-source-reference t]
["Consider path" po-consider-source-path t]
["Ignore path" po-ignore-source-path t]
;; "---"
;; ;; "Compendiums"
;; ["To add entry to compendium" po-save-entry nil]
;; ["Select from compendium, save" po-select-and-save-entry nil]
"---"
;; "Auxiliary files"
["Cycle through auxilicary file" po-cycle-auxiliary t]
["Select auxilicary file" po-select-auxiliary t]
["Consider as auxilicary file" po-consider-as-auxiliary t]
["Ignore as auxilicary file" po-ignore-as-auxiliary t]
;; "---"
;; ;; "Lexicography"
;; ["Lookup translation" po-lookup-lexicons nil]
;; ["Add/edit translation" po-edit-lexicon-entry nil]
;; ["Consider lexicon" po-consider-lexicon-file nil]
;; ["Ignore lexicon" po-ignore-lexicon-file nil])
"---"
"Source marking"
["Find first string" (po-tags-search '(nil)) t]
["Prefer keyword" (po-select-mark-and-mark '(nil)) t]
["Find next string" po-tags-search t]
["Mark preferred" po-mark-translatable t]
["Mark with keyword" po-select-mark-and-mark t])
"---"
["Version info" po-mode-version
:help "Display version number of PO mode"]
["Help page" po-help
:help "Show the PO mode help screen"]
["Validate" po-validate
:help "Check validity of current translation file using `msgfmt'"]
["Mail officially" po-send-mail
:help "Send current translation file to the Translation Robot by mail"]
["Edit out full" po-edit-out-full
:help "Leave PO mode to edit translation file using fundamental mode"]
"---"
["Forceful quit" po-quit
:help "Close (kill) current translation file without saving"]
["Soft quit" po-confirm-and-quit
:help "Save current translation file, than close (kill) it"]))
(defconst po-subedit-mode-menu-layout
`("PO-Edit"
["Ediff and merge translation variants" po-subedit-ediff
:help "Call `ediff' for merging variants"]
["Cycle through auxiliary files" po-subedit-cycle-auxiliary t]
"---"
["Abort edit" po-subedit-abort
:help "Don't change the translation"]
["Exit edit" po-subedit-exit
:help "Use this text as the translation and close current edit buffer"]))
(defconst po-subedit-message
(_"Type 'C-c C-c' once done, or 'C-c C-k' to abort edit")
"Message to post in the minibuffer when an edit buffer is displayed.")
(defvar po-auxiliary-list nil
"List of auxiliary PO files, in completing read format.")
(defvar po-auxiliary-cursor nil
"Cursor into the 'po-auxiliary-list'.")
(defvar po-compose-mail-function
(let ((functions '(compose-mail-other-window
message-mail-other-window
compose-mail
message-mail))
result)
(while (and (not result) functions)
(if (fboundp (car functions))
(setq result (car functions))
(setq functions (cdr functions))))
(cond (result)
((fboundp 'mail-other-window)
(function (lambda (to subject)
(mail-other-window nil to subject))))
((fboundp 'mail)
(function (lambda (to subject)
(mail nil to subject))))
(t (function (lambda (to subject)
(error (_"I do not know how to mail to '%s'") to))))))
"Function to start composing an electronic message.")
(defvar po-any-previous-msgctxt-regexp
"^#\\(~\\)?|[ \t]*msgctxt.*\n\\(#\\(~\\)?|[ \t]*\".*\n\\)*"
"Regexp matching a whole #| msgctxt field, whether obsolete or not.")
(defvar po-any-previous-msgid-regexp
"^#\\(~\\)?|[ \t]*msgid.*\n\\(#\\(~\\)?|[ \t]*\".*\n\\)*"
"Regexp matching a whole #| msgid field, whether obsolete or not.")
(defvar po-any-previous-msgid_plural-regexp
"^#\\(~\\)?|[ \t]*msgid_plural.*\n\\(#\\(~\\)?|[ \t]*\".*\n\\)*"
"Regexp matching a whole #| msgid_plural field, whether obsolete or not.")
(defvar po-any-msgctxt-msgid-regexp
"^\\(#~[ \t]*\\)?msg\\(ctxt\\|id\\).*\n\\(\\(#~[ \t]*\\)?\".*\n\\)*"
"Regexp matching a whole msgctxt or msgid field, whether obsolete or not.")
(defvar po-any-msgid-regexp
"^\\(#~[ \t]*\\)?msgid.*\n\\(\\(#~[ \t]*\\)?\".*\n\\)*"
"Regexp matching a whole msgid field, whether obsolete or not.")
(defvar po-any-msgid_plural-regexp
"^\\(#~[ \t]*\\)?msgid_plural.*\n\\(\\(#~[ \t]*\\)?\".*\n\\)*"
"Regexp matching a whole msgid_plural field, whether obsolete or not.")
(defvar po-any-msgstr-block-regexp
"^\\(#~[ \t]*\\)?msgstr\\([ \t]\\|\\[0\\]\\).*\n\\(\\(#~[ \t]*\\)?\".*\n\\)*\\(\\(#~[ \t]*\\)?msgstr\\[[0-9]\\].*\n\\(\\(#~[ \t]*\\)?\".*\n\\)*\\)*"
"Regexp matching a whole msgstr or msgstr[] field, whether obsolete or not.")
(defvar po-any-msgstr-form-regexp
;; "^\\(#~[ \t]*\\)?msgstr.*\n\\(\\(#~[ \t]*\\)?\".*\n\\)*"
"^\\(#~[ \t]*\\)?msgstr\\(\\[[0-9]\\]\\)?.*\n\\(\\(#~[ \t]*\\)?\".*\n\\)*"
"Regexp matching just one msgstr or msgstr[] field, whether obsolete or not.")
(defvar po-msgstr-idx-keyword-regexp
"^\\(#~[ \t]*\\)?msgstr\\[[0-9]\\]"
"Regexp matching an indexed msgstr keyword, whether obsolete or not.")
(defvar po-msgfmt-program "msgfmt"
"Path to msgfmt program from GNU gettext package.")
;; Font lock based highlighting code.
(defconst po-font-lock-keywords
'(
;; ("^\\(msgctxt \\|msgid \\|msgstr \\)?\"\\|\"$" . font-lock-keyword-face)
;; (regexp-opt
;; '("msgctxt " "msgid " "msgid_plural " "msgstr " "msgstr[0] " "msgstr[1] "))
("^\\(\\(msg\\(ctxt\\|id\\(_plural\\)?\\|str\\(\\[[0-9]\\]\\)?\\)\\) \\)?\"\\|\"$"
. font-lock-keyword-face)
("\\\\.\\|%[*$-.0-9hjltuzL]*[a-zA-Z]" . font-lock-variable-name-face)
("^# .*\\|^#[:,]?" . font-lock-comment-face)
("^#:\\(.*\\)" 1 font-lock-reference-face)
("^#,\\(.*\\)" 1 font-lock-function-name-face)
)
"Additional expressions to highlight in PO mode.")
;; Old activator for 'font lock'. Is it still useful? I don't think so.
;;(if (boundp 'font-lock-keywords)
;; (put 'po-mode 'font-lock-keywords 'po-font-lock-keywords))
;; 'hilit19' based highlighting code has been disabled, as most probably
;; nobody really needs it (it also generates ugly byte-compiler warnings).
;;
;;(if (fboundp 'hilit-set-mode-patterns)
;; (hilit-set-mode-patterns 'po-mode
;; '(("^# .*\\|^#$" nil comment)
;; ("^#[.,:].*" nil include)
;; ("^\\(msgid\\|msgstr\\) *\"" nil keyword)
;; ("^\"\\|\"$" nil keyword))))
;;; Mode activation.
;; Emacs 21.2 comes with po-find-file-coding-system. We give preference
;; to the version shipped with Emacs.
(if (not (fboundp 'po-find-file-coding-system))
(require 'po-compat))
(defvar po-mode-abbrev-table nil
"Abbrev table used while in PO mode.")
(define-abbrev-table 'po-mode-abbrev-table ())
(defvar po-mode-map
;; Use (make-keymap) because (make-sparse-keymap) does not work on Demacs.
(let ((po-mode-map (make-keymap)))
(suppress-keymap po-mode-map)
(define-key po-mode-map "\C-i" 'po-unfuzzy)
(define-key po-mode-map "\C-j" 'po-msgid-to-msgstr)
(define-key po-mode-map "\C-m" 'po-edit-msgstr)
(define-key po-mode-map " " 'po-auto-select-entry)
(define-key po-mode-map "?" 'po-help)
(define-key po-mode-map "#" 'po-edit-comment)
(define-key po-mode-map "," 'po-tags-search)
(define-key po-mode-map "." 'po-current-entry)
(define-key po-mode-map "<" 'po-first-entry)
(define-key po-mode-map "=" 'po-statistics)
(define-key po-mode-map ">" 'po-last-entry)
(define-key po-mode-map "a" 'po-cycle-auxiliary)
;;;; (define-key po-mode-map "c" 'po-save-entry)
(define-key po-mode-map "f" 'po-next-fuzzy-entry)
(define-key po-mode-map "h" 'po-help)
(define-key po-mode-map "k" 'po-kill-msgstr)
;;;; (define-key po-mode-map "l" 'po-lookup-lexicons)
(define-key po-mode-map "m" 'po-push-location)
(define-key po-mode-map "n" 'po-next-entry)
(define-key po-mode-map "o" 'po-next-obsolete-entry)
(define-key po-mode-map "p" 'po-previous-entry)
(define-key po-mode-map "q" 'po-confirm-and-quit)
(define-key po-mode-map "r" 'po-pop-location)
(define-key po-mode-map "s" 'po-cycle-source-reference)
(define-key po-mode-map "t" 'po-next-translated-entry)
(define-key po-mode-map "u" 'po-next-untranslated-entry)
(define-key po-mode-map "v" 'po-mode-version)
(define-key po-mode-map "w" 'po-kill-ring-save-msgstr)
(define-key po-mode-map "x" 'po-exchange-location)
(define-key po-mode-map "y" 'po-yank-msgstr)
(define-key po-mode-map "A" 'po-consider-as-auxiliary)
(define-key po-mode-map "E" 'po-edit-out-full)
(define-key po-mode-map "F" 'po-previous-fuzzy-entry)
(define-key po-mode-map "K" 'po-kill-comment)
;;;; (define-key po-mode-map "L" 'po-consider-lexicon-file)
(define-key po-mode-map "M" 'po-send-mail)
(define-key po-mode-map "O" 'po-previous-obsolete-entry)
(define-key po-mode-map "T" 'po-previous-translated-entry)
(define-key po-mode-map "U" 'po-previous-untranslated-entry)
(define-key po-mode-map "Q" 'po-quit)
(define-key po-mode-map "S" 'po-consider-source-path)
(define-key po-mode-map "V" 'po-validate)
(define-key po-mode-map "W" 'po-kill-ring-save-comment)
(define-key po-mode-map "Y" 'po-yank-comment)
(define-key po-mode-map "_" 'po-undo)
(define-key po-mode-map "\C-_" 'po-undo)
(define-key po-mode-map "\C-xu" 'po-undo)
(define-key po-mode-map "0" 'po-other-window)
(define-key po-mode-map "\177" 'po-fade-out-entry)