Back to index

plone3  3.1.7
Functions | Variables
CMFPlone.i18nl10n Namespace Reference

Functions

def utranslate
def ulocalized_time
def _numbertoenglishname
def monthname_english
def weekdayname_english
def monthname_msgid
def monthname_msgid_abbr
def weekdayname_msgid
def weekdayname_msgid_abbr
def weekdayname_msgid_short

Variables

tuple plonedomain = PTSTranslationDomain('plone')
tuple atctdomain = PTSTranslationDomain('atcontenttypes')
tuple pltdomain = PTSTranslationDomain('plonelanguagetool')
tuple prtdomain = PTSTranslationDomain('passwordresettool')
tuple cmfpwdomain = PTSTranslationDomain('cmfplacefulworkflow')
tuple cmfedomain = PTSTranslationDomain('cmfeditions')
string NAME_RE = r"[a-zA-Z][a-zA-Z0-9_]*"
tuple _interp_regex = re.compile(r'(?<!\$)(\$(?:%(n)s|{%(n)s}))' %({'n': NAME_RE}))
tuple datetime_formatvariables = ('H', 'I', 'm', 'd', 'M', 'p', 'S', 'Y', 'y', 'Z')
tuple name_formatvariables = ('a', 'A', 'b', 'B')

Detailed Description

Collection of i18n and l10n utility methods.

Function Documentation

def CMFPlone.i18nl10n._numbertoenglishname (   number,
  format = None,
  attr = '_days' 
) [private]

Definition at line 150 of file i18nl10n.py.

00150 
00151 def _numbertoenglishname(number, format=None, attr='_days'):
00152     # returns the english name of day or month number
00153     # starting with Sunday == 0
00154     # and January = 1
00155     # format is either None, 'a' or 'p')
00156     #   None  means full name (January, February, ...)
00157     #   'a' means abbreviated (Jan, Feb, ..)
00158     #   'p' means abbreviated with . (dot) at end (Jan., Feb., ...)
00159     
00160     number = int(number)
00161     if format is not None:
00162         attr = '%s_%s' % (attr, format)
00163     
00164     # get list from DateTime attribute
00165     thelist = getattr(DateTime, attr)
00166 
00167     return thelist[number]
    

Here is the caller graph for this function:

def CMFPlone.i18nl10n.monthname_english (   number,
  format = None 
)

Definition at line 168 of file i18nl10n.py.

00168 
00169 def monthname_english(number, format=None):
00170     # returns the english name of month with number
00171     return _numbertoenglishname(number, format=format, attr='_months')

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 176 of file i18nl10n.py.

00176 
00177 def monthname_msgid(number):
00178     # returns the msgid for monthname
00179     # use to translate to full monthname (January, February, ...)
00180     # eg. month_jan, month_feb, ...
00181     return "month_%s" % monthname_english(number, format='a').lower()
    

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 182 of file i18nl10n.py.

00182 
00183 def monthname_msgid_abbr(number):
00184     # returns the msgid for the abbreviated monthname
00185     # use to translate to abbreviated format (Jan, Feb, ...)
00186     # eg. month_jan_abbr, month_feb_abbr, ...
00187     return "month_%s_abbr" % monthname_english(number, format='a').lower()
    

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.i18nl10n.ulocalized_time (   time,
  long_format = None,
  context = None,
  domain = 'plonelocales',
  request = None 
)

Definition at line 46 of file i18nl10n.py.

00046 
00047                     domain='plonelocales', request=None):
00048     # get msgid
00049     msgid = long_format and 'date_format_long' or 'date_format_short'
00050 
00051     # NOTE: this requires the presence of two msgids inside the translation catalog
00052     #       date_format_long and date_format_short
00053     #       These msgids are translated using interpolation.
00054     #       The variables used here are the same as used in the strftime formating.
00055     #       Supported are %A, %a, %B, %b, %H, %I, %m, %d, %M, %p, %S, %Y, %y, %Z, each used as
00056     #       variable in the msgstr without the %.
00057     #       For example: "${A} ${d}. ${B} ${Y}, ${H}:${M} ${Z}"
00058     #       Each language dependend part is translated itself as well.
00059 
00060     # From http://docs.python.org/lib/module-time.html
00061     #
00062     # %a    Locale's abbreviated weekday name.   
00063     # %A      Locale's full weekday name.        
00064     # %b      Locale's abbreviated month name.   
00065     # %B      Locale's full month name.   
00066     # %d      Day of the month as a decimal number [01,31].    
00067     # %H      Hour (24-hour clock) as a decimal number [00,23].       
00068     # %I      Hour (12-hour clock) as a decimal number [01,12].       
00069     # %m      Month as a decimal number [01,12].        
00070     # %M      Minute as a decimal number [00,59].       
00071     # %p      Locale's equivalent of either AM or PM.   
00072     # %S      Second as a decimal number [00,61].       
00073     # %y      Year without century as a decimal number [00,99].       
00074     # %Y      Year with century as a decimal number.    
00075     # %Z      Time zone name (no characters if no time zone exists).  
00076 
00077     mapping = {}
00078     # convert to DateTime instances. Either a date string or 
00079     # a DateTime instance needs to be passed.
00080     if not IDateTime.providedBy(time):
00081         try:
00082             time = DateTime(time)
00083         except:
00084             log('Failed to convert %s to a DateTime object' % time,
00085                 severity=logging.DEBUG)
00086             return None
00087 
00088     if context is None:
00089         # when without context, we cannot do very much.
00090         return time.ISO()
00091 
00092     if request is None:
00093         request = aq_acquire(context, 'REQUEST')
00094 
00095     # get the formatstring
00096     formatstring = translate(msgid, domain, mapping, request)
00097 
00098     if formatstring is None or formatstring.startswith('date_'):
00099         # msg catalog was not able to translate this msgids
00100         # use default setting
00101 
00102         properties=getToolByName(context, 'portal_properties').site_properties
00103         if long_format:
00104             format=properties.localLongTimeFormat
00105         else:
00106             format=properties.localTimeFormat
00107 
00108         return time.strftime(format)
00109     
00110     # get the format elements used in the formatstring
00111     formatelements = _interp_regex.findall(formatstring)
00112     # reformat the ${foo} to foo
00113     formatelements = [el[2:-1] for el in formatelements]
00114 
00115     # add used elements to mapping
00116     elements = [e for e in formatelements if e in datetime_formatvariables]
00117 
00118     # add weekday name, abbr. weekday name, month name, abbr month name
00119     week_included = True
00120     month_included = True
00121 
00122     name_elements = [e for e in formatelements if e in name_formatvariables]
00123     if not ('a' in name_elements or 'A' in name_elements):
00124         week_included = False
00125     if not ('b' in name_elements or 'B' in name_elements):
00126         month_included = False
00127 
00128     for key in elements:
00129         mapping[key]=time.strftime('%'+key)
00130 
00131     if week_included:
00132         weekday = int(time.strftime('%w')) # weekday, sunday = 0
00133         if 'a' in name_elements:
00134             mapping['a']=weekdayname_msgid_abbr(weekday)
00135         if 'A' in name_elements:
00136             mapping['A']=weekdayname_msgid(weekday)
00137     if month_included:
00138         monthday = int(time.strftime('%m')) # month, january = 1
00139         if 'b' in name_elements:
00140             mapping['b']=monthname_msgid_abbr(monthday)
00141         if 'B' in name_elements:
00142             mapping['B']=monthname_msgid(monthday)
00143 
00144     # translate translateable elements
00145     for key in name_elements:
00146         mapping[key] = translate(mapping[key], domain, context=request, default=mapping[key])
00147 
00148     # translate the time string
00149     return translate(msgid, domain, mapping, request)

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.i18nl10n.utranslate (   args,
  kw 
)

