-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
255 lines (233 loc) · 4.87 KB
/
utils.py
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
# -*- coding: UTF-8 -*-
# Copyright (C) 2000-2003 Juan David Ibáñez Palomar <[email protected]>
#
# 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/>.
# Import from itools
from itools import get_abspath
from itools.i18n import AcceptLanguageType, init_language_selector
from itools.gettext import get_domain, register_domain
# Import from Zope
from App.Common import package_home
# Import from Localizer
from patches import get_request
# Package home
ph = package_home(globals())
# Initializes a list with the charsets
charsets = [ x.strip() for x in open(ph + '/charsets.txt').readlines() ]
###########################################################################
# Language negotiation
###########################################################################
def lang_negotiator(available_languages):
"""Receives two ordered lists, the list of user preferred languages and
the list of available languages. Returns the first user pref. language
that is available, if none is available returns None.
"""
request = get_request()
if request is None:
return None
try:
accept = request['AcceptLanguage']
except KeyError:
return None
return accept.select_language(available_languages)
init_language_selector(lang_negotiator)
###########################################################################
# Provide an API to access translations stored as MO files in the 'locale'
# directory.
###########################################################################
class DomainAware(object):
def __init__(self, namespace):
mname = namespace['__name__']
domain = get_abspath('locale', mname=mname)
self.class_domain = domain
register_domain(domain, domain)
def gettext(self, message, language=None):
domain = get_domain(self.class_domain)
if language is None:
languages = domain.get_languages()
language = select_language(languages)
return domain.gettext(message, language)
_ = DomainAware(globals()).gettext
###########################################################################
# Defines strings that must be internationalized
###########################################################################
# Tabs of the management screens
u'Contents'
u'View'
u'Properties'
u'Security'
u'Undo'
u'Ownership'
u'Find'
# Languages (FIXME This will be removed once we upgrade to itools 0.60)
u'Abkhazian'
u'Afar'
u'Afrikaans'
u'Albanian'
u'Amharic'
u'Arabic'
u'Armenian'
u'Assamese'
u'Aymara'
u'Azerbaijani'
u'Bashkir'
u'Basque'
u'Bengali'
u'Bhutani'
u'Bihari'
u'Bislama'
u'Bosnian'
u'Breton'
u'Bulgarian'
u'Burmese'
u'Belarusian'
u'Cambodian'
u'Catalan'
u'Chinese'
u'Chinese/China'
u'Chinese/Taiwan'
u'Cornish'
u'Corsican'
u'Croatian'
u'Czech'
u'Danish'
u'Dutch'
u'Dutch/Belgium'
u'English'
u'English/United Kingdom'
u'English/United States'
u'Esperanto'
u'Estonian'
u'Faroese'
u'Fiji'
u'Finnish'
u'French'
u'French/Belgium'
u'French/Canada'
u'French/France'
u'French/Switzerland'
u'Frisian'
u'Galician'
u'Georgian'
u'German'
u'German/Austria'
u'German/Germany'
u'German/Switzerland'
u'Greek'
u'Greenlandic'
u'Guarani'
u'Gujarati'
u'Hausa'
u'Hebrew'
u'Hindi'
u'Hungarian'
u'Icelandic'
u'Indonesian'
u'Interlingua'
u'Interlingue'
u'Inuktitut'
u'Inupiak'
u'Irish'
u'Italian'
u'Japanese'
u'Javanese'
u'Kannada'
u'Kashmiri'
u'Kazakh'
u'Kinyarwanda'
u'Kirghiz'
u'Kirundi'
u'Korean'
u'Kurdish'
u'Laothian'
u'Latin'
u'Latvian'
u'Lingala'
u'Lithuanian'
u'Luxembourgish'
u'Macedonian'
u'Malagasy'
u'Malay'
u'Malayalam'
u'Maltese'
u'Maori'
u'Marathi'
u'Moldavian'
u'Mongolian'
u'Nauru'
u'Nepali'
u'Northern Saami'
u'Norwegian'
u'Occitan'
u'Oriya'
u'Oromo'
u'Pashto'
u'Persian'
u'Polish'
u'Portuguese'
u'Portuguese/Brazil'
u'Punjabi'
u'Quechua'
u'Rhaeto-Romance'
u'Romanian'
u'Russian'
u'Samoan'
u'Sangho'
u'Sanskrit'
u'Scots Gaelic'
u'Serbian'
u'Serbo-Croatian'
u'Sesotho'
u'Setswana'
u'Shona'
u'Sindhi'
u'Sinhalese'
u'Siswati'
u'Slovak'
u'Slovenian'
u'Somali'
u'Spanish'
u'Spanish/Argentina'
u'Spanish/Colombia'
u'Spanish/Mexico'
u'Spanish/Spain'
u'Sundanese'
u'Swahili'
u'Swedish'
u'Tagalog'
u'Tajik'
u'Tamil'
u'Tatar'
u'Telugu'
u'Thai'
u'Tibetan'
u'Tigrinya'
u'Tonga'
u'Tsonga'
u'Turkish'
u'Turkmen'
u'Twi'
u'Uighur'
u'Ukrainian'
u'Urdu'
u'Uzbek'
u'Vietnamese'
u'Volapuk'
u'Welsh'
u'Wolof'
u'Xhosa'
u'Yiddish'
u'Yoruba'
u'Zhuang'
u'Zulu'