This file is indexed.

/usr/share/uim/i18n.scm is in uim-data 1:1.8.6+gh20180114.64e3173-2build2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
;;; i18n.scm: Internationalization functions for uim
;;;
;;; Copyright (c) 2003-2013 uim Project https://github.com/uim/uim
;;;
;;; All rights reserved.
;;;
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;; 1. Redistributions of source code must retain the above copyright
;;;    notice, this list of conditions and the following disclaimer.
;;; 2. Redistributions in binary form must reproduce the above copyright
;;;    notice, this list of conditions and the following disclaimer in the
;;;    documentation and/or other materials provided with the distribution.
;;; 3. Neither the name of authors nor the names of its contributors
;;;    may be used to endorse or promote products derived from this software
;;;    without specific prior written permission.
;;;
;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;;; ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
;;; SUCH DAMAGE.
;;;;

(require "util.scm")

;;
;; string translation
;;

;; WARNING: ugettext and _ should not be used for normal codes.
;; convenience shorthand of runtime translation
(define ugettext
  (if (provided? "nls")
      (lambda (str)
	(dgettext (gettext-package) str))
      (lambda (str)
	str)))

;; WARNING: ugettext and _ should not be used for normal codes.
;; shorthand version of gettext. it is also used as xgettext keyword
(define _ ugettext)

;; shorthand version of gettext_noop. it is used as xgettext keyword
(define N_
  (lambda (str)
    str))

;; All other gettext functions are defined in C. See uim/intl.c


;;
;; locale
;;
(define-record 'locale
  '((lang       "")
    (territory  "")
    (codeset    "")))
(define locale-new-internal locale-new)
(define locale-set-lang-internal! locale-set-lang!)
(define locale-set-territory-internal! locale-set-territory!)

;; Create a locale object from a localestr. localestr assumes
;; following format. modifier is not supported
;;
;;   language[_territory][.codeset]
;;
;; Some exception rules exist.
;;
;; * Accept #f, "C" and "POSIX" as "en" locale
;;
;; * Accept "" as native locale as like as performed in
;;   setlocale(). It attempt to retrieve the locale information from
;;   LC_ALL and LANG environment variable. If failed to retrieve the
;;   information from the two variable, it defaults to "en". It does
;;   not attempt to retrieve from particular locale category such as
;;   LC_CTYPE or LC_MESSAGES since appropriate category for input
;;   method does not exist
(define locale-new
  (lambda (localestr)
    (let* ((substituted-str (cond
			     ((not (string? localestr))	;; mainly for #f
			      "C")
			     ((string=? localestr "")
			      (or (getenv "LC_ALL")
				  (getenv "LANG")
				  "C"))
			     (else
			      localestr)))
	   (canonical-str (cond
			   ((or (string=? substituted-str "C")
				(string=? substituted-str "POSIX"))
			    "en")
			   (else
			    substituted-str)))
	   ;; detect delimiter with empty part such as "ja_", "_JP" or
	   ;; "ja."
	   (invalid-pair? (lambda (orig-str pair)
			    (case (length pair)
			      ((1) #f)
			      ((2)
			       (or (zero? (string-length (car pair)))
				   (zero? (string-length (cadr pair)))))
			      (else #t))))
	   (locale-split (lambda (locale delimiter)
			   (let* ((pair (string-split locale delimiter))
				  (invalid? (invalid-pair? locale pair))
				  (former (if (and (not invalid?)
						   (not (null? pair)))
					      (car pair)
					      ""))
				  (latter (if (and (not invalid?)
						   (not (null? pair))
						   (not (null? (cdr pair))))
					      (cadr pair)
					      "")))
			     (cons former latter))))
	   (lang-territory (car (locale-split canonical-str ".")))
	   (codeset (cdr (locale-split canonical-str ".")))
	   (lang (car (locale-split lang-territory "_")))
	   (territory (cdr (locale-split lang-territory "_")))
	   (localeobj (locale-new-internal)))
      ;; set attributes with validation
      (locale-set-lang! localeobj lang)
      (locale-set-territory! localeobj territory)
      (locale-set-codeset! localeobj codeset)
      ;; make whole part invalid if one of them is invalid
      (if (and (not (string=? (locale-lang localeobj)
			      ""))
	       (string=? (locale-territory localeobj)
			 territory)
	       (string=? (locale-codeset localeobj)
			 codeset))
	  localeobj
	  (locale-new-internal "")))))

(define locale-set-lang!
  (lambda (locale lang)
    (let ((validated-lang (or (and (string? lang)
				   (= (string-length lang)
				      2)
				   lang)
			      "")))
      (locale-set-lang-internal! locale validated-lang))))

(define locale-set-territory!
  (lambda (locale territory)
    (let ((validated-territory (or (and (string? territory)
					(= (string-length territory)
					   2)
					territory)
				   "")))
      (locale-set-territory-internal! locale validated-territory))))

(define locale-lang-territory-str
  (lambda (locale)
    (let ((lang (locale-lang locale))
	  (territory (locale-territory locale)))
      (if (and (= (string-length lang)
		  2)
	       (= (string-length territory)
		  2))
	  (string-append lang "_" territory)
	  lang))))

(define locale-str
  (lambda (locale)
    (let ((lang-territory (locale-lang-territory-str locale))
	  (codeset (locale-codeset locale)))
      (if (and (<= 2
		   (string-length lang-territory))
	       (< 0
		  (string-length codeset)))
	  (string-append lang-territory "." codeset)
	  lang-territory))))

(define locale-zh-awared-lang
  (lambda (locale)
    (if (string=? (locale-lang locale)
		  "zh")
	(locale-lang-territory-str locale)
	(locale-lang locale))))

;;
;; language handling
;;

;; requires 'N_' definition
(require "iso-639-1.scm")

;; This predicate supports following langgrp formats
;;
;; "ja"          matches with the language exactly
;; "en:fr:de"    matches with one of the colon-separated language
;; "zh_TW:zh_HK" matches with one of the colon-separated lang-territory string
;; "*"           matches with any languages
;; ""            matches with no languages
(define langgroup-covers?
  (lambda (langgrp lang)
    (cond
     ((or (not (string? langgrp))
	  (not (string? lang))
	  (string=? langgrp ""))
      #f)
     ((string=? langgrp "*")
      #t)
     (else
      (let ((langs (string-split langgrp ":")))
	(member lang langs))))))

(define lang-code->lang-name
  (lambda (langcode)
    (let* ((pair (assoc langcode iso-639-1-alist))
	   (langname (and pair
			  (cdr pair))))
      (or langname
	  "-"))))

(define lang-name->lang-code
  (lambda (langname)
    (or (find (lambda (pair)
                (and (string=? (cdr pair)
                               langname)
                     (car pair)))
              iso-639-1-alist)
        "-")))

;; returns "zh_TW" of "zh_TW:zh_HK"
(define langgroup-primary-lang-code
  (lambda (localestr)
    (let* ((primary-localestr (if (not (string=? localestr ""))
				  (car (string-split localestr ":"))
				  "invalid"))  ;; intentionally invalid
	   (locale (locale-new primary-localestr))
	   (langcode (locale-zh-awared-lang locale)))
      langcode)))