source: themeengineplugin/tags/themeengine-2.3.0/themeengine/translation.py

Last change on this file was 15008, checked in by Ryan J Ollos, 8 years ago

2.2.2dev: Fixup whitespace.

  • Property svn:executable set to *
File size: 1.5 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# Copyright (c) 2013      Olemis Lang <olemis+trac@gmail.com>
4# All rights reserved.
5#
6# This software is licensed as described in the file COPYING, which
7# you should have received as part of this distribution.
8#
9
10"""Translation functions and classes."""
11
12from pkg_resources import parse_version
13
14from trac import __version__ as trac_version
15
16#------------------------------------------------------
17#    Internationalization
18#------------------------------------------------------
19
20try:
21    from trac.util.translation import domain_functions
22    _, ngettext, tag_, tagn_, gettext, N_, add_domain = \
23        domain_functions('themeengine', ('_', 'ngettext', 'tag_', 'tagn_',
24                                         'gettext', 'N_', 'add_domain'))
25    dgettext = None
26except ImportError:
27    from genshi.builder  import tag as tag_
28    from trac.util.translation  import gettext
29    _ = gettext
30    N_ = lambda text: text
31    def add_domain(a,b,c=None):
32        pass
33    def dgettext(domain, string, **kwargs):
34        return safefmt(string, kwargs)
35    def ngettext(singular, plural, num, **kwargs):
36        string = num == 1 and singular or plural
37        kwargs.setdefault('num', num)
38        return safefmt(string, kwargs)
39    def safefmt(string, kwargs):
40        if kwargs:
41            try:
42                return string % kwargs
43            except KeyError:
44                pass
45        return string
46
47
48if parse_version(trac_version) >= parse_version('1.0'):
49    I18N_DOC_OPTIONS = dict(doc_domain='themeengine')
50else:
51    I18N_DOC_OPTIONS = {}
Note: See TracBrowser for help on using the repository browser.