Definition at line 40 of file i18nl10n.py.

00040 
00041 def utranslate(*args, **kw):
00042     # safety precaution for cases where we get passed in an encoded string
00043     return safe_unicode(getGlobalTranslationService().translate(*args, **kw))
00044 
# unicode aware localized time method (l10n)

Here is the call graph for this function:

def CMFPlone.i18nl10n.weekdayname_english (   number,
  format = None 
)

Definition at line 172 of file i18nl10n.py.

00172 
00173 def weekdayname_english(number, format=None):
00174     # returns the english name of week with number
00175     return _numbertoenglishname(number, format=format, attr='_days')

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 188 of file i18nl10n.py.

00188 
00189 def weekdayname_msgid(number):
00190     # returns the msgid for the weekdayname
00191     # use to translate to full weekdayname (Monday, Tuesday, ...)
00192     # eg. weekday_mon, weekday_tue, ...
00193     return "weekday_%s" % weekdayname_english(number, format='a').lower()
    

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 194 of file i18nl10n.py.

00194 
00195 def weekdayname_msgid_abbr(number):
00196     # returns the msgid for abbreviated weekdayname
00197     # use to translate to abbreviated format (Mon, Tue, ...)
00198     # eg. weekday_mon_abbr, weekday_tue_abbr, ...
00199     return "weekday_%s_abbr" % weekdayname_english(number, format='a').lower()
    

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 200 of file i18nl10n.py.

00200 
00201 def weekdayname_msgid_short(number):
00202     # return the msgid for short weekdayname
00203     # use to translate to 2 char format (Mo, Tu, ...)
00204     # eg. weekday_mon_short, weekday_tue_short, ...
00205     return "weekday_%s_short" % weekdayname_english(number, format='a').lower()

Here is the call graph for this function:


Variable Documentation

tuple CMFPlone.i18nl10n._interp_regex = re.compile(r'(?<!\$)(\$(?:%(n)s|{%(n)s}))' %({'n': NAME_RE}))

Definition at line 34 of file i18nl10n.py.

tuple CMFPlone.i18nl10n.atctdomain = PTSTranslationDomain('atcontenttypes')

Definition at line 26 of file i18nl10n.py.

tuple CMFPlone.i18nl10n.cmfedomain = PTSTranslationDomain('cmfeditions')

Definition at line 30 of file i18nl10n.py.

tuple CMFPlone.i18nl10n.cmfpwdomain = PTSTranslationDomain('cmfplacefulworkflow')

Definition at line 29 of file i18nl10n.py.

tuple CMFPlone.i18nl10n.datetime_formatvariables = ('H', 'I', 'm', 'd', 'M', 'p', 'S', 'Y', 'y', 'Z')

Definition at line 36 of file i18nl10n.py.

tuple CMFPlone.i18nl10n.name_formatvariables = ('a', 'A', 'b', 'B')

Definition at line 37 of file i18nl10n.py.

string CMFPlone.i18nl10n.NAME_RE = r"[a-zA-Z][a-zA-Z0-9_]*"

Definition at line 33 of file i18nl10n.py.

tuple CMFPlone.i18nl10n.plonedomain = PTSTranslationDomain('plone')

Definition at line 25 of file i18nl10n.py.

tuple CMFPlone.i18nl10n.pltdomain = PTSTranslationDomain('plonelanguagetool')

Definition at line 27 of file i18nl10n.py.

tuple CMFPlone.i18nl10n.prtdomain = PTSTranslationDomain('passwordresettool')

Definition at line 28 of file i18nl10n.py.