Browse Source

move localization to customization submodule

this makes every (translateable) string customizable: just add a translation
english translations will override the strings in source
parent
commit
bd2bea00c0
No known key found for this signature in database

+ 3
- 1
c3smembership/__init__.py View File

@@ -23,6 +23,7 @@ from c3smembership.presentation.views.dashboard import (
23 23
 from c3smembership.presentation.views.membership_listing import (
24 24
     membership_content_size_provider
25 25
 )
26
+from c3smembership.i18n import enforcing_locale_negotiator
26 27
 
27 28
 
28 29
 __version__ = open(os.path.join(os.path.abspath(
@@ -50,6 +51,7 @@ def main(global_config, **settings):
50 51
 
51 52
     # using a custom request with user information
52 53
     config.set_request_factory(RequestWithUserAttribute)
54
+    config.set_locale_negotiator(enforcing_locale_negotiator)
53 55
 
54 56
     config.include('pyramid_mailer')
55 57
     config.include('pyramid_chameleon')
@@ -59,7 +61,7 @@ def main(global_config, **settings):
59 61
     config.add_translation_dirs(
60 62
         'colander:locale/',
61 63
         'deform:locale/',
62
-        'c3smembership:locale/')
64
+        'c3smembership:../customization/locale/')
63 65
 
64 66
     config.add_static_view('static_deform', 'deform:static')
65 67
     config.add_static_view(

+ 41
- 0
c3smembership/i18n.py View File

@@ -0,0 +1,41 @@
1
+import customization
2
+
3
+def enforcing_locale_negotiator(request):
4
+    """ The :term:`custom locale negotiator`. Returns a locale name.
5
+
6
+    - First, the negotiator looks for the ``_LOCALE_`` attribute of
7
+      the request object (possibly set by a view or a listener for an
8
+      :term:`event`).
9
+
10
+    - Then it looks for the ``request.params['_LOCALE_']`` value.
11
+
12
+    - Then it looks for the ``request.cookies['_LOCALE_']`` value.
13
+
14
+    - Then it looks for the ``Accept-Language`` header value,
15
+      which is set by the user in his/her browser configuration.
16
+
17
+    - Finally, if the locale could not be determined via any of
18
+      the previous checks, the negotiator returns the
19
+      :term:`default locale name`.
20
+
21
+    - In all cases it enforces the locale being in customization.translations, falling back to default_locale_name  if the negotiation so far lead to something else
22
+    """
23
+
24
+    name = '_LOCALE_'
25
+    locale_name = getattr(request, name, None)
26
+    if locale_name is None:
27
+        locale_name = request.params.get(name)
28
+        if locale_name is None:
29
+            locale_name = request.cookies.get(name)
30
+            if locale_name is None:
31
+                locale_name = request.accept_language.best_match(
32
+                    customization.locale_country_mapping.keys(), request.registry.settings.default_locale_name)
33
+                if not request.accept_language:
34
+                    # If browser has no language configuration
35
+                    # the default locale name is returned.
36
+                    locale_name = request.registry.settings.default_locale_name
37
+
38
+    if locale_name not in customization.translations:
39
+        locale_name = request.registry.settings.default_locale_name
40
+        
41
+    return locale_name

+ 0
- 1048
c3smembership/locale/c3smembership.pot
File diff suppressed because it is too large
View File


BIN
c3smembership/locale/de/LC_MESSAGES/c3smembership.mo View File


+ 0
- 1169
c3smembership/locale/de/LC_MESSAGES/c3smembership.po
File diff suppressed because it is too large
View File


BIN
c3smembership/locale/de/LC_MESSAGES/deform.mo View File


+ 0
- 118
c3smembership/locale/de/LC_MESSAGES/deform.po View File

@@ -1,118 +0,0 @@
1
-# German translations for deform.
2
-# Copyright (C) 2010 Charlie Clark
3
-# Copyright (C) 2011 Jan Dittberner
4
-# This file is distributed under the same license as the deform project.
5
-msgid ""
6
-msgstr ""
7
-"Project-Id-Version: deform 0.6\n"
8
-"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
9
-"POT-Creation-Date: 2012-03-30 16:17+0200\n"
10
-"PO-Revision-Date: 2011-11-08 15:51+0100\n"
11
-"Last-Translator: Jan Dittberner <jan@dittberner.info>\n"
12
-"Language-Team: repoze developers <repoze-dev@lists.repoze.org>\n"
13
-"Plural-Forms: nplurals=2; plural=(n != 1)\n"
14
-"MIME-Version: 1.0\n"
15
-"Content-Type: text/plain; charset=utf-8\n"
16
-"Content-Transfer-Encoding: 8bit\n"
17
-"Generated-By: Babel 0.9.6\n"
18
-
19
-#: deform/schema.py:100
20
-msgid "${value} is not a dictionary"
21
-msgstr "$[value} ist kein Dictionary"
22
-
23
-#: deform/schema.py:107
24
-msgid "${value} has no ${key} key"
25
-msgstr "Es gibt keinen Schlüssel ${key} für ${value}"
26
-
27
-#: deform/schema.py:146
28
-msgid "${value} is not iterable"
29
-msgstr " ${value} ist nicht iterierbar"
30
-
31
-#: deform/schema.py:150
32
-msgid "Required"
33
-msgstr "Pflichtangabe"
34
-
35
-#: deform/widget.py:779
36
-msgid "Fields did not match"
37
-msgstr "Die Felder sind nicht gleich"
38
-
39
-#: deform/widget.py:780
40
-msgid "Value"
41
-msgstr "Wert"
42
-
43
-#: deform/widget.py:781
44
-msgid "Confirm Value"
45
-msgstr "Wert bestätigen"
46
-
47
-#: deform/widget.py:829
48
-msgid "Password did not match confirm"
49
-msgstr "Passwort und Passwortbestätigung stimmen nicht überein"
50
-
51
-#: deform/widget.py:980
52
-msgid "Add ${subitem_title}"
53
-msgstr "${subitem_title} hinzufügen"
54
-
55
-#: deform/widget.py:1239
56
-msgid "Incomplete date"
57
-msgstr "Unvollständig"
58
-
59
-#: deform/templates/checked_password.pt:5
60
-msgid "Password"
61
-msgstr "Passwort"
62
-
63
-#: deform/templates/checked_password.pt:10
64
-msgid "Confirm Password"
65
-msgstr "Passwortbestätigung"
66
-
67
-#: deform/templates/dateparts.pt:5 deform/templates/readonly/dateparts.pt:2
68
-msgid "Year"
69
-msgstr "Jahr"
70
-
71
-#: deform/templates/dateparts.pt:12 deform/templates/readonly/dateparts.pt:4
72
-msgid "Month"
73
-msgstr "Monat"
74
-
75
-#: deform/templates/dateparts.pt:19 deform/templates/readonly/dateparts.pt:6
76
-msgid "Day"
77
-msgstr "Tag"
78
-
79
-#: deform/templates/form.pt:19
80
-msgid "There was a problem with your submission"
81
-msgstr "Es gab ein Problem mit Ihren Angaben"
82
-
83
-#: deform/templates/form.pt:21
84
-msgid "Errors have been highlighted below"
85
-msgstr "Die Fehler wurden weiter unten hervorgehoben"
86
-
87
-#: deform/templates/mapping.pt:6
88
-msgid "There was a problem with this section"
89
-msgstr "Es gab ein Problem in diesem Bereich"
90
-
91
-#. Default: en
92
-#: deform/templates/richtext.pt:15
93
-msgid "language-code"
94
-msgstr "de"
95
-
96
-#: deform/templates/sequence_item.pt:6
97
-msgid "Remove"
98
-msgstr "Entfernen"
99
-
100
-#: deform/templates/readonly/checked_password.pt:2
101
-#: deform/templates/readonly/password.pt:2
102
-msgid "Password not displayed."
103
-msgstr "Passwort wird nicht angezeigt."
104
-
105
-#: deform/templates/readonly/file_upload.pt:7
106
-msgid "Read-only."
107
-msgstr "Nur lesen. "
108
-
109
-#: deform/templates/readonly/radio_choice.pt:4
110
-#: deform/templates/readonly/select.pt:3
111
-msgid "Selected"
112
-msgstr "Ausgewählt"
113
-
114
-#: deform/templates/readonly/radio_choice.pt:5
115
-#: deform/templates/readonly/select.pt:4
116
-msgid "Not Selected"
117
-msgstr "Nicht ausgewählt"
118
-

+ 5
- 5
setup.cfg View File

@@ -12,16 +12,16 @@ statistics = true
12 12
 
13 13
 [extract_messages]
14 14
 add_comments = TRANSLATORS:
15
-output_file = c3smembership/locale/c3smembership.pot
15
+output_file = customization/locale/c3smembership.pot
16 16
 width = 80
17 17
 
18 18
 [init_catalog]
19 19
 domain = c3smembership
20
-input_file = c3smembership/locale/c3smembership.pot
21
-output_dir = c3smembership/locale
20
+input_file = customization/locale/c3smembership.pot
21
+output_dir = customization/locale
22 22
 
23 23
 [update_catalog]
24 24
 domain = c3smembership
25
-input_file = c3smembership/locale/c3smembership.pot
26
-output_dir = c3smembership/locale
25
+input_file = customization/locale/c3smembership.pot
26
+output_dir = customization/locale
27 27
 previous = true

Loading…
Cancel
Save