# HG changeset patch # User Pierre-Yves David # Date 1291979838 -3600 # Node ID 48f468f33704e401a8e7907e258bf1ac61eb8407 # Parent 52226299c352b6139127ccc426f6b3fcd3f60d83 [config, i18n] Create default translation mechanism for all supported languages. Mostly usefull in test where language are never initialised from .po files. This is a reapplication of changeset 1a423eaee782 backouted by b9ffecd0316a with an additional fix not to break i18nxxx commands diff -r 52226299c352 -r 48f468f33704 cwconfig.py --- a/cwconfig.py Fri Dec 10 15:17:16 2010 +0100 +++ b/cwconfig.py Fri Dec 10 12:17:18 2010 +0100 @@ -141,7 +141,7 @@ from smtplib import SMTP from threading import Lock from os.path import (exists, join, expanduser, abspath, normpath, - basename, isdir, dirname) + basename, isdir, dirname, splitext) from warnings import warn from logilab.common.decorators import cached, classproperty from logilab.common.deprecation import deprecated @@ -399,6 +399,13 @@ return join(cls.shared_dir(), 'i18n') @classmethod + def cw_languages(cls): + for fname in os.listdir(join(cls.i18n_lib_dir())): + if fname.endswith('.po'): + yield splitext(fname)[0] + + + @classmethod def available_cubes(cls): import re cubes = set() @@ -947,6 +954,9 @@ def __init__(self, appid, debugmode=False): self.appid = appid super(CubicWebConfiguration, self).__init__(debugmode) + fake_gettext = (unicode, lambda ctx, msgid: unicode(msgid)) + for lang in self.available_languages(): + self.translations[lang] = fake_gettext self._cubes = None self.load_file_configuration(self.main_config_file()) diff -r 52226299c352 -r 48f468f33704 devtools/__init__.py --- a/devtools/__init__.py Fri Dec 10 15:17:16 2010 +0100 +++ b/devtools/__init__.py Fri Dec 10 12:17:18 2010 +0100 @@ -24,7 +24,7 @@ import logging from datetime import timedelta from os.path import (abspath, join, exists, basename, dirname, normpath, split, - isfile, isabs) + isfile, isabs, splitext) from logilab.common.date import strptime from cubicweb import CW_SOFTWARE_ROOT, ConfigurationError, schema, cwconfig @@ -190,7 +190,7 @@ cube_appobject_path = TestServerConfiguration.cube_appobject_path | TwistedConfiguration.cube_appobject_path def available_languages(self, *args): - return ('en', 'fr', 'de', 'es') + return self.cw_languages() def pyro_enabled(self): # but export PYRO_MULTITHREAD=0 or you get problems with sqlite and diff -r 52226299c352 -r 48f468f33704 devtools/devctl.py --- a/devtools/devctl.py Fri Dec 10 15:17:16 2010 +0100 +++ b/devtools/devctl.py Fri Dec 10 12:17:18 2010 +0100 @@ -26,7 +26,7 @@ # completion). So import locally in command helpers. import sys from datetime import datetime -from os import mkdir, chdir, listdir, path as osp +from os import mkdir, chdir, path as osp from warnings import warn from logilab.common import STD_BLACKLIST @@ -34,6 +34,7 @@ from cubicweb.__pkginfo__ import version as cubicwebversion from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage from cubicweb.cwctl import CWCTL +from cubicweb.cwconfig import CubicWebNoAppConfiguration from cubicweb.toolsutils import (SKEL_EXCLUDE, Command, copy_skeleton, underline_title) from cubicweb.web.webconfig import WebConfiguration @@ -64,6 +65,10 @@ @property def apphome(self): return None + + def available_languages(self): + return self.cw_languages() + def main_config_file(self): return None def init_log(self): @@ -263,11 +268,6 @@ ''' % cubicwebversion -def cw_languages(): - for fname in listdir(osp.join(WebConfiguration.i18n_lib_dir())): - if fname.endswith('.po'): - yield osp.splitext(fname)[0] - class UpdateCubicWebCatalogCommand(Command): """Update i18n catalogs for cubicweb library. @@ -329,7 +329,7 @@ print '-> merging main pot file with existing translations.' chdir(cwi18ndir) toedit = [] - for lang in cw_languages(): + for lang in CubicWebNoAppConfiguration.cw_languages(): target = '%s.po' % lang execute('msgmerge -N --sort-output -o "%snew" "%s" "%s"' % (target, target, cubicwebpot)) @@ -444,7 +444,7 @@ print '-> merging main pot file with existing translations:' chdir('i18n') toedit = [] - for lang in cw_languages(): + for lang in CubicWebNoAppConfiguration.cw_languages(): print '-> language', lang cubepo = '%s.po' % lang if not osp.exists(cubepo):