diff --git a/.gitignore b/.gitignore index 93d120782..4901b510b 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ db_repository/* upload/avatar/* tmp/* .ropeproject + +# translate +*.mo diff --git a/README.md b/README.md index fde76d097..3963f0c40 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,14 @@ For testing purpose, you could also use SQLite as backend. This way you do not h ### PowerDNS-Admin +#### Requirements + +For Debian/Ubuntu: + +``` +$ sudo apt install libmysqlclient-dev libldap2-dev libldap-2.4-2 libsasl2-dev libxml2-dev libxmlsec1-dev +``` + In this installation guide, I am using CentOS 7 and run my python stuffs with *virtualenv*. If you don't have it, lets install it: ``` $ sudo yum install python-pip diff --git a/app/__init__.py b/app/__init__.py index 897db566e..1f06ee2a0 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -2,10 +2,12 @@ from flask import Flask, request, session, redirect, url_for from flask_login import LoginManager from flask_sqlalchemy import SQLAlchemy +from flask_babel import Babel, gettext app = Flask(__name__) app.config.from_object('config') app.wsgi_app = ProxyFix(app.wsgi_app) +babel = Babel(app) login_manager = LoginManager() login_manager.init_app(app) diff --git a/app/models.py b/app/models.py index 696783849..f9ede6149 100644 --- a/app/models.py +++ b/app/models.py @@ -194,7 +194,10 @@ def is_validate(self, method): return False if LDAP_TYPE == 'ad': - searchFilter = "(&(objectcategory=person)(%s=%s)(%s))" % (LDAP_USERNAMEFIELD, self.username, LDAP_FILTER) + if not LDAP_FILTER: + searchFilter = "(&(objectcategory=person)(%s=%s))" % (LDAP_USERNAMEFIELD, self.username) + else: + searchFilter = "(&(objectcategory=person)(%s=%s)(%s))" % (LDAP_USERNAMEFIELD, self.username,LDAP_FILTER) elif LDAP_TYPE == 'ldap': searchFilter = "(&(%s=%s)(%s))" % (LDAP_USERNAMEFIELD, self.username, LDAP_FILTER) diff --git a/app/static/js/gettext.js b/app/static/js/gettext.js new file mode 100644 index 000000000..8a905e6a1 --- /dev/null +++ b/app/static/js/gettext.js @@ -0,0 +1,1265 @@ +/* +Pure Javascript implementation of Uniforum message translation. +Copyright (C) 2008 Joshua I. Miller , all rights reserved + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU Library General Public License as published +by the Free Software Foundation; either version 2, 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +USA. + +=head1 NAME + +Javascript Gettext - Javascript implemenation of GNU Gettext API. + +=head1 SYNOPSIS + + // ////////////////////////////////////////////////////////// + // Optimum caching way + + + + var gt = new Gettext({ "domain" : "myDomain" }); + // rest is the same + + + // ////////////////////////////////////////////////////////// + // The reson the shortcuts aren't exported by default is because they'd be + // glued to the single domain you created. So, if you're adding i18n support + // to some js library, you should use it as so: + + if (typeof(MyNamespace) == 'undefined') MyNamespace = {}; + MyNamespace.MyClass = function () { + var gtParms = { "domain" : 'MyNamespace_MyClass' }; + this.gt = new Gettext(gtParams); + return this; + }; + MyNamespace.MyClass.prototype._ = function (msgid) { + return this.gt.gettext(msgid); + }; + MyNamespace.MyClass.prototype.something = function () { + var myString = this._("this will get translated"); + }; + + // ////////////////////////////////////////////////////////// + // Adding the shortcuts to a global scope is easier. If that's + // ok in your app, this is certainly easier. + var myGettext = new Gettext({ 'domain' : 'myDomain' }); + function _ (msgid) { + return myGettext.gettext(msgid); + } + alert( _("text") ); + + // ////////////////////////////////////////////////////////// + // Data structure of the json data + // NOTE: if you're loading via the + + // in domain.json + json_locale_data = { + "mydomain" : { + // po header fields + "" : { + "plural-forms" : "...", + "lang" : "en", + }, + // all the msgid strings and translations + "msgid" : [ "msgid_plural", "translation", "plural_translation" ], + }, + }; + // please see the included bin/po2json script for the details on this format + +This method also allows you to use unsupported file formats, so long as you can parse them into the above format. + +=item 2. Use AJAX to load language file. + +Use XMLHttpRequest (actually, SJAX - syncronous) to load an external resource. + +Supported external formats are: + +=over + +=item * Javascript Object Notation (.json) + +(see bin/po2json) + + type=application/json + +=item * Uniforum Portable Object (.po) + +(see GNU Gettext's xgettext) + + type=application/x-po + +=item * Machine Object (compiled .po) (.mo) + +NOTE: .mo format isn't actually supported just yet, but support is planned. + +(see GNU Gettext's msgfmt) + + type=application/x-mo + +=back + +=back + +=head1 METHODS + +The following methods are implemented: + + new Gettext(args) + textdomain (domain) + gettext (msgid) + dgettext (domainname, msgid) + dcgettext (domainname, msgid, LC_MESSAGES) + ngettext (msgid, msgid_plural, count) + dngettext (domainname, msgid, msgid_plural, count) + dcngettext (domainname, msgid, msgid_plural, count, LC_MESSAGES) + pgettext (msgctxt, msgid) + dpgettext (domainname, msgctxt, msgid) + dcpgettext (domainname, msgctxt, msgid, LC_MESSAGES) + npgettext (msgctxt, msgid, msgid_plural, count) + dnpgettext (domainname, msgctxt, msgid, msgid_plural, count) + dcnpgettext (domainname, msgctxt, msgid, msgid_plural, count, LC_MESSAGES) + strargs (string, args_array) + + +=head2 new Gettext (args) + +Several methods of loading locale data are included. You may specify a plugin or alternative method of loading data by passing the data in as the "locale_data" option. For example: + + var get_locale_data = function () { + // plugin does whatever to populate locale_data + return locale_data; + }; + var gt = new Gettext( 'domain' : 'messages', + 'locale_data' : get_locale_data() ); + +The above can also be used if locale data is specified in a statically included