moved default language names to scripts/update_language_files

revert removal of hdf attribute "Lang.Name"
finally fixed multilingual interface
This commit is contained in:
lars 2007-03-29 15:51:34 +00:00
parent 6227c73f70
commit 525ce2812e
7 changed files with 75 additions and 99 deletions

View file

@ -24,6 +24,10 @@ $LIST_DIR = "$HOME_DIR/lists";
# defaults to "$LIST_DIR/webusers"
$WEBUSERS_FILE = "$LIST_DIR/webusers";
# Where are the language files
# usually something like /usr/local/share/ezmlm-web/lang
$LANGUAGE_DIR = "/usr/local/share/ezmlm-web/lang";
# Where are the template files
# usually something like /usr/local/share/ezmlm-web/template
$TEMPLATE_DIR = "/usr/local/share/ezmlm-web/template";

View file

@ -43,25 +43,6 @@ unless (&safely_import_module("Encode")) {
# setting is enabled
# the local names of all available (and some other) languages
my %LANGUAGE_NAMES = (
"cs" => 'Český',
"da" => 'Dansk',
"de" => 'Deutsch',
"en" => 'English',
"es" => 'Español',
"fi" => 'Suomi',
"fr" => 'Français',
"hu" => 'Magyar',
"it" => 'Italiano',
"ja" => '日本語',
"nl" => 'Nederlands',
"pl" => 'Polski',
"pt" => 'Português',
"ru" => 'Русский',
"sl" => 'Slovensko',
"sv" => 'Svenska',
);
################## some preparations at the beginning ##################
@ -94,14 +75,14 @@ use vars qw[$HOME_DIR]; $HOME_DIR=$tmp[7];
use vars qw[$DEFAULT_OPTIONS $UNSAFE_RM $ALIAS_USER $LIST_DIR];
use vars qw[$QMAIL_BASE $PRETTY_NAMES $DOTQMAIL_DIR];
use vars qw[$FILE_UPLOAD $WEBUSERS_FILE $MAIL_DOMAIN $HTML_TITLE];
use vars qw[$HTML_CSS_FILE $TEMPLATE_DIR $HTML_LANGUAGE];
use vars qw[$DEFAULT_HOST @LANGUAGE_LIST];
use vars qw[$HTML_CSS_FILE $TEMPLATE_DIR $LANGUAGE_DIR $HTML_LANGUAGE];
use vars qw[$DEFAULT_HOST];
# some settings for encrypted mailing lists
use vars qw[$GPG_SUPPORT];
# some deprecated configuration settings - they have to be announced
# otherwise old configuration files would break
use vars qw[$LANGUAGE_DIR]; # deprecated since v3.2
# for now there are no deprecated settings
# "pagedata" contains the hdf tree for clearsilver
# "pagename" refers to the template file that should be used
@ -151,10 +132,6 @@ if (defined($opt_d)) {
# then use former default value for compatibility
$WEBUSERS_FILE = $LIST_DIR . '/webusers' unless (defined($WEBUSERS_FILE));
# set default value of supported languages
@LANGUAGE_LIST = ( 'en', 'de' ) unless (defined(@LANGUAGE_LIST));
# check for non-default dotqmail directory
$DOTQMAIL_DIR = $HOME_DIR unless defined($DOTQMAIL_DIR);
@ -462,8 +439,13 @@ sub init_hdf {
# initialize the data for clearsilver
my $hdf = ClearSilver::HDF->new();
&fatal_error("Language data dir ($LANGUAGE_DIR) not found!")
unless (-e $LANGUAGE_DIR);
$hdf->setValue("LanguageDir", "$LANGUAGE_DIR/");
&fatal_error("Template dir ($TEMPLATE_DIR) not found!") unless (-e $TEMPLATE_DIR);
&fatal_error("Template dir ($TEMPLATE_DIR) not found!")
unless (-e $TEMPLATE_DIR);
$hdf->setValue("TemplateDir", "$TEMPLATE_DIR/");
# "normal", "basic" and "expert" should be supported soon
@ -536,8 +518,13 @@ sub load_interface_language {
# set default language
$config_language = 'en';
# english should always be there - but just in case of local modifications
$config_language = $HTML_LANGUAGE
unless (&check_interface_language($HTML_LANGUAGE));
# first: load default language - in case some translations are incomplete
$data->readFile("$LANGUAGE_DIR/$HTML_LANGUAGE" . ".hdf");
# check for preferred browser language, if the box was not initialized yet
my $prefLang = &get_browser_language();
@ -560,72 +547,13 @@ sub load_interface_language {
# add the setting to every link
$data->setValue('Config.UI.LinkAttrs.web_lang', "$config_language");
&translate_language_data($data, $config_language);
# import the configured resp. the temporarily selected language
$data->readFile("$LANGUAGE_DIR/$config_language" . ".hdf");
return $data;
}
# ---------------------------------------------------------------------------
sub translate_language_data {
my ($hdf, $language) = @_;
my $langdata;
my %language_strings;
my $key;
# read language template
$langdata = ClearSilver::HDF->new();
$langdata->readFile("$TEMPLATE_DIR/language.hdf");
# parse all strings
my $subtree = $langdata->getObj("Lang");
%language_strings = &recurse_hdf($subtree, "Lang");
if ($GETTEXT_SUPPORT) {
# create gettext object
&textdomain("ezmlm-web");
warn "failed to set locale: $@" unless (&setlocale(LC_MESSAGES, ''));
# "setlocale" seems to need "de_DE" instead of just "de" - so we will
# use the environment setting instead
# see http://lists.debian.org/debian-perl/2000/01/msg00016.html
# avoid calling other programs later: their output may suffer :)
$ENV{LC_ALL} = "$language";
# translate every string
foreach $key (keys %language_strings) {
$hdf->setValue($key, &gettext($language_strings{$key}))
}
} else {
# just copy all strings
foreach $key (keys %language_strings) {
$hdf->setValue($key, $language_strings{$key})
}
}
}
# ---------------------------------------------------------------------------
sub recurse_hdf {
my ($node, $prefix) = @_;
my ($value, $child, $next, %result, %sub_result, $key);
$value = $node->objValue();
if ($value) {
#print "Prefix: " . $prefix . " / " . $value . "\n";
$result{$prefix} = $value;
}
$next = $node->objChild();
while ($next) {
%sub_result = &recurse_hdf($next, $prefix . "." . $next->objName());
foreach $key (keys %sub_result) {
$result{$key} = $sub_result{$key};
}
$next = $next->objNext();
}
return %result;
}
# ---------------------------------------------------------------------------
sub get_browser_language {
@ -2107,13 +2035,20 @@ sub webauth_create_allowed {
# ---------------------------------------------------------------------------
sub get_available_interface_languages {
my (%languages, $lang_id);
foreach $lang_id (@LANGUAGE_LIST) {
if (defined($LANGUAGE_NAMES{$lang_id})) {
$languages{$lang_id} = $LANGUAGE_NAMES{$lang_id};
} else {
$languages{$lang_id} = $lang_id;
}
my (%languages, @files, $file);
opendir(DIR, $LANGUAGE_DIR)
or &fatal_error ("Language directory ($LANGUAGE_DIR) not accessible!");
@files = sort grep { /.*\.hdf$/ } readdir(DIR);
close(DIR);
foreach $file (@files) {
my $hdf = ClearSilver::HDF->new();
$hdf->readFile("$LANGUAGE_DIR/$file");
substr($file, -4) = "";
my $lang_name = $hdf->getValue("Lang.Name", "$file");
$languages{$file} = $lang_name;
}
return %languages;
}

View file

@ -1,4 +1,5 @@
Lang {
Name = Deutsch
Menue {
ListCreate = Neue Liste anlegen
ListDelete = Liste löschen

View file

@ -1,5 +1,7 @@
Lang {
Name = English
Menue {
ListCreate = Create new list
ListDelete = Delete list

View file

@ -46,6 +46,7 @@ if test "$(id -u)" == 0
DEST_GROUP=pootle
TARGETPATH=${1%/}
# BASEPATH must be absolute
BASEPATH=$(cd $(dirname "$0")/..; pwd)
############# functions ###############

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#
# Copyright 2007 Lars Kruse <devel@sumpfralle.de>
#
@ -70,6 +71,25 @@ ALL_LANGUAGES = "cs da de en es fi fr hu it ja nl pl pt ru sl sv".split(" ")
## use subversion for reverting?
USE_SVN = True
LANGUAGE_NAMES = {
"cs": 'Český',
"da": 'Dansk',
"de": 'Deutsch',
"en": 'English',
"es": 'Español',
"fi": 'Suomi',
"fr": 'Français',
"hu": 'Magyar',
"it": 'Italiano',
"ja": '日本語',
"nl": 'Nederlands',
"pl": 'Polski',
"pt": 'Português',
"ru": 'Русский',
"sl": 'Slovensko',
"sv": 'Svenska',
};
# --------------=-=-=- functions -=-=-=--------------------
def revert_if_unchanged(po_file):
@ -128,7 +148,7 @@ def generate_po_files(hdf_file, po_dir, textDomain):
def walk_hdf(prefix, node):
def addPoItem(hdf_node):
## ignore hdf values with a "LINK" attribute
for (key,value) in hdf_node.attrs():
for (key, value) in hdf_node.attrs():
if key == "LINK":
return
if not hdf_node.value():
@ -150,12 +170,14 @@ def generate_po_files(hdf_file, po_dir, textDomain):
or new_prefix.endswith(".Link.Attr1.name.") \
or new_prefix.endswith(".Link.Attr1.value.") \
or new_prefix.endswith(".Link.Attr2.name.") \
or new_prefix.endswith(".Link.Attr2.value.")):
or new_prefix.endswith(".Link.Attr2.value.") \
or new_prefix == "Lang.Name."):
addPoItem(node)
walk_hdf(new_prefix, node.child())
node = node.next()
walk_hdf("",hdf)
pot.savefile(pot_file)
# TODO: remove the following line?
p = translate.storage.po.pofile(pot_file)
for ld in ALL_LANGUAGES:
if not os.path.isdir(os.path.join(po_dir,ld)):
@ -218,7 +240,7 @@ def generate_translated_hdf_file(orig_hdf_file, po_dir, hdf_dir, textdomain, lan
translate_count = 0
def addHdfItem(hdf_node):
## ignore hdf values with a "LINK" attribute
for (key,value) in hdf_node.attrs():
for (key, value) in hdf_node.attrs():
if key == "LINK":
return
if not hdf_node.value():
@ -237,13 +259,23 @@ def generate_translated_hdf_file(orig_hdf_file, po_dir, hdf_dir, textdomain, lan
new_prefix = prefix
## as the attribute feature of clearsilver does not work yet, we
## have to rely on magic names to prevent the translation of links
if not (new_prefix.endswith(".Link.Rel.") \
if (new_prefix.endswith(".Link.Rel.") \
or new_prefix.endswith(".Link.Prot.") \
or new_prefix.endswith(".Link.Abs.") \
or new_prefix.endswith(".Link.Attr1.name.") \
or new_prefix.endswith(".Link.Attr1.value.") \
or new_prefix.endswith(".Link.Attr2.name.") \
or new_prefix.endswith(".Link.Attr2.value.")):
pass
elif new_prefix == "Lang.Name.":
# set the "Lang.Name" attribute properly
# remove trailing dot
new_prefix = new_prefix.strip(".")
if language in LANGUAGE_NAMES:
hdf.setValue(new_prefix, LANGUAGE_NAMES[language])
else:
hdf.setValue(new_prefix, language)
else:
if addHdfItem(node):
translate_count += 1
translate_count += walk_hdf(new_prefix, node.child())

View file

@ -1,4 +1,5 @@
ScriptName
LanguageDir
TemplateDir
Stylesheet
HelpIconURL