Ejemplo n.º 1
0
 def test_new_lang_files_do_not_modify_settings(self, trans_patch):
     """
     Test to make sure that building the new lang files list does not
     modify `settings.DOTLANG_FILES`.
     """
     old_setting = settings.DOTLANG_FILES[:]
     trans_str = 'Translate me'
     _(trans_str)
     call_lang_files = [LANG_FILES] + settings.DOTLANG_FILES
     trans_patch.assert_called_with(trans_str, call_lang_files)
     eq_(old_setting, settings.DOTLANG_FILES)
Ejemplo n.º 2
0
 def test_new_lang_files_do_not_modify_settings(self, trans_patch):
     """
     Test to make sure that building the new lang files list does not
     modify `settings.DOTLANG_FILES`.
     """
     old_setting = settings.DOTLANG_FILES[:]
     trans_str = 'Translate me'
     _(trans_str)
     call_lang_files = [LANG_FILES] + settings.DOTLANG_FILES
     trans_patch.assert_called_with(trans_str, call_lang_files)
     eq_(old_setting, settings.DOTLANG_FILES)
Ejemplo n.º 3
0
 def clean(self, *args, **kwargs):
     super(ContributeUniversityAmbassadorForm, self).clean(*args, **kwargs)
     if (self.cleaned_data.get('current_status', '') == 'student'
             and not self.cleaned_data.get('expected_graduation_year', '')):
         self._errors['expected_graduation_year'] = (
             self.error_class([_('This field is required.')]))
     return self.cleaned_data
Ejemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     locale = kwargs.get('locale', 'en-US')
     super(ContributeUniversityAmbassadorForm, self).__init__(*args, **kwargs)
     country_list = product_details.get_regions(locale).items()
     country_list = sorted(country_list, key=lambda country: country[1])
     country_list.insert(0, ('', _('Country')))
     self.fields['country'].choices = country_list
Ejemplo n.º 5
0
    def test_gettext_searches_kwarg_specified_lang_files(self, trans_patch):
        """
        The `l10n_utils.dotlang._` function should search .lang files
        specified in the `lang_files` keyword arg, and not the ones from the
        module.
        """
        # test the case when LANG_FILES is a string
        trans_str = 'Translate me'
        _(trans_str, lang_files='maude')
        call_lang_files = ['maude'] + settings.DOTLANG_FILES
        trans_patch.assert_called_with(trans_str, call_lang_files)

        # test the case when LANG_FILES is a list
        lang_files_list = ['maude', 'bunny', 'uli']
        _(trans_str, lang_files=lang_files_list)
        call_lang_files = lang_files_list + settings.DOTLANG_FILES
        trans_patch.assert_called_with(trans_str, call_lang_files)
Ejemplo n.º 6
0
    def test_gettext_searches_kwarg_specified_lang_files(self, trans_patch):
        """
        The `l10n_utils.dotlang._` function should search .lang files
        specified in the `lang_files` keyword arg, and not the ones from the
        module.
        """
        # test the case when LANG_FILES is a string
        trans_str = 'Translate me'
        _(trans_str, lang_files='maude')
        call_lang_files = ['maude'] + settings.DOTLANG_FILES
        trans_patch.assert_called_with(trans_str, call_lang_files)

        # test the case when LANG_FILES is a list
        lang_files_list = ['maude', 'bunny', 'uli']
        _(trans_str, lang_files=lang_files_list)
        call_lang_files = lang_files_list + settings.DOTLANG_FILES
        trans_patch.assert_called_with(trans_str, call_lang_files)
Ejemplo n.º 7
0
    def test_gettext_ignores_default_lang_files(self, trans_patch):
        """
        The `l10n_utils.dotlang._` function should search .lang files
        specified in the module from which it's called before the
        default files, but it should not include the defaults twice.
        """
        # use LANG_FILES global in this module
        global LANG_FILES
        old_lang_files = LANG_FILES

        trans_str = 'Translate me'
        LANG_FILES = [settings.DOTLANG_FILES[0], 'dude', 'donnie', 'walter']
        _(trans_str)
        call_lang_files = LANG_FILES[1:] + settings.DOTLANG_FILES
        trans_patch.assert_called_with(trans_str, call_lang_files)

        # restore original value to avoid test leakage
        LANG_FILES = old_lang_files
