Warning:
Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.
Ticket #1382: no_package_problem.patch
| File no_package_problem.patch,
4.1 KB
(added by chrisz, 5 years ago) |
|
addresses comment 06/07/07 13:27:31 by jtate
|
-
|
|
|
|
| 12 | 12 | def get_locale_dir(): |
| 13 | 13 | localedir = turbogears.config.get("i18n.locale_dir") |
| 14 | 14 | if not localedir: |
| 15 | | localedir = os.path.join(os.path.dirname( |
| 16 | | sys.modules[get_package_name()].__path__[0]), "locales") |
| | 15 | package = get_package_name() |
| | 16 | if package: |
| | 17 | localedir = os.path.join(os.path.dirname( |
| | 18 | sys.modules[package].__path__[0]), "locales") |
| 17 | 19 | return localedir |
| 18 | 20 | |
| 19 | 21 | def is_locale_supported(locale, domain=None): |
| 20 | 22 | """Checks if [domain].mo file exists for this language |
| 21 | 23 | """ |
| 22 | | if not domain: domain = turbogears.config.get("i18n.domain", "messages") |
| | 24 | if not domain: |
| | 25 | domain = turbogears.config.get("i18n.domain", "messages") |
| 23 | 26 | |
| 24 | 27 | localedir = get_locale_dir() |
| 25 | 28 | return os.path.exists(os.path.join(localedir, locale, "LC_MESSAGES", "%s.mo" % domain)) |
| … |
… |
|
| 27 | 30 | def get_catalog(locale, domain = None): |
| 28 | 31 | """Return translations for given locale. |
| 29 | 32 | """ |
| 30 | | if not domain: domain = turbogears.config.get("i18n.domain", "messages") |
| | 33 | if not domain: |
| | 34 | domain = turbogears.config.get("i18n.domain", "messages") |
| 31 | 35 | |
| 32 | 36 | catalog = _catalogs.get(domain) |
| 33 | 37 | |
| … |
… |
|
| 45 | 49 | def plain_gettext(key, locale=None, domain=None): |
| 46 | 50 | """Gets the gettext value for key.Added to builtins as '_'. Returns Unicode string. |
| 47 | 51 | @param key: text to be translated |
| 48 | | @param locale: locale code to be used. If locale is None, gets the value provided |
| | 52 | @param locale: locale code to be used.If locale is None, gets the value provided |
| 49 | 53 | by get_locale. |
| 50 | 54 | """ |
| 51 | 55 | gettext_func = turbogears.config.get("i18n.gettext", tg_gettext) |
| … |
… |
|
| 54 | 58 | def tg_gettext(key, locale=None, domain=None): |
| 55 | 59 | """Gets the gettext value for key.Added to builtins as '_'. Returns Unicode string. |
| 56 | 60 | @param key: text to be translated |
| 57 | | @param locale: locale code to be used. If locale is None, gets the value provided by |
| | 61 | @param locale: locale code to be used.If locale is None, gets the value provided by |
| 58 | 62 | get_locale. |
| 59 | 63 | """ |
| 60 | 64 | if locale is None:locale = get_locale() |
| … |
… |
|
| 72 | 76 | """Translates two possible texts based on whether num is greater than 1 |
| 73 | 77 | @param key1: text if num==1 |
| 74 | 78 | @param key2: text if num!=1 |
| 75 | | |
| 76 | 79 | @param num: a number |
| 77 | 80 | @type num: integer |
| 78 | | |
| 79 | | @param locale: locale code to be used.If locale is None, gets the value |
| 80 | | provided by get_locale. |
| | 81 | @locale:locale code to be used.If locale is None, gets the value provided by get_locale. |
| 81 | 82 | """ |
| 82 | 83 | |
| 83 | 84 | if num==1: |
| … |
… |
|
| 89 | 90 | return plain_gettext(key2, locale) |
| 90 | 91 | |
| 91 | 92 | class lazystring(object): |
| 92 | | """Has a number of lazily evaluated functions replicating a string. |
| 93 | | Just override the eval() method to produce the actual value. |
| | 93 | """Has a number of lazily evaluated functions replicating a string. Just override the eval() method to produce the actual value. |
| 94 | 94 | """ |
| 95 | 95 | |
| 96 | 96 | def __init__(self, func, *args, **kw): |
| … |
… |
|
| 138 | 138 | lazy_ngettext = lazify(plain_ngettext) |
| 139 | 139 | |
| 140 | 140 | def gettext(key, locale=None, domain=None): |
| 141 | | """Gets the gettext value for key. Added to builtins as '_'. |
| 142 | | Returns Unicode string. |
| | 141 | """Gets the gettext value for key. Added to builtins as '_'. Returns Unicode string. |
| 143 | 142 | |
| 144 | 143 | @param key: text to be translated |
| 145 | | @param locale: locale code to be used. If locale is None, |
| 146 | | gets the value provided by get_locale. |
| | 144 | @param locale: locale code to be used. If locale is None, gets the value provided by get_locale. |
| 147 | 145 | """ |
| 148 | 146 | |
| 149 | 147 | if request_available(): |
| … |
… |
|
| 156 | 154 | |
| 157 | 155 | @param key1: text if num==1 |
| 158 | 156 | @param key2: text if num!=1 |
| 159 | | |
| 160 | 157 | @param num: a number |
| 161 | 158 | @type num: integer |
| 162 | | |
| 163 | | @param locale: locale code to be used. If locale is None, gets the value |
| 164 | | provided by get_locale. |
| | 159 | @param locale: locale code to be used. If locale is None, gets the value provided by get_locale. |
| 165 | 160 | """ |
| 166 | 161 | if request_available(): |
| 167 | 162 | return plain_ngettext(key1, key2, num, locale) |
Download in other formats: