Warning:
Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.
| File extended_locales.patch,
8.6 KB
(added by chrisz, 5 years ago) |
|
Extended patch that also solves the problem of finding the locales directory
|
-
|
|
|
|
| 2 | 2 | import turbogears |
| 3 | 3 | from turbogears.i18n.utils import get_locale |
| 4 | 4 | from turbojson.jsonify import jsonify |
| 5 | | from turbogears.util import request_available |
| | 5 | from turbogears.util import get_package_name, request_available |
| 6 | 6 | import os |
| | 7 | import sys |
| 7 | 8 | import types |
| 8 | 9 | |
| 9 | 10 | _catalogs = {} |
| 10 | 11 | |
| | 12 | def get_locale_dir(): |
| | 13 | localedir = turbogears.config.get("i18n.locale_dir") |
| | 14 | if not localedir: |
| | 15 | localedir = os.path.join(os.path.dirname( |
| | 16 | sys.modules[get_package_name()].__path__[0]), "locales") |
| | 17 | return localedir |
| | 18 | |
| 11 | 19 | def is_locale_supported(locale, domain=None): |
| 12 | 20 | """Checks if [domain].mo file exists for this language |
| 13 | 21 | """ |
| | 22 | if not domain: domain = turbogears.config.get("i18n.domain", "messages") |
| 14 | 23 | |
| 15 | | if not domain:domain = turbogears.config.get("i18n.domain", "messages") |
| 16 | | localedir = turbogears.config.get("i18n.locale_dir", "locales") |
| | 24 | localedir = get_locale_dir() |
| | 25 | return os.path.exists(os.path.join(localedir, locale, "LC_MESSAGES", "%s.mo" % domain)) |
| 17 | 26 | |
| 18 | | return os.path.exists(os.path.join(localedir, locale, "LC_MESSAGES", "%s.mo" %domain)) |
| 19 | | |
| 20 | 27 | def get_catalog(locale, domain = None): |
| 21 | | """Return translations for given locale. |
| | 28 | """Return translations for given locale. |
| 22 | 29 | """ |
| 23 | | if domain is None:domain = turbogears.config.get("i18n.domain", "messages") |
| | 30 | if not domain: domain = turbogears.config.get("i18n.domain", "messages") |
| 24 | 31 | |
| 25 | 32 | catalog = _catalogs.get(domain) |
| 26 | 33 | |
| 27 | 34 | if not catalog: |
| 28 | | |
| 29 | 35 | catalog = _catalogs[domain] = {} |
| 30 | 36 | |
| 31 | 37 | messages = catalog.get(locale) |
| 32 | 38 | if not messages: |
| 33 | | |
| 34 | | localedir = turbogears.config.get("i18n.locale_dir", "locales") |
| 35 | | messages = catalog[locale] = translation(domain=domain, |
| | 39 | localedir = get_locale_dir() |
| | 40 | messages = catalog[locale] = translation(domain=domain, |
| 36 | 41 | localedir=localedir, languages=[locale]) |
| 37 | 42 | |
| 38 | 43 | return messages |
| … |
… |
|
| 40 | 45 | def plain_gettext(key, locale=None, domain=None): |
| 41 | 46 | """Gets the gettext value for key.Added to builtins as '_'. Returns Unicode string. |
| 42 | 47 | @param key: text to be translated |
| 43 | | @param locale: locale code to be used.If locale is None, gets the value provided |
| | 48 | @param locale: locale code to be used.If locale is None, gets the value provided |
| 44 | 49 | by get_locale. |
| 45 | 50 | """ |
| 46 | 51 | gettext_func = turbogears.config.get("i18n.gettext", tg_gettext) |
| … |
… |
|
| 49 | 54 | def tg_gettext(key, locale=None, domain=None): |
| 50 | 55 | """Gets the gettext value for key.Added to builtins as '_'. Returns Unicode string. |
| 51 | 56 | @param key: text to be translated |
| 52 | | @param locale: locale code to be used.If locale is None, gets the value provided by |
| | 57 | @param locale: locale code to be used.If locale is None, gets the value provided by |
| 53 | 58 | get_locale. |
| 54 | 59 | """ |
| 55 | 60 | if locale is None:locale = get_locale() |
| … |
… |
|
| 74 | 79 | |
| 75 | 80 | if num==1: |
| 76 | 81 | |
| 77 | | return plain_gettext(key1, locale) |
| | 82 | return plain_gettext(key1, locale) |
| 78 | 83 | |
| 79 | 84 | else: |
| 80 | 85 | |
| 81 | | return plain_gettext(key2, locale) |
| | 86 | return plain_gettext(key2, locale) |
| 82 | 87 | |
| 83 | 88 | class lazystring(object): |
| 84 | 89 | """Has a number of lazily evaluated functions replicating a string. Just override the eval() method to produce the actual value. |
-
|
|
|
|
| 4 | 4 | import os |
| 5 | 5 | execfile(os.path.join("${package}", "release.py")) |
| 6 | 6 | |
| | 7 | packages=find_packages() |
| | 8 | package_data = find_package_data(where='${package}', |
| | 9 | package='${package}') |
| | 10 | if os.path.isdir('locales'): |
| | 11 | packages.append('locales') |
| | 12 | package_data.update(find_package_data(where='locales', |
| | 13 | exclude=('*.po',), only_in_packages=False)) |
| | 14 | |
| 7 | 15 | setup( |
| 8 | 16 | name="${project}", |
| 9 | 17 | version=version, |
| 10 | | |
| | 18 | |
| 11 | 19 | # uncomment the following lines if you fill them out in release.py |
| 12 | 20 | #description=description, |
| 13 | 21 | #author=author, |
| … |
… |
|
| 15 | 23 | #url=url, |
| 16 | 24 | #download_url=download_url, |
| 17 | 25 | #license=license, |
| 18 | | |
| 19 | | install_requires = [ |
| | 26 | |
| | 27 | install_requires=[ |
| 20 | 28 | "TurboGears >= ${turbogearsversion}", |
| 21 | | #if $identity == "sqlalchemy" |
| 22 | | "SQLAlchemy", |
| 23 | | #end if |
| | 29 | #if $identity == "sqlalchemy" |
| | 30 | "SQLAlchemy", |
| | 31 | #end if |
| 24 | 32 | ], |
| 25 | | scripts = ["start-${package}.py"], |
| | 33 | scripts=["start-${package}.py"], |
| 26 | 34 | zip_safe=False, |
| 27 | | packages=find_packages(), |
| 28 | | package_data = find_package_data(where='${package}', |
| 29 | | package='${package}'), |
| 30 | | keywords = [ |
| | 35 | packages=packages, |
| | 36 | package_data=package_data, |
| | 37 | keywords=[ |
| 31 | 38 | # Use keywords if you'll be adding your package to the |
| 32 | 39 | # Python Cheeseshop |
| 33 | | |
| | 40 | |
| 34 | 41 | # if this has widgets, uncomment the next line |
| 35 | 42 | # 'turbogears.widgets', |
| 36 | | |
| | 43 | |
| 37 | 44 | # if this has a tg-admin command, uncomment the next line |
| 38 | 45 | # 'turbogears.command', |
| 39 | | |
| | 46 | |
| 40 | 47 | # if this has identity providers, uncomment the next line |
| 41 | 48 | # 'turbogears.identity.provider', |
| 42 | | |
| | 49 | |
| 43 | 50 | # If this is a template plugin, uncomment the next line |
| 44 | 51 | # 'python.templating.engines', |
| 45 | | |
| | 52 | |
| 46 | 53 | # If this is a full application, uncomment the next line |
| 47 | 54 | # 'turbogears.app', |
| 48 | 55 | ], |
| 49 | | classifiers = [ |
| | 56 | classifiers=[ |
| 50 | 57 | 'Development Status :: 3 - Alpha', |
| 51 | 58 | 'Operating System :: OS Independent', |
| 52 | 59 | 'Programming Language :: Python', |
| … |
… |
|
| 55 | 62 | # if this is an application that you'll distribute through |
| 56 | 63 | # the Cheeseshop, uncomment the next line |
| 57 | 64 | # 'Framework :: TurboGears :: Applications', |
| 58 | | |
| | 65 | |
| 59 | 66 | # if this is a package that includes widgets that you'll distribute |
| 60 | 67 | # through the Cheeseshop, uncomment the next line |
| 61 | 68 | # 'Framework :: TurboGears :: Widgets', |
| 62 | 69 | ], |
| 63 | | test_suite = 'nose.collector', |
| | 70 | test_suite='nose.collector', |
| 64 | 71 | ) |
| 65 | | |
| | 72 | |
-
|
|
|
|
| 2 | 2 | import pkg_resources |
| 3 | 3 | pkg_resources.require("TurboGears") |
| 4 | 4 | |
| 5 | | from turbogears import update_config, start_server |
| | 5 | from turbogears import config, update_config, start_server |
| 6 | 6 | import cherrypy |
| 7 | 7 | cherrypy.lowercase_api = True |
| 8 | 8 | from os.path import * |
| … |
… |
|
| 13 | 13 | # look for setup.py in this directory. If it's not there, this script is |
| 14 | 14 | # probably installed |
| 15 | 15 | if len(sys.argv) > 1: |
| 16 | | update_config(configfile=sys.argv[1], |
| | 16 | update_config(configfile=sys.argv[1], |
| 17 | 17 | modulename="${package}.config") |
| 18 | 18 | elif exists(join(dirname(__file__), "setup.py")): |
| 19 | 19 | update_config(configfile="dev.cfg",modulename="${package}.config") |
| 20 | 20 | else: |
| 21 | 21 | update_config(configfile="prod.cfg",modulename="${package}.config") |
| | 22 | config.update(dict(package="${package}")) |
| 22 | 23 | |
| 23 | 24 | from ${package}.controllers import Root |
| 24 | 25 | |
-
|
|
|
|
| 98 | 98 | |
| 99 | 99 | def get_package_name(): |
| 100 | 100 | """Try to find out the package name of the current directory.""" |
| | 101 | package = config.get("package") |
| | 102 | if package: |
| | 103 | return package |
| 101 | 104 | if "--egg" in sys.argv: |
| 102 | 105 | projectname = sys.argv[sys.argv.index("--egg")+1] |
| 103 | 106 | egg = pkg_resources.get_distribution(projectname) |
| 104 | | package = list(egg._get_metadata("top_level.txt"))[0] |
| 105 | | return package |
| 106 | | fname = get_project_meta('top_level.txt') |
| 107 | | if fname: |
| 108 | | return open(fname).readline()[:-1] |
| | 107 | top_level = egg._get_metadata("top_level.txt") |
| | 108 | else: |
| | 109 | fname = get_project_meta('top_level.txt') |
| | 110 | top_level = fname and open(fname) or [] |
| | 111 | for package in top_level: |
| | 112 | package = package.rstrip() |
| | 113 | if package and package != 'locales': |
| | 114 | return package |
| 109 | 115 | |
| 110 | 116 | def get_project_name(): |
| 111 | 117 | pkg_info = get_project_meta('PKG-INFO') |
| … |
… |
|
| 426 | 432 | "arg_index", "inject_arg", "inject_args", "bind_args", |
| 427 | 433 | "recursive_update", "combine_contexts", "request_available", |
| 428 | 434 | "flatten_sequence", "load_class", "Bunch", |
| 429 | | "parse_http_accept_header", |
| | 435 | "parse_http_accept_header", |
| 430 | 436 | "to_unicode", "to_utf8", "get_template_encoding_default", |
| 431 | 437 | "find_precision", "copy_if_mutable"] |
Download in other formats: