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_2.patch
| File no_package_problem_2.patch,
4.1 KB
(added by chrisz, 5 years ago) |
|
addresses comment 06/07/07 20:46: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 | | return os.path.exists(os.path.join(localedir, locale, "LC_MESSAGES", "%s.mo" % domain)) |
| | 28 | return localedir and os.path.exists(os.path.join( |
| | 29 | localedir, locale, "LC_MESSAGES", "%s.mo" % domain)) |
| 26 | 30 | |
| 27 | 31 | def get_catalog(locale, domain = None): |
| 28 | 32 | """Return translations for given locale. |
| 29 | 33 | """ |
| 30 | | if not domain: domain = turbogears.config.get("i18n.domain", "messages") |
| | 34 | if not domain: |
| | 35 | domain = turbogears.config.get("i18n.domain", "messages") |
| 31 | 36 | |
| 32 | 37 | catalog = _catalogs.get(domain) |
| 33 | 38 | |
| … |
… |
|
| 45 | 50 | def plain_gettext(key, locale=None, domain=None): |
| 46 | 51 | """Gets the gettext value for key.Added to builtins as '_'. Returns Unicode string. |
| 47 | 52 | @param key: text to be translated |
| 48 | | @param locale: locale code to be used. If locale is None, gets the value provided |
| 49 | | by get_locale. |
| | 53 | @param locale: locale code to be used.If locale is None, gets the value provided by get_locale. |
| 50 | 54 | """ |
| 51 | 55 | gettext_func = turbogears.config.get("i18n.gettext", tg_gettext) |
| 52 | 56 | return gettext_func(key, locale, domain) |
| … |
… |
|
| 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 |
| 58 | | get_locale. |
| | 61 | @param locale: locale code to be used. If locale is None, gets the value provided by get_locale. |
| 59 | 62 | """ |
| 60 | 63 | if locale is None:locale = get_locale() |
| 61 | 64 | if not is_locale_supported(locale):locale = locale[:2] |
| … |
… |
|
| 72 | 75 | """Translates two possible texts based on whether num is greater than 1 |
| 73 | 76 | @param key1: text if num==1 |
| 74 | 77 | @param key2: text if num!=1 |
| 75 | | |
| 76 | 78 | @param num: a number |
| 77 | 79 | @type num: integer |
| 78 | | |
| 79 | | @param locale: locale code to be used.If locale is None, gets the value |
| 80 | | provided by get_locale. |
| | 80 | @locale:locale code to be used. If locale is None, gets the value provided by get_locale. |
| 81 | 81 | """ |
| 82 | | |
| 83 | 82 | if num==1: |
| 84 | | |
| 85 | 83 | return plain_gettext(key1, locale) |
| 86 | | |
| 87 | 84 | else: |
| 88 | | |
| 89 | 85 | return plain_gettext(key2, locale) |
| 90 | 86 | |
| 91 | 87 | class lazystring(object): |
| … |
… |
|
| 138 | 134 | lazy_ngettext = lazify(plain_ngettext) |
| 139 | 135 | |
| 140 | 136 | def gettext(key, locale=None, domain=None): |
| 141 | | """Gets the gettext value for key. Added to builtins as '_'. |
| 142 | | Returns Unicode string. |
| | 137 | """Gets the gettext value for key. Added to builtins as '_'. Returns Unicode string. |
| 143 | 138 | |
| 144 | 139 | @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. |
| | 140 | @param locale: locale code to be used. If locale is None, gets the value provided by get_locale. |
| 147 | 141 | """ |
| 148 | 142 | |
| 149 | 143 | if request_available(): |
| … |
… |
|
| 156 | 150 | |
| 157 | 151 | @param key1: text if num==1 |
| 158 | 152 | @param key2: text if num!=1 |
| 159 | | |
| 160 | 153 | @param num: a number |
| 161 | 154 | @type num: integer |
| 162 | | |
| 163 | | @param locale: locale code to be used. If locale is None, gets the value |
| 164 | | provided by get_locale. |
| | 155 | @param locale: locale code to be used. If locale is None, gets the value provided by get_locale. |
| 165 | 156 | """ |
| 166 | 157 | if request_available(): |
| 167 | 158 | return plain_ngettext(key1, key2, num, locale) |
Download in other formats: