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

  • 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() 
    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)) 
    2630 
    2731def get_catalog(locale, domain = None): 
    2832    """Return translations for given locale. 
    2933    """ 
    30     if not domain: domain = turbogears.config.get("i18n.domain", "messages") 
     34    if not domain: 
     35        domain = turbogears.config.get("i18n.domain", "messages") 
    3136 
    3237    catalog = _catalogs.get(domain) 
    3338 
     
    4550def plain_gettext(key, locale=None, domain=None): 
    4651    """Gets the gettext value for key.Added to builtins as '_'. Returns Unicode string. 
    4752    @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. 
    5054    """ 
    5155    gettext_func = turbogears.config.get("i18n.gettext", tg_gettext) 
    5256    return gettext_func(key, locale, domain) 
     
    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 
    58     get_locale. 
     61    @param locale: locale code to be used. If locale is None, gets the value provided by get_locale. 
    5962    """ 
    6063    if locale is None:locale = get_locale() 
    6164    if not is_locale_supported(locale):locale = locale[:2] 
     
    7275    """Translates two possible texts based on whether num is greater than 1 
    7376    @param key1: text if num==1 
    7477    @param key2: text if num!=1 
    75  
    7678    @param num: a number 
    7779    @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. 
    8181    """ 
    82  
    8382    if num==1: 
    84  
    8583        return plain_gettext(key1, locale) 
    86  
    8784    else: 
    88  
    8985        return plain_gettext(key2, locale) 
    9086 
    9187class lazystring(object): 
     
    138134lazy_ngettext = lazify(plain_ngettext) 
    139135 
    140136def 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. 
    143138 
    144139    @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. 
    147141     """ 
    148142 
    149143    if request_available(): 
     
    156150 
    157151    @param key1: text if num==1 
    158152    @param key2: text if num!=1 
    159  
    160153    @param num: a number 
    161154    @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. 
    165156    """ 
    166157    if request_available(): 
    167158        return plain_ngettext(key1, key2, num, locale)