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

  • turbogears/i18n/tg_gettext.py

     
    1212def get_locale_dir(): 
    1313    localedir = turbogears.config.get("i18n.locale_dir") 
    1414    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") 
    1719    return localedir 
    1820 
    1921def is_locale_supported(locale, domain=None): 
    2022    """Checks if [domain].mo file exists for this language 
    2123    """ 
    22     if not domain: domain = turbogears.config.get("i18n.domain", "messages") 
     24    if not domain: 
     25        domain = turbogears.config.get("i18n.domain", "messages") 
    2326 
    2427    localedir = get_locale_dir() 
    2528    return os.path.exists(os.path.join(localedir, locale, "LC_MESSAGES", "%s.mo" % domain)) 
     
    2730def get_catalog(locale, domain = None): 
    2831    """Return translations for given locale. 
    2932    """ 
    30     if not domain: domain = turbogears.config.get("i18n.domain", "messages") 
     33    if not domain: 
     34        domain = turbogears.config.get("i18n.domain", "messages") 
    3135 
    3236    catalog = _catalogs.get(domain) 
    3337 
     
    4549def plain_gettext(key, locale=None, domain=None): 
    4650    """Gets the gettext value for key.Added to builtins as '_'. Returns Unicode string. 
    4751    @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 
    4953    by get_locale. 
    5054    """ 
    5155    gettext_func = turbogears.config.get("i18n.gettext", tg_gettext) 
     
    5458def tg_gettext(key, locale=None, domain=None): 
    5559    """Gets the gettext value for key.Added to builtins as '_'. Returns Unicode string. 
    5660    @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 
    5862    get_locale. 
    5963    """ 
    6064    if locale is None:locale = get_locale() 
     
    7276    """Translates two possible texts based on whether num is greater than 1 
    7377    @param key1: text if num==1 
    7478    @param key2: text if num!=1 
    75  
    7679    @param num: a number 
    7780    @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. 
    8182    """ 
    8283 
    8384    if num==1: 
     
    8990        return plain_gettext(key2, locale) 
    9091 
    9192class 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. 
    9494    """ 
    9595 
    9696    def __init__(self, func, *args, **kw): 
     
    138138lazy_ngettext = lazify(plain_ngettext) 
    139139 
    140140def 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. 
    143142 
    144143    @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. 
    147145     """ 
    148146 
    149147    if request_available(): 
     
    156154 
    157155    @param key1: text if num==1 
    158156    @param key2: text if num!=1 
    159  
    160157    @param num: a number 
    161158    @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. 
    165160    """ 
    166161    if request_available(): 
    167162        return plain_ngettext(key1, key2, num, locale)