Commits

Zhang Huangbin  committed 876530e

* Allow run-time language switch in login page, store selected
language in LDAP after success authentication.

  • Participants
  • Parent commits a7846d0

Comments (0)

Files changed (20)

 = 0.1.1 =
-    * Run-time language switch.
+    * Allow run-time language switch in login page, store selected
+      language in LDAP after success authentication.
+    * Add run-time language switch support.
     * Add enabledService={pop3secured,imapsecured,managesievesecured}.
     * Add new translation: vi_VN (Vietnamese), zh_CN, zh_TW.
     * Fixed: use 'ENINGE=' instead of 'TYPE='. Thanks peterpp @forum.

File controllers/ldap/basic.py

             web.seeother('/dashboard')
         else:
             i = web.input()
-            msg = i.get('msg', None)
+
+            adminLib = admin.Admin()
+            cur_lang = i.get('lang', cfg.general.get('lang', 'en_US'))
+            if cur_lang is not None:
+                session['lang'] = cur_lang
 
             # Show login page.
-            return render.login(msg=msg)
+            return render.login(
+                    cur_lang=cur_lang,
+                    languagemaps=adminLib.getLanguageMaps(),
+                    msg=i.get('msg'),
+                    )
 
     def POST(self):
         # Get username, password.
                 # Expire session when browser closed.
                 web.config.session_parameters['timeout'] = 600      # 10 minutes
 
-            # Per-user i18n.
-            try:
-                adminLib = admin.Admin()
-                lang = adminLib.getPreferredLanguage(userdn)
-                if lang is not False:
-                    session['lang'] = lang
-            except:
-                pass
-
             web.seeother('/dashboard')
         else:
             session['failedTimes'] += 1

File i18n/en_US/LC_MESSAGES/iredadmin.mo

Binary file modified.

File i18n/en_US/LC_MESSAGES/iredadmin.po

-# English (United States) translations for PROJECT.
+# English (United States) translations for iRedAdmin.
 # Copyright (C) 2009 ORGANIZATION
-# This file is distributed under the same license as the PROJECT project.
+# This file is distributed under the same license as the iRedAdmin project.
 # FIRST AUTHOR <EMAIL@ADDRESS>, 2009.
 #
-#, fuzzy
 msgid ""
 msgstr ""
 "Project-Id-Version: iRedAdmin 0.1.1\n"
 "Report-Msgid-Bugs-To: michaelbibby@gmail.com\n"
 "POT-Creation-Date: 2009-10-03 23:01+0800\n"
-"PO-Revision-Date: 2009-10-22 20:24+0800\n"
+"PO-Revision-Date: 2009-10-22 21:53+0800\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: en_US <LL@li.org>\n"
 "Plural-Forms: nplurals=2; plural=(n != 1)\n"
 msgid "Password"
 msgstr ""
 
-#: ../templates/default/ldap/login.html:78
+#: ../templates/default/ldap/login.html:77
+#: ../templates/default/ldap/macros.html:103
+msgid "Preferred language"
+msgstr ""
+
+#: ../templates/default/ldap/login.html:91
 msgid "Remember me"
 msgstr ""
 
-#: ../templates/default/ldap/login.html:78
+#: ../templates/default/ldap/login.html:91
 msgid "Log me in automatically each time I visit."
 msgstr ""
 
-#: ../templates/default/ldap/login.html:84
+#: ../templates/default/ldap/login.html:97
 msgid "Login"
 msgstr ""
 
 msgid "Telephone Number"
 msgstr ""
 
-#: ../templates/default/ldap/macros.html:103
-msgid "Default language"
-msgstr ""
-
 #: ../templates/default/ldap/macros.html:124
 msgid "Enable this domain"
 msgstr ""

File i18n/fr_FR/LC_MESSAGES/iredadmin.mo

Binary file modified.

File i18n/fr_FR/LC_MESSAGES/iredadmin.po

 # Copyright (C) 2009 ORGANIZATION
-# This file is distributed under the same license as the PROJECT project.
+# This file is distributed under the same license as the iRedAdmin project.
 # FIRST AUTHOR <EMAIL@ADDRESS>, 2009.
 #
 msgid ""
 "Project-Id-Version: iRedAdmin 0.1.1\n"
 "Report-Msgid-Bugs-To: michaelbibby@gmail.com\n"
 "POT-Creation-Date: 2009-10-04 00:45+0800\n"
-"PO-Revision-Date: 2009-10-22 20:24+0800\n"
+"PO-Revision-Date: 2009-10-22 21:53+0800\n"
 "Last-Translator: Mael LE SAOUT <mael.lesaout@gmail.com>\n"
 "Language-Team: fr_FR <LL@li.org>\n"
 "Plural-Forms: nplurals=2; plural=(n > 1)\n"
 msgstr "Besoin de plus de fonctionnalités?"
 
 #: ../templates/default/ldap/dashboard.html:61
-#, fuzzy
 msgid ""
 "Purchase Full-featured Edition to support iRedMail project and get more "
 "features."
 msgid "Password"
 msgstr "Mot de passe"
 
-#: ../templates/default/ldap/login.html:78
+#: ../templates/default/ldap/login.html:77
+#: ../templates/default/ldap/macros.html:103
+msgid "Preferred language"
+msgstr "Langage par défaut"
+
+#: ../templates/default/ldap/login.html:91
 msgid "Remember me"
 msgstr "Se souvenir de moi"
 
-#: ../templates/default/ldap/login.html:78
+#: ../templates/default/ldap/login.html:91
 msgid "Log me in automatically each time I visit."
 msgstr "Me connecter automatiquement à chaque fois que je visite."
 
-#: ../templates/default/ldap/login.html:84
+#: ../templates/default/ldap/login.html:97
 msgid "Login"
 msgstr "Connexion"
 
 msgid "Telephone Number"
 msgstr "Numéro de téléphone"
 
-#: ../templates/default/ldap/macros.html:103
-msgid "Default language"
-msgstr "Langage par défaut"
-
 #: ../templates/default/ldap/macros.html:124
 msgid "Enable this domain"
 msgstr "Activer ce domaine"
 msgstr "La mise à jour du profil a échoué."
 
 #: ../templates/default/ldap/msgHandlers.html:90
-#, fuzzy
 msgid "No domain under control."
 msgstr "Tous les domaines sous votre controle."
 

File i18n/iredadmin.po

 msgstr ""
 "Project-Id-Version: PROJECT VERSION\n"
 "Report-Msgid-Bugs-To: michaelbibby@gmail.com\n"
-"POT-Creation-Date: 2009-10-22 20:24+0800\n"
+"POT-Creation-Date: 2009-10-22 21:53+0800\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 msgid "Password"
 msgstr ""
 
-#: ../templates/default/ldap/login.html:78
+#: ../templates/default/ldap/login.html:77
+#: ../templates/default/ldap/macros.html:103
+msgid "Preferred language"
+msgstr ""
+
+#: ../templates/default/ldap/login.html:91
 msgid "Remember me"
 msgstr ""
 
-#: ../templates/default/ldap/login.html:78
+#: ../templates/default/ldap/login.html:91
 msgid "Log me in automatically each time I visit."
 msgstr ""
 
-#: ../templates/default/ldap/login.html:84
+#: ../templates/default/ldap/login.html:97
 msgid "Login"
 msgstr ""
 
 msgid "Telephone Number"
 msgstr ""
 
-#: ../templates/default/ldap/macros.html:103
-msgid "Default language"
-msgstr ""
-
 #: ../templates/default/ldap/macros.html:124
 msgid "Enable this domain"
 msgstr ""

File i18n/translation.sh

             -D ${DOMAIN} \
             -d . \
             -l ${lang}
+
+        # Add project name and version number.
         perl -pi -e 's#(.*Project-Id-Version:).*#${1} iRedAdmin $ENV{version}\\n"#' ${lang}/LC_MESSAGES/${DOMAIN}.po
+
+        # Remove 'fuzzy' tag.
+        perl -pi -e 's/#, fuzzy//' ${lang}/LC_MESSAGES/${DOMAIN}.po
     done
 }
 

File i18n/vi_VN/LC_MESSAGES/iredadmin.mo

Binary file modified.

File i18n/vi_VN/LC_MESSAGES/iredadmin.po

 "Project-Id-Version: iRedAdmin 0.1.1\n"
 "Report-Msgid-Bugs-To: michaelbibby@gmail.com\n"
 "POT-Creation-Date: 2009-10-02 01:16+0800\n"
-"PO-Revision-Date: 2009-10-22 20:24+0800\n"
+"PO-Revision-Date: 2009-10-22 21:53+0800\n"
 "Last-Translator: Lâm Minh Thông <lmthong@gmail.com>\n"
 "Language-Team: vi_VN <LL@li.org>\n"
 "Plural-Forms: nplurals=1; plural=0\n"
 
 #: ../templates/default/ldap/error404.html:31
 #: ../templates/default/ldap/error404.html:37
-#, fuzzy
 msgid "Page not found."
 msgstr "Không tìm thấy trang (%s)."
 
 msgid "Password"
 msgstr "Mật khẩu"
 
-#: ../templates/default/ldap/login.html:78
+#: ../templates/default/ldap/login.html:77
+#: ../templates/default/ldap/macros.html:103
+msgid "Preferred language"
+msgstr "Ngôn ngữ mặc định"
+
+#: ../templates/default/ldap/login.html:91
 msgid "Remember me"
 msgstr "Ghi nhớ tài khoản này"
 
-#: ../templates/default/ldap/login.html:78
+#: ../templates/default/ldap/login.html:91
 msgid "Log me in automatically each time I visit."
 msgstr "Giúp tôi tự động đăng nhập."
 
-#: ../templates/default/ldap/login.html:84
+#: ../templates/default/ldap/login.html:97
 msgid "Login"
 msgstr "Đăng nhập"
 
 msgid "Telephone Number"
 msgstr "Số điện thoại"
 
-#: ../templates/default/ldap/macros.html:103
-msgid "Default language"
-msgstr "Ngôn ngữ mặc định"
-
 #: ../templates/default/ldap/macros.html:124
 msgid "Enable this domain"
 msgstr "Kích hoạt tên miền này"
 msgstr "Cập nhật thông tin không thành công."
 
 #: ../templates/default/ldap/msgHandlers.html:90
-#, fuzzy
 msgid "No domain under control."
 msgstr "Bạn có thể quản lý tất cả các tên miền."
 

File i18n/zh_CN/LC_MESSAGES/iredadmin.mo

Binary file modified.

File i18n/zh_CN/LC_MESSAGES/iredadmin.po

 "Project-Id-Version: iRedAdmin 0.1.1\n"
 "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
 "POT-Creation-Date: 2009-10-13 14:15+0800\n"
-"PO-Revision-Date: 2009-10-22 20:24+0800\n"
+"PO-Revision-Date: 2009-10-22 21:53+0800\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: zh_CN <LL@li.org>\n"
 "Plural-Forms: nplurals=1; plural=0\n"
 msgstr ""
 
 #: ../templates/default/ldap/dashboard.html:65
-#, fuzzy
 msgid "Unlimited number of mail lists"
 msgstr "邮件列表的最大数量"
 
 #: ../templates/default/ldap/dashboard.html:66
-#, fuzzy
 msgid "Unlimited number of mail aliases"
 msgstr "邮件别名的最大数量"
 
 #: ../templates/default/ldap/dashboard.html:67
-#, fuzzy
 msgid "Per-user mail forwarding control"
 msgstr "针对单个用户的邮件转发控制"
 
 #: ../templates/default/ldap/dashboard.html:68
-#, fuzzy
 msgid "Per-user service control"
 msgstr "服务控制"
 
 msgid "Password"
 msgstr "密码"
 
-#: ../templates/default/ldap/login.html:78
+#: ../templates/default/ldap/login.html:77
+#: ../templates/default/ldap/macros.html:103
+msgid "Preferred language"
+msgstr "偏好的语言"
+
+#: ../templates/default/ldap/login.html:91
 msgid "Remember me"
 msgstr "记住我"
 
-#: ../templates/default/ldap/login.html:78
+#: ../templates/default/ldap/login.html:91
 msgid "Log me in automatically each time I visit."
 msgstr "每次访问时自动登录"
 
-#: ../templates/default/ldap/login.html:84
+#: ../templates/default/ldap/login.html:97
 msgid "Login"
 msgstr "登录"
 
 msgid "Telephone Number"
 msgstr "电话号码"
 
-#: ../templates/default/ldap/macros.html:103
-msgid "Default language"
-msgstr "默认语言"
-
 #: ../templates/default/ldap/macros.html:124
 msgid "Enable this domain"
 msgstr "启用这个域"
 msgstr "为域指派管理员"
 
 #: ../templates/default/ldap/macros.html:157
-#, fuzzy
 msgid "If no admin assigned, you can manage it with global admin."
 msgstr "如果没有指派管理员,您仍然可以使用全局管理员帐号进行管理。"
 
 msgstr "编辑用户属性"
 
 #: ../templates/default/ldap/user_profile.html:52
-#, fuzzy
 msgid "Reset Password"
 msgstr "重置密码"
 
 msgstr "查看域内的用户:"
 
 #: ../templates/default/ldap/users.html:39
-#, fuzzy
 msgid "Select one domain"
 msgstr "选择一个域"
 

File libs/iredbase.py

 
 web.config.session_parameters['cookie_name'] = 'iRedAdmin-OSE'
 web.config.session_parameters['cookie_domain'] = None
-web.config.session_parameters['timeout'] = 600  # 10 minutes
 web.config.session_parameters['ignore_expiry'] = False
 web.config.session_parameters['ignore_change_ip'] = False
 

File libs/iredutils.py

     # Init translation.
     if cfg.allTranslations.has_key(lang):
         translation = cfg.allTranslations[lang]
-    elif lang == 'en_US' or lang is None:
+    elif lang is None:
         translation = gettext.NullTranslations()
     else:
         try:

File libs/ldaplib/auth.py

 import ldap, ldap.filter
 
 cfg = web.iredconfig
+session = web.config.get('_session')
 
 # Used for user auth.
 def Auth(dn, pw, session=web.config.get('_session')):
                 else:
                     pass
 
+                # Update preferred language.
+                try:
+                    conn.modify_s(dn, [( ldap.MOD_REPLACE, 'preferredlanguage', web.safestr(session.get('lang', 'en_US')) )])
+                except:
+                    pass
+
                 return True
             else:
                 return False

File templates/default/ldap/domain_profile.html

                     <li>
                         <span><strong>{{ _('Domain Name') }}</strong></span>
                         <span>
-                            <select id="domainSelect" name="domainName" onchange="changeDomain(this, baseurl='{{ctx.homepath}}/profile/domain/{{profile_type}}/');">
+                            <select id="domainSelect" name="domainName" onchange="changeUrl(this, baseurl='{{ctx.homepath}}/profile/domain/{{profile_type}}/');">
                                 {% for d in allDomains %}
                                 <option value="{{d[1].domainName[0]}}" {% if cur_domain == d[1].domainName[0] %}selected{%endif%}>{{d[1].domainName[0]}}</option>
                                 {% endfor %}

File templates/default/ldap/layout.html

             }
         }
 
-        function changeDomain(domain, baseurl) {
+        function changeUrl(domain, baseurl) {
             if ( domain.options[domain.selectedIndex].value != 'none' ) {
                 location.href = baseurl + domain.options[domain.selectedIndex].value;
             }

File templates/default/ldap/login.html

                 </div>
 
                 <div class="sf-set">
+                    <div class="sf-box text required">
+                        <label><span>{{ _('Preferred language') }}</span></label><br />
+                        <span class="fld-input">
+                            <select id="selectLang" name="lang" onchange="changeUrl(this, baseurl='{{ctx.homepath}}/login?lang=');">
+                            {% for lang in languagemaps %}
+                                <option value="{{lang}}" {% if lang == cur_lang %}selected{%endif%}>{{languagemaps[lang]}}</option>
+                            {% endfor %}
+                            </select>
+                        </span>
+                    </div>
+                </div>
+
+                <div class="sf-set">
                     <div class="sf-box checkbox">
                         <span class="fld-input"><input type="checkbox" name="save_pass" value="yes" /></span>
                         <label><span>{{ _('Remember me')}} </span>{{ _('Log me in automatically each time I visit.') }}</label>

File templates/default/ldap/macros.html

     <fieldset class="frm-group {% if firstitem == 'yes' %}group1{% endif %}">
         <div class="sf-set {% if firstitem == 'yes' %}set1{% endif %}">
             <div class="sf-box select">
-                <label><span>{{ _('Default language') }}</span></label>
+                <label><span>{{ _('Preferred language') }}</span></label>
                 <span class="fld-input">
                     <select name="preferredLanguage">
                         {% for lang in languagemaps %}

File templates/default/ldap/users.html

 {% block id_welcome %}
 <span>{{ _('View users under domain:') }} </span>
 <span>
-    <select id="domainSelect" name="domainName" onchange="changeDomain(this, baseurl='{{ctx.homepath}}/users/');">
+    <select id="domainSelect" name="domainName" onchange="changeUrl(this, baseurl='{{ctx.homepath}}/users/');">
         <option value="none" {% if cur_domain is sameas none %}selected{%endif%}>{{ _('Select one domain') }}</option>
         {% for d in allDomains %}
             <option value="{{d[1].domainName[0]}}" {% if cur_domain == d[1].domainName[0] %}selected{%endif%}>{{d[1].domainName[0]}}</option>