Ejemplo n.º 8
0
def contribute(request, template, return_to_form):
    has_contribute_form = (request.method == 'POST' and
                           'contribute-form' in request.POST)

    has_newsletter_form = (request.method == 'POST' and
                           'newsletter-form' in request.POST)

    locale = getattr(request, 'locale', 'en-US')

    contribute_success = False
    newsletter_success = False

    # This is ugly, but we need to handle two forms. I would love if
    # these forms could post to separate pages and get redirected
    # back, but we're forced to keep the error/success workflow on the
    # same page. Please change this.
    if has_contribute_form:
        form = ContributeForm(request.POST)
        contribute_success = email_contribute.handle_form(request, form)
        if contribute_success:
            # If form was submitted successfully, return a new, empty
            # one.
            form = ContributeForm()
    else:
        form = ContributeForm()

    if has_newsletter_form:
        newsletter_form = NewsletterForm(locale,
                                         request.POST,
                                         prefix='newsletter')
        if newsletter_form.is_valid():
            data = newsletter_form.cleaned_data

            try:
                basket.subscribe(data['email'],
                                 'about-mozilla',
                                 format=data['fmt'],
                                 country=data['country'])
                newsletter_success = True
            except basket.BasketException:
                msg = newsletter_form.error_class(
                    [_('We apologize, but an error occurred in our system. '
                       'Please try again later.')]
                )
                newsletter_form.errors['__all__'] = msg
    else:
        newsletter_form = NewsletterForm(locale, prefix='newsletter')

    return l10n_utils.render(request,
                             template,
                             {'form': form,
                              'contribute_success': contribute_success,
                              'newsletter_form': newsletter_form,
                              'newsletter_success': newsletter_success,
                              'return_to_form': return_to_form,
                              'hide_form': hide_contrib_form(request.locale),
                              'has_moz15': locale in settings.LOCALES_WITH_MOZ15})
Ejemplo n.º 9
0
    def test_gettext_ignores_default_lang_files(self, trans_patch):
        """
        The `l10n_utils.dotlang._` function should search .lang files
        specified in the module from which it's called before the
        default files, but it should not include the defaults twice.
        """
        # use LANG_FILES global in this module
        global LANG_FILES
        old_lang_files = LANG_FILES

        trans_str = 'Translate me'
        LANG_FILES = [settings.DOTLANG_FILES[0], 'dude', 'donnie', 'walter']
        _(trans_str)
        call_lang_files = LANG_FILES[1:] + settings.DOTLANG_FILES
        trans_patch.assert_called_with(trans_str, call_lang_files)

        # restore original value to avoid test leakage
        LANG_FILES = old_lang_files
Ejemplo n.º 10
0
    def render(self, name, value, attrs=None):
        attrs['required'] = 'true'
        input_txt = super(PrivacyWidget, self).render(name, value, attrs)

        policy_txt = _('I agree to the <a href="%s">Privacy Policy</a>')
        return mark_safe(
            '<label for="%s" class="privacy-check-label">'
            '%s '
            '<span class="title">%s</span></label>' %
            (attrs['id'], input_txt, policy_txt % '/en-US/privacy-policy'))
Ejemplo n.º 11
0
 def render(self, name, value, attrs=None):
     honeypot_txt = _(u'Check this box if you are not human.')
     # semi-randomized in case we have more than one per page.
     # this is maybe/probably overthought
     honeypot_id = 'super-priority-' + str(randrange(1001)) + '-' + str(datetime.now().strftime("%Y%m%d%H%M%S%f"))
     return mark_safe(
         '<div class="super-priority-field">'
         '<label for="%s" class="super-priority-check-label">%s</label>'
         '<input type="checkbox" name="superpriority" id="%s">'
         '</div>' % (honeypot_id, honeypot_txt, honeypot_id))
Ejemplo n.º 12
0
 def clean_number(self):
     mobile = self.cleaned_data['number']
     mobile = re.sub(r'\D+', '', mobile)
     if len(mobile) == 10:
         mobile = '1' + mobile
     elif len(mobile) != 11 or mobile[0] != '1':
         raise forms.ValidationError(
             _('Sorry. This number isn\'t valid. Please enter a U.S. phone '
               'number or <a href="%s">download directly '
               'from Google Play.</a>') % 'http://mzl.la/OgZo6k')
     return mobile
    def render(self, name, value, attrs=None):
        attrs['required'] = 'true'
        input_txt = super(PrivacyWidget, self).render(name, value, attrs)

        policy_txt = _(u'I’m okay with you handling this info as you explain '
                       u'in your <a href="%s">Privacy Policy</a>')
        return mark_safe(
            '<label for="%s" class="privacy-check-label">'
            '%s '
            '<span class="title">%s</span></label>' %
            (attrs['id'], input_txt, policy_txt % '/en-US/privacy-policy'))
Ejemplo n.º 14
0
    def render(self, name, value, attrs=None):
        attrs['required'] = 'true'
        input_txt = super(PrivacyWidget, self).render(name, value, attrs)

        policy_txt = _('I agree to the <a href="%s">Privacy Policy</a>')
        return mark_safe(
            '<label for="%s" class="privacy-check-label">'
            '%s '
            '<span class="title">%s</span></label>'
            % (attrs['id'], input_txt,
               policy_txt % '/en-US/privacy-policy')
         )
Ejemplo n.º 15
0
    def render(self, name, value, attrs=None):
        attrs["required"] = "required"
        input_txt = super(PrivacyWidget, self).render(name, value, attrs)

        policy_txt = _(
            u"I’m okay with you handling this info as you explain " u'in your <a href="%s">Privacy Policy</a>'
        )
        return mark_safe(
            '<label for="%s" class="privacy-check-label">'
            "%s "
            '<span class="title">%s</span></label>' % (attrs["id"], input_txt, policy_txt % "/en-US/privacy-policy")
        )
Ejemplo n.º 16
0
    def render(self, name, value, attrs=None):
        attrs['required'] = 'true'
        input_txt = super(PrivacyWidget, self).render(name, value, attrs)

        policy_txt = _(u'I’m okay with you handling this info as you explain in your <a href="%s">Privacy Policy</a>')
        return mark_safe(
            '<label for="%s" class="privacy-check-label">'
            '%s '
            '<span class="title">%s</span></label>'
            % (attrs['id'], input_txt,
               policy_txt % '/en-US/privacy-policy')
         )
Ejemplo n.º 17
0
 def clean_number(self):
     mobile = self.cleaned_data['number']
     mobile = re.sub(r'\D+', '', mobile)
     if len(mobile) == 10:
         mobile = '1' + mobile
     elif len(mobile) != 11 or mobile[0] != '1':
         raise forms.ValidationError(_(
             'Sorry. This number isn\'t valid. Please enter a U.S. phone '
             'number or <a href="%s">download directly '
             'from Google Play.</a>'
         ) % 'http://mzl.la/OgZo6k')
     return mobile
Ejemplo n.º 18
0
    def test_gettext_searches_specified_lang_files(self, trans_patch):
        """
        The `l10n_utils.dotlang._` function should search .lang files
        specified in the module from which it's called before the
        default files.
        """
        # use LANG_FILES global in this module
        global LANG_FILES
        old_lang_files = LANG_FILES

        # test the case when LANG_FILES is a string
        trans_str = 'Translate me'
        _(trans_str)
        call_lang_files = [LANG_FILES] + settings.DOTLANG_FILES
        trans_patch.assert_called_with(trans_str, call_lang_files)

        # test the case when LANG_FILES is a list
        LANG_FILES = ['dude', 'donnie', 'walter']
        _(trans_str)
        call_lang_files = LANG_FILES + settings.DOTLANG_FILES
        trans_patch.assert_called_with(trans_str, call_lang_files)

        # restore original value to avoid test leakage
        LANG_FILES = old_lang_files
Ejemplo n.º 19
0
    def test_gettext_searches_specified_lang_files(self, trans_patch):
        """
        The `l10n_utils.dotlang._` function should search .lang files
        specified in the module from which it's called before the
        default files.
        """
        # use LANG_FILES global in this module
        global LANG_FILES
        old_lang_files = LANG_FILES

        # test the case when LANG_FILES is a string
        trans_str = 'Translate me'
        _(trans_str)
        call_lang_files = [LANG_FILES] + settings.DOTLANG_FILES
        trans_patch.assert_called_with(trans_str, call_lang_files)

        # test the case when LANG_FILES is a list
        LANG_FILES = ['dude', 'donnie', 'walter']
        _(trans_str)
        call_lang_files = LANG_FILES + settings.DOTLANG_FILES
        trans_patch.assert_called_with(trans_str, call_lang_files)

        # restore original value to avoid test leakage
        LANG_FILES = old_lang_files
Ejemplo n.º 20
0
def contribute_university_ambassadors(request):
    form = ContributeUniversityAmbassadorForm(request.POST or None)
    if form.is_valid():
        try:
            form.save()
        except basket.BasketException:
            msg = form.error_class(
                [_('We apologize, but an error occurred in our system. '
                   'Please try again later.')])
            form.errors['__all__'] = msg
        else:
            return redirect('mozorg.contribute_university_ambassadors_thanks')
    return l10n_utils.render(
        request,
        'mozorg/contribute_university_ambassadors.html', {'form': form}
    )
Ejemplo n.º 21
0
def sms_send(request):
    form = SMSSendForm(request.POST or None)
    if request.method == 'POST' and form.is_valid():
        try:
            basket.send_sms(form.cleaned_data['number'], 'SMS_Android',
                            form.cleaned_data['optin'])
        except basket.BasketException:
            msg = form.error_class([
                _('An error occurred in our system. '
                  'Please try again later.')
            ])
            form.errors['__all__'] = msg
        else:
            return HttpResponseRedirect(reverse('firefox.mobile.sms-thankyou'))
    return l10n_utils.render(request, 'firefox/mobile/sms-send.html',
                             {'sms_form': form})
Ejemplo n.º 22
0
def sms_send(request):
    form = SMSSendForm(request.POST or None)
    if request.method == 'POST' and form.is_valid():
        try:
            basket.send_sms(form.cleaned_data['number'],
                            'SMS_Android',
                            form.cleaned_data['optin'])
        except basket.BasketException:
            msg = form.error_class(
                [_('An error occurred in our system. '
                   'Please try again later.')]
            )
            form.errors['__all__'] = msg
        else:
            return HttpResponseRedirect(
                reverse('firefox.mobile.sms-thankyou'))
    return l10n_utils.render(request, 'firefox/mobile/sms-send.html',
                             {'sms_form': form})
Ejemplo n.º 23
0
from collections import namedtuple

from django.core.mail import EmailMessage

import basket
import jingo
from jinja2.exceptions import TemplateNotFound

from l10n_utils.dotlang import _lazy as _

fa = namedtuple('FunctionalArea', ['id', 'name', 'subject', 'contacts'])

FUNCTIONAL_AREAS = (
    fa('support',
        _('Helping Users'),
        'Support',
        ['*****@*****.**', '*****@*****.**', '*****@*****.**'],
    ),
    fa('qa',
        _('Testing and QA'),
        'QA',
        ['*****@*****.**'],
    ),
    fa('coding',
        _('Coding'),
        'Coding',
        ['*****@*****.**'],
    ),
    fa('marketing',
        _('Marketing'),
        'Marketing',
Ejemplo n.º 24
0
def do_translate():
    return _(u"I'm The Dude, so that's what you call me, man.")
Ejemplo n.º 25
0
 def test_gettext_str_interpolation(self):
     result = _("The %s %s.", "dude", "abides")
     eq_(result, "The dude abides.")
Ejemplo n.º 26
0
from collections import namedtuple

from django.core.mail import EmailMessage

import basket
import jingo
from jinja2.exceptions import TemplateNotFound

from l10n_utils.dotlang import _lazy as _


fa = namedtuple('FunctionalArea', ['id', 'name', 'subject', 'contacts'])
LANG_FILES = 'mozorg/contribute'
FUNCTIONAL_AREAS = (
    fa('support',
        _('Helping Users'),
        'Support',
        ['*****@*****.**', '*****@*****.**', '*****@*****.**'],
    ),
    fa('qa',
        _('Testing and QA'),
        'QA',
        ['*****@*****.**'],
    ),
    fa('coding',
        _('Coding'),
        'Coding',
        ['*****@*****.**'],
    ),
    fa('marketing',
        _('Marketing'),
Ejemplo n.º 27
0
from collections import namedtuple

from django.core.mail import EmailMessage

import basket
import jingo
from jinja2.exceptions import TemplateNotFound

from l10n_utils.dotlang import _lazy as _

fa = namedtuple('FunctionalArea', ['id', 'name', 'subject', 'contacts'])
LANG_FILES = 'mozorg/contribute'
FUNCTIONAL_AREAS = (
    fa(
        'support',
        _('Helping Users'),
        'Support',
        ['*****@*****.**', '*****@*****.**', '*****@*****.**'],
    ),
    fa(
        'qa',
        _('Testing and QA'),
        'QA',
        ['*****@*****.**'],
    ),
    fa(
        'coding',
        _('Coding'),
        'Coding',
        ['*****@*****.**'],
    ),
Ejemplo n.º 28
0
# coding: utf-8

from l10n_utils.dotlang import _


LANG_FILES = [
    'lebowski',
    'dude',
]

dude_says = _(u"I'm The Dude, so that's what you call me, man.")
Ejemplo n.º 29
0
def do_translate():
    return _(u"I'm The Dude, so that's what you call me, man.")
Ejemplo n.º 30
0

class NewsletterCountryForm(NewsletterForm):
    def __init__(self, locale, *args, **kwargs):
        regions = product_details.get_regions(locale)
        regions = sorted(regions.iteritems(), key=lambda x: x[1])
        locale = locale.lower()

        if locale.find('-') != -1:
            locale = locale.split('-')[1]

        super(NewsletterCountryForm, self).__init__(*args, **kwargs)
        self.fields['country'] = forms.ChoiceField(choices=regions,
                                                   initial=locale)

INTEREST_CHOICES = (('', _('Area of interest?')),
                    ('Support', _('Helping Users')),
                    ('QA', _('Testing and QA')),
                    ('Coding', _('Coding')),
                    ('Marketing', _('Marketing')),
                    ('Localization', _('Localization and Translation')),
                    ('Webdev', _('Web Development')),
                    ('Add-ons', _('Add-ons')),
                    ('Design', _('Visual Design')),
                    ('Documentation', _('Developer Documentation')),
                    ('Accessibility', _('Accessibility')),
                    ('IT', _('Systems Administration')),
                    ('Research', _('User Research')),
                    ('Education', 'Education'),
                    ('Thunderbird', _('Thunderbird')),
                    (' ', _('Other')),
Ejemplo n.º 31
0
# coding: utf-8

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from l10n_utils.dotlang import _


LANG_FILES = [
    'lebowski',
    'dude',
]

dude_says = _(u"I'm The Dude, so that's what you call me, man.")
Ejemplo n.º 32
0
from collections import namedtuple

from django.core.mail import EmailMessage

import basket
import jingo
from jinja2.exceptions import TemplateNotFound

from l10n_utils.dotlang import _lazy as _

fa = namedtuple('FunctionalArea', ['id', 'name', 'subject', 'contacts'])

FUNCTIONAL_AREAS = (
    fa('support',
        _('Helping Users'),
        'Support',
        ['*****@*****.**', '*****@*****.**', '*****@*****.**'],
    ),
    fa('qa',
        _('Testing and QA'),
        'QA',
        ['*****@*****.**'],
    ),
    fa('coding',
        _('Coding'),
        'Coding',
        ['*****@*****.**'],
    ),
    fa('marketing',
        _('Marketing'),
        'Marketing',
Ejemplo n.º 33
0
 def test_gettext_str_interpolation(self):
     result = _('The %s %s.', 'dude', 'abides')
     eq_(result, 'The dude abides.')
Ejemplo n.º 34
0
from collections import namedtuple

from django.core.mail import EmailMessage

import basket
import jingo
from jinja2.exceptions import TemplateNotFound

from l10n_utils.dotlang import _lazy as _


fa = namedtuple("FunctionalArea", ["id", "name", "subject", "contacts"])
LANG_FILES = "mozorg/contribute"
FUNCTIONAL_AREAS = (
    fa("support", _("Helping Users"), "Support", ["*****@*****.**", "*****@*****.**", "*****@*****.**"]),
    fa("qa", _("Testing and QA"), "QA", ["*****@*****.**"]),
    fa("coding", _("Coding"), "Coding", ["*****@*****.**"]),
    fa("marketing", _("Marketing"), "Marketing", ["*****@*****.**"]),
    fa(
        "localization",
        _("Localization and Translation"),
        "Localization",
        ["*****@*****.**", "*****@*****.**", "*****@*****.**"],
    ),
    fa("webdev", _("Web Development"), "Webdev", ["*****@*****.**"]),
    fa("addons", _("Add-ons"), "Add-ons", ["*****@*****.**"]),
    fa("design", _("Visual Design"), "Design", ["*****@*****.**"]),
    fa("documentation", _("Documentation and Writing"), "Documentation", ["*****@*****.**"]),
    fa("education", _("Education"), "Education", ["*****@*****.**"]),
    fa("other", _("Other"), "", ["*****@*****.**"]),
Ejemplo n.º 35
0
 def test_gettext_str_interpolation(self):
     result = _('The %s %s.', 'dude', 'abides')
     eq_(result, 'The dude abides.')
Ejemplo n.º 36
0
def do_translate():
    _(u'Stuff\xa0about\r\nmany\t   things.')
Ejemplo n.º 37
0
class NewsletterCountryForm(NewsletterForm):
    def __init__(self, locale, *args, **kwargs):
        regions = product_details.get_regions(locale)
        regions = sorted(regions.iteritems(), key=lambda x: x[1])
        locale = locale.lower()

        if locale.find('-') != -1:
            locale = locale.split('-')[1]

        super(NewsletterCountryForm, self).__init__(*args, **kwargs)
        self.fields['country'] = forms.ChoiceField(choices=regions,
                                                   initial=locale)


INTEREST_CHOICES = (('', _('Area of interest?')), ('Support',
                                                   _('Helping Users')),
                    ('QA', _('Testing and QA')), ('Coding', _('Coding')),
                    ('Marketing',
                     _('Marketing')), ('Localization',
                                       _('Localization and Translation')),
                    ('Webdev', _('Web Development')),
                    ('Add-ons', _('Add-ons')), ('Design', _('Visual Design')),
                    ('Documentation',
                     _('Developer Documentation')), ('Accessibility',
                                                     _('Accessibility')),
                    ('IT', _('Systems Administration')), ('Research',
                                                          _('User Research')),
                    ('Education', 'Education'), ('Thunderbird',
                                                 _('Thunderbird')),
                    (' ', _('Other')), ('Firefox Suggestions',
Ejemplo n.º 38
0
def do_translate():
    _(u'Stuff\xa0about\r\nmany\t   things.')