ó
I()Qc           @   s4  d  d l  Z  d  d l Z d  d l m Z d  d l m Z d  d l m Z d  d l	 m
 Z
 m Z m Z m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d	 l m Z d  d
 l m Z d  d l m Z d „  Z d „  Z d Z d Z d Z d Z d Z  d Z! d Z" d Z# d d d „ Z% d d d „ Z& d S(   iÿÿÿÿN(   t   http(   t   settings(   t	   importlib(   t   check_for_languaget   activatet	   to_localet   get_language(   t   javascript_quote(   t
   smart_text(   t   get_format_modulest
   get_format(   t   upath(   t   is_safe_url(   t   sixc         C   sç   |  j  j d ƒ } t d | d |  j ƒ  ƒ sf |  j j d ƒ } t d | d |  j ƒ  ƒ sf d } qf n  t j | ƒ } |  j d k rã |  j j d d
 ƒ } | rã t
 | ƒ rã t |  d ƒ rÊ | |  j d	 <qà | j t j | ƒ qã n  | S(   s¯  
    Redirect to a given url while setting the chosen language in the
    session or cookie. The url and the language code need to be
    specified in the request parameters.

    Since this view changes how the user will see the rest of the site, it must
    only be accessed as a POST request. If called as a GET request, it will
    redirect to the page in the request (the 'next' parameter) without changing
    any state.
    t   nextt   urlt   hostt   HTTP_REFERERt   /t   POSTt   languaget   sessiont   django_languageN(   t   REQUESTt   getR   t   get_hostt   METAR    t   HttpResponseRedirectt   methodR   t   NoneR   t   hasattrR   t
   set_cookieR   t   LANGUAGE_COOKIE_NAME(   t   requestR   t   responset	   lang_code(    (    s*   ../Django//lib/python/django/views/i18n.pyt   set_language   s    c          C   s%  d }  i  } x? t  g t d t ƒ D]' } x |  D] } t | ƒ | | <q0 Wq# Wg  } xÁ | j ƒ  D]³ \ } } t | t j t f ƒ r± | j	 d t
 | ƒ t
 t | ƒ ƒ f ƒ qa t | t t f ƒ ra g  | D] } t
 t | ƒ ƒ ^ qÍ } | j	 d t
 | ƒ d j | ƒ f ƒ qa qa Wd j | ƒ S(   s?   
    Returns all formats strings required for i18n to work
    t   DATE_FORMATt   DATETIME_FORMATt   TIME_FORMATt   YEAR_MONTH_FORMATt   MONTH_DAY_FORMATt   SHORT_DATE_FORMATt   SHORT_DATETIME_FORMATt   FIRST_DAY_OF_WEEKt   DECIMAL_SEPARATORt   THOUSAND_SEPARATORt   NUMBER_GROUPINGt   DATE_INPUT_FORMATSt   TIME_INPUT_FORMATSt   DATETIME_INPUT_FORMATSt   reverses   formats['%s'] = '%s';
s   formats['%s'] = ['%s'];
s   ', 't    (   R%   R&   R'   R(   R)   R*   R+   R,   R-   R.   R/   R0   R1   R2   (   R   R	   t   TrueR
   t   itemst
   isinstanceR   t   string_typest   intt   appendR   R   t   tuplet   listt   join(   t   FORMAT_SETTINGSt   resultt   modulet   attrt   srct   kt   vt   value(    (    s*   ../Django//lib/python/django/views/i18n.pyt   get_formats)   s"        ,%-sh  
/* gettext identity library */

function gettext(msgid) { return msgid; }
function ngettext(singular, plural, count) { return (count == 1) ? singular : plural; }
function gettext_noop(msgid) { return msgid; }
function pgettext(context, msgid) { return msgid; }
function npgettext(context, singular, plural, count) { return (count == 1) ? singular : plural; }
s3   
/* gettext library */

var catalog = new Array();
s^  

function gettext(msgid) {
  var value = catalog[msgid];
  if (typeof(value) == 'undefined') {
    return msgid;
  } else {
    return (typeof(value) == 'string') ? value : value[0];
  }
}

function ngettext(singular, plural, count) {
  value = catalog[singular];
  if (typeof(value) == 'undefined') {
    return (count == 1) ? singular : plural;
  } else {
    return value[pluralidx(count)];
  }
}

function gettext_noop(msgid) { return msgid; }

function pgettext(context, msgid) {
  var value = gettext(context + '\x04' + msgid);
  if (value.indexOf('\x04') != -1) {
    value = msgid;
  }
  return value;
}

function npgettext(context, singular, plural, count) {
  var value = ngettext(context + '\x04' + singular, context + '\x04' + plural, count);
  if (value.indexOf('\x04') != -1) {
    value = ngettext(singular, plural, count);
  }
  return value;
}
s7   
/* formatting library */

var formats = new Array();

sµ   
function get_format(format_type) {
    var value = formats[format_type];
    if (typeof(value) == 'undefined') {
      return format_type;
    } else {
      return value;
    }
}
s<   
function pluralidx(count) { return (count == 1) ? 0 : 1; }
só   
function interpolate(fmt, obj, named) {
  if (named) {
    return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])});
  } else {
    return fmt.replace(/%s/g, function(match){return String(obj.shift())});
  }
}
sz   
function pluralidx(n) {
  var v=%s;
  if (typeof(v) == 'boolean') {
    return v ? 1 : 0;
  } else {
    return v;
  }
}
c         C   s1   t  t t t ƒ  t g } t j d j | ƒ d ƒ S(   s}   
    Returns "identity" versions of the JavaScript i18n functions -- i.e.,
    versions that don't actually do anything.
    R4   s   text/javascript(   t
   NullSourcet   InterPolatet   LibFormatHeadRF   t   LibFormatFootR    t   HttpResponseR=   (   R!   t   domaint   packagesRB   (    (    s*   ../Django//lib/python/django/views/i18n.pyt   null_javascript_catalog£   s    t   djangojsc      	   C   s’  |  j  rE d |  j  k rE t |  j  d ƒ rB t |  j  d ƒ qB qE n  | d k r] d g } n  t | t j ƒ r | j d ƒ } n  g  | D]' } | d k s© | t j	 k rˆ | ^ qˆ } t
 t j ƒ } t
 t ƒ  ƒ } i  } g  } | j d ƒ } t }	 xT | D]L }
 t j |
 ƒ } t j j t j j t | j ƒ ƒ d ƒ } | j | ƒ qû W| j t t t j ƒ ƒ ƒ x] | D]U } y, t j | | d g ƒ } | j | j ƒ Wn t  k
 r³qnX| rnt! }	 qnqnW| d k r<xf | D][ } y t j | | | g ƒ } Wn t  k
 rd } n X| d k	 rÚ| j | j ƒ qÚqÚWn  | | k rÛ| r]|	 r]i  } qÛi  } xc | D][ } y t j | | | g ƒ } Wn t  k
 r¥d } n X| d k	 rj| j | j ƒ qjqjW| rÛ| } qÛn  t" g } d } d | k rExL | d j d ƒ D]4 } | j d ƒ r
| j d	 d
 ƒ d
 j# ƒ  } q
q
Wn  | d k	 r¶g  | j d ƒ D]' } | j# ƒ  j d ƒ ra| j# ƒ  ^ qad j d d
 ƒ d
 } | j t$ | ƒ n | j t% ƒ g  } i  } xø | j& ƒ  D]ê \ } } | d k rúqÜn  t | t j ƒ r2| j d t' | ƒ t' | ƒ f ƒ qÜt | t( ƒ rº| d | k rf| d
 | | d <n# t) | d
 | | d ƒ | | d <| j d t' | d ƒ | d
 t' | ƒ f ƒ qÜt* | ƒ ‚ qÜW| j+ ƒ  xK | j& ƒ  D]= \ } } | j d t' | ƒ d j d g | d
 ƒ f ƒ qáW| j | ƒ | j t, ƒ | j t- ƒ | j t. ƒ | j t/ ƒ  ƒ | j t0 ƒ d j | ƒ } t1 j2 | d ƒ S(   s  
    Returns the selected language catalog as a javascript library.

    Receives the list of packages to check for translations in the
    packages parameter either from an infodict or as a +-delimited
    string from the request. Default is 'django.conf'.

    Additionally you can override the gettext domain for this view,
    but usually you don't want to do that, as JavaScript messages
    go to the djangojs domain. But this might be needed if you
    deliver your JavaScript source from Django templates.
    R   s   django.conft   +t   ent   localeR4   s   
s   Plural-Forms:t   :i   t   ;s   plural=i    t   =s   catalog['%s'] = '%s';
s   catalog['%s'][%d] = '%s';
s   catalog['%s'] = [%s];
t   ,s   ''s   text/javascriptN(3   t   GETR   R   R   R7   R   R8   t   splitR   t   INSTALLED_APPSR   t   LANGUAGE_CODER   t
   startswithR5   R   t   import_modulet   ost   pathR=   t   dirnameR   t   __file__R:   t   extendR<   t   reversedt   LOCALE_PATHSt   gettext_modulet   translationt   updatet   _catalogt   IOErrort   Falset   LibHeadt   stript	   PluralIdxt   SimplePluralR6   R   R;   t   maxt	   TypeErrort   sortt   LibFootRH   RI   RF   RJ   R    RK   (   R!   RL   RM   t   pt   default_localeRR   t   tt   pathst   en_selectedt   en_catalog_missingt   packageR^   t   catalogt   locale_tRB   t   pluralt   lt   elt   csrct   pdictRC   RD   (    (    s*   ../Django//lib/python/django/views/i18n.pyt   javascript_catalog«   s¦    	4*
	
	&Q&#1
5('   R]   t   gettextRd   t   djangoR    t   django.confR   t   django.utilsR   t   django.utils.translationR   R   R   R   t   django.utils.textR   t   django.utils.encodingR   t   django.utils.formatsR	   R
   t   django.utils._osR   t   django.utils.httpR   R   R$   RF   RG   Rj   Rq   RI   RJ   Rm   RH   Rl   R   RN   R€   (    (    (    s*   ../Django//lib/python/django/views/i18n.pyt   <module>   s.   "		 '
