* Makefile creates/updates po/davadmin.pot, .po, and .mo files
 * admin/i18n.inc.php sets the locale and puts it in the session
 * admin/common.inc.php and admin/getgroups.php use admin/i18n.inc.php
 * po/pot.sed replaces generated header of po/davadmin.pot
This commit is contained in:
Jan Dittberner 2007-11-30 21:25:52 +00:00
parent 83251502e9
commit a978fb5ef0
6 changed files with 344 additions and 14 deletions

View File

@ -23,21 +23,71 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA.
VERSION := 0.2
PROJECT := davadmin
SRCFILES := $(wildcard admin/*.php)
APISRC := $(SRCFILES:,= )
TEMPDIR := $(shell mktemp -t -d davadmin.XXXXXXXXXX)
XSRCFILES := $(patsubst %,$(TEMPDIR)/%,$(SRCFILES))
TRANSLANG := de
POSRC := po
POFILES := $(foreach lang,$(TRANSLANG),$(POSRC)/$(lang).po)
MOFILES := $(patsubst %.po,%.mo,$(POFILES))
POT=$(POSRC)/$(PROJECT).pot
.PHONY: all
all: $(POT) $(MOFILES) $(TEMPDIR)/delete
$(MOFILES): %.mo: %.po
@echo "msgfmt: $@"
msgfmt -o$@ $<
$(POFILES): %: $(POT)
@echo "msgmerge: $@"
msgmerge -U $@ $(POT)
touch $@
$(POT): $(XSRCFILES) po/pot.sed
@echo "xgettext: $@"
cd $(TEMPDIR) && \
xgettext --default-domain=$(PROJECT) --language=php \
--from-code=UTF-8 \
--msgid-bugs-address="jan@dittberner.info" -o- $(SRCFILES) \
| sed -f $(CURDIR)/po/pot.sed \
> $(CURDIR)/$@
for pofile in $(POFILES); do \
if test ! -f $(CURDIR)/$${pofile}; then \
cp $(CURDIR)/$@ $(CURDIR)/$${pofile}; \
fi; \
done
.INTERMEDIATE: $(XSRCFILES)
$(XSRCFILES): $(TEMPDIR)/%: %
@echo "processing: $<"
mkdir -p $(@D)
cp $< $@
$(TEMPDIR)/delete:
rm -rf $(TEMPDIR)
.PHONY: apidoc
VERSION=0.2
PROJECT=webdavadmin
SRCFILES=admin/common.inc.php,admin/directories.php,admin/getgroups.php,admin/index.php,admin/users.php
apidoc:
if [ -d apidoc ]; then rm -r apidoc; fi
phpdoc -f $(SRCFILES) -t apidoc --undocumentedelements on -s
phpdoc -f $(APISRC) -t apidoc --undocumentedelements on -s
clean:
.PHONY: clean distclean
clean: $(TEMPDIR)/delete
find -name '*~' -type f -exec rm {} \;
distclean: clean
if [ -d apidoc ]; then rm -r apidoc; fi
RELPREFIX := $(PROJECT)-$(VERSION)
dist: distclean
cd .. ; tar czf $(PROJECT)-$(VERSION).tar.gz $(PROJECT)-$(VERSION)
cd .. ; if test ! -d $(RELPREFIX); then \
ln -s trunk $(RELPREFIX)-dev; \
tar czh --exclude=.svn -f $(RELPREFIX)-dev.tar.gz $(RELPREFIX)-dev; \
rm -f $(RELPREFIX)-dev; \
else \
tar czhf $(PROJECT)-$(VERSION).tar.gz $(PROJECT)-$(VERSION); \
fi

View File

@ -27,6 +27,9 @@
* 02110-1301 USA.
*/
/** Include common internationalization code. */
require_once("i18n.inc.php");
if (!isset($_SERVER['DavAdminConfDir'])) {
header('HTTP/1.0 500 Internal Server Error');
header('Status: 500 Internal Server Error');
@ -79,7 +82,7 @@ function getFullPath($dirname) {
$errmsgs = array();
if (!isset($davconfig['digest.file'])) {
array_push($errmsgs,
_("digest.file is not defined."));
sprintf(_("%s is not defined."), "digest.file"));
} elseif (!is_readable($davconfig['digest.file']) ||
!is_writable($davconfig['digest.file'])) {
array_push($errmsgs,
@ -87,7 +90,7 @@ if (!isset($davconfig['digest.file'])) {
}
if (!isset($davconfig['group.file'])) {
array_push($errmsgs,
_("group.file is not defined."));
sprintf(_("%s is not defined."), "group.file"));
} elseif (!is_readable($davconfig['group.file']) ||
!is_writable($davconfig['group.file'])) {
array_push($errmsgs,
@ -95,7 +98,7 @@ if (!isset($davconfig['group.file'])) {
}
if (!isset($davconfig['namemap.file'])) {
array_push($errmsgs,
_("namemap.file is not defined."));
sprintf(_("%s is not defined."), "namemap.file"));
} elseif (!is_readable($davconfig['namemap.file']) ||
!is_writable($davconfig['namemap.file'])) {
array_push($errmsgs,
@ -103,7 +106,7 @@ if (!isset($davconfig['namemap.file'])) {
}
if (!isset($davconfig['dav.dir'])) {
array_push($errmsgs,
_("dav.dir is not defined."));
sprintf(_("%s is not defined."), "dav.dir"));
} elseif (!is_dir($davconfig['dav.dir']) ||
!is_readable($davconfig['dav.dir']) ||
!is_writable($davconfig['dav.dir'])) {
@ -112,11 +115,11 @@ if (!isset($davconfig['dav.dir'])) {
}
if (empty($davconfig['dav.realm'])) {
array_push($errmsgs,
_("dav.realm is not defined."));
sprintf(_("%s is not defined."), "dav.realm"));
}
if (empty($davconfig['dav.uri'])) {
array_push($errmsgs,
_("dav.uri is not defined."));
sprintf(_("%s is not defined."), "dav.uri"));
}
if (!empty($errmsgs)) {
errorAsHtml(implode("<br />", $errmsgs));

View File

@ -27,6 +27,9 @@
* 02110-1301 USA.
*/
/** Include common internationalization code. */
require_once("i18n.inc.php");
if (!isset($_SERVER['DavAdminConfDir'])) {
header('HTTP/1.0 500 Internal Server Error');
header('Status: 500 Internal Server Error');

144
admin/i18n.inc.php Normal file
View File

@ -0,0 +1,144 @@
<?php
/**
* Internationalization code for DAVAdmin.
*
* @author Jan Dittberner <jan@dittberner.info>
* @version $Id$
* @license GPL
* @package DAVAdmin
*
* Copyright (c) 2007 Jan Dittberner
*
* This file is part of DAVAdmin.
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*/
/**
* Gets the language data.
*/
function get_language_data() {
static $supportedLanguages = array();
static $defaultCountry = array();
if (empty($supportedLanguages)) {
/* English */
$supportedLanguages['en']['US']['description'] = 'English (US)';
$supportedLanguages['en']['GB']['description'] = 'English (UK)';
$defaultCountry['en'] = 'US';
/* German */
$supportedLanguages['de']['DE']['description'] = 'Deutsch';
$defaultCountry['de'] = 'DE';
}
return array($supportedLanguages, $defaultCountry);
}
function _setlocale($category, $locale) {
if (($ret = setlocale($category, $locale)) !== false) {
return $ret;
}
/* Try just selecting the language */
if (($i = strpos($locale, '_')) !== false
&& ($ret = setlocale($category, substr($locale, 0, $i))) !== false) {
return $ret;
} else if (($i = strpos($locale, '_')) === false) {
list($languages, $defcountries) = get_language_data();
$locale = $locale . "_" . $defcountries[$locale];
if (($ret = setlocale($category, substr($locale, 0, $i))) !== false) {
return $ret;
}
}
/*
* Try appending some character set names; some systems (like FreeBSD)
* need this. Some require a format with hyphen (eg. Gentoo) and others
* without (eg. FreeBSD).
*/
foreach (array('UTF-8', 'UTF8', 'utf8',
'ISO8859-1', 'ISO8859-2', 'ISO8859-5', 'ISO8859-7',
'ISO8859-9', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-5',
'ISO-8859-7', 'ISO-8859-9', 'ISO-8859-15',
'EUC', 'Big5') as $charset) {
if (($ret = setlocale($category, $locale . '.' . $charset)) !== false) {
return $ret;
}
}
echo "unable to select a valid locale code";
return false;
}
function _get_supported_language_code($code, $fallback = true) {
static $supportedLanguages;
static $defaultCountry;
if (!isset($supportedLanguages)) {
list($supportedLanguages, $defaultCountry) = get_language_data();
}
list ($language, $country) = preg_split('/[-_]/', "${code}_");
$country = strtoupper($country);
if ((empty($country) || !isset($supportedLanguages[$language][$country]))
&& isset($defaultCountry[$language])) {
/* Use default country if none specified or particular country not
* supported */
$country = $defaultCountry[$language];
}
if (isset($supportedLanguages[$language][$country])) {
return "${language}_${country}";
}
if ($fallback) {
return 'en_US';
} else {
return null;
}
}
function _http_negotiate_locale() {
$accepted = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (!empty($accepted)) {
foreach(explode(",", $accepted) as $code) {
$languageCode = _get_supported_language_code($code, false);
if (isset($languageCode)) {
return $languageCode;
}
}
}
return null;
}
session_start();
$project = "davadmin";
if (isset($_GET["language"])) {
$languageCode = _get_supported_language_code($_GET["language"], false);
if (isset($languageCode)) {
$_SESSION["language"] = $languageCode;
}
}
if ($_SESSION["language"]) {
$language = $_SESSION["language"];
} else {
$language = _http_negotiate_locale();
$_SESSION["language"] = $language;
}
putenv(sprintf("LANG=%s", $_SESSION["language"]));
putenv(sprintf("LANGUAGE=%s", $_SESSION["language"]));
$_SESSION["locale"] = _setlocale(LC_ALL, $_SESSION["language"]);
bindtextdomain($project, realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR .
".." . DIRECTORY_SEPARATOR . "po"));
textdomain($project);
?>

100
po/davadmin.pot Normal file
View File

@ -0,0 +1,100 @@
# DAVAdmin.
# Copyright (C) 2007, Jan Dittberner
# This file is distributed under the same license as the davadmin package.
# Jan Dittberner <jan AT dittberner.info>, 2007.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: davadmin 0.2\n"
"Report-Msgid-Bugs-To: jan@dittberner.info\n"
"POT-Creation-Date: 2007-11-30 22:16+0100\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"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: admin/common.inc.php:37 admin/getgroups.php:37
msgid ""
"The Server is not configured correctly. Please tell your Administrator to "
"set the DavAdminConfDir environment variable."
msgstr ""
#: admin/common.inc.php:57
msgid "Invalid call!"
msgstr ""
#: admin/common.inc.php:85 admin/common.inc.php:93 admin/common.inc.php:101
#: admin/common.inc.php:109 admin/common.inc.php:118 admin/common.inc.php:122
#, php-format
msgid "%s is not defined."
msgstr ""
#: admin/common.inc.php:89
msgid "The specified digest file is not readable and writable."
msgstr ""
#: admin/common.inc.php:97
msgid "The specified group file is not readable and writable."
msgstr ""
#: admin/common.inc.php:105
msgid "The specified name mapping file is not readable and writable."
msgstr ""
#: admin/common.inc.php:114
msgid "The specified DAV directory is no directory or not accessable."
msgstr ""
#: admin/directories.php:114
#, php-format
msgid "%d kBytes"
msgstr ""
#: admin/directories.php:130 admin/directories.php:236
#: admin/directories.php:275
#, php-format
msgid "Invalid directory name %s!"
msgstr ""
#: admin/directories.php:227
#, php-format
msgid "There already is a directory entry named %s, but it's not a directory!"
msgstr ""
#: admin/directories.php:286 admin/directories.php:307 admin/users.php:344
#: admin/users.php:365 admin/users.php:369
#, php-format
msgid "Unexpected values %s!"
msgstr ""
#: admin/directories.php:303
msgid "Delete failed!"
msgstr ""
#: admin/users.php:64 admin/users.php:84 admin/users.php:327
#, php-format
msgid "Invalid user id %s"
msgstr ""
#: admin/users.php:105
msgid "Uid must be numeric."
msgstr ""
#: admin/users.php:108 admin/users.php:115
msgid "Password must be at least 8 characters long."
msgstr ""
#: admin/users.php:112
msgid ""
"Username must be at least 2 characters long and must contain letters and "
"digits only."
msgstr ""
#: admin/users.php:125
msgid ""
"Groups must be a list of group names separated by commas. Group names must "
"consist of letters and digits."
msgstr ""

30
po/pot.sed Normal file
View File

@ -0,0 +1,30 @@
# Copyright (c) 2007 Jan Dittberner. $Revision$
#
# inspired by Alex Tingle's pot.sed from
# http://blogs.admissions.buffalo.edu/news/wp-content/plugins/eventcalendar3/gettext/pot.sed
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# Fills in some details in the ec3.pot file.
1,/^$/ {
s/SOME DESCRIPTIVE TITLE/DAVAdmin/
s/YEAR THE PACKAGE.S COPYRIGHT HOLDER/2007, Jan Dittberner/
s/PACKAGE/davadmin/
s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Jan Dittberner <jan AT dittberner.info>, 2007./
s/VERSION/0.2/
s/CHARSET/UTF-8/
}