Commit f3a9e7ec authored by Pierre-Yves David's avatar Pierre-Yves David
Browse files

[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

branch : oldstable
parent 52226299c352
......@@ -141,7 +141,7 @@ import logging
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
......@@ -398,6 +398,13 @@ this option is set to yes",
return join(CW_SOFTWARE_ROOT, 'i18n')
return join(cls.shared_dir(), 'i18n')
def cw_languages(cls):
for fname in os.listdir(join(cls.i18n_lib_dir())):
if fname.endswith('.po'):
yield splitext(fname)[0]
def available_cubes(cls):
import re
......@@ -947,6 +954,9 @@ the repository',
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
......@@ -24,7 +24,7 @@ import sys
import logging
from datetime import timedelta
from os.path import (abspath, join, exists, basename, dirname, normpath, split,
isfile, isabs)
isfile, isabs, splitext)
from import strptime
from cubicweb import CW_SOFTWARE_ROOT, ConfigurationError, schema, cwconfig
......@@ -190,7 +190,7 @@ class BaseApptestConfiguration(TestServerConfiguration, TwistedConfiguration):
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
......@@ -26,7 +26,7 @@ __docformat__ = "restructuredtext en"
# 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 logilab.common import STD_BLACKLIST
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,
from cubicweb.web.webconfig import WebConfiguration
......@@ -64,6 +65,10 @@ class DevConfiguration(ServerConfiguration, WebConfiguration):
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 @@ msgstr ""
''' % 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 @@ class UpdateCubicWebCatalogCommand(Command):
print '-> merging main pot file with existing translations.'
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 @@ def update_cube_catalogs(cubedir):
print '-> merging main pot file with existing translations:'
toedit = []
for lang in cw_languages():
for lang in CubicWebNoAppConfiguration.cw_languages():
print '-> language', lang
cubepo = '%s.po' % lang
if not osp.exists(cubepo):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment