Skip to content

Commit

Permalink
Fix #813 - Add Fluent l10n library to Django project
Browse files Browse the repository at this point in the history
  • Loading branch information
maxxcrawford committed May 28, 2021
1 parent fcac5a7 commit 4d23fd7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions privaterelay/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

def django_settings(request):
return {'settings': settings}

def ftl_mode(request):
return {'ftl_mode': 'server'}
3 changes: 3 additions & 0 deletions privaterelay/ftl_bundles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django_ftl.bundles import Bundle

main = Bundle(['privaterelay/brands.ftl', 'privaterelay/home.ftl'])
6 changes: 6 additions & 0 deletions privaterelay/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
'django.contrib.sites',
'django.contrib.staticfiles',

'django_ftl.apps.DjangoFtlConfig',

'dockerflow.django',

'allauth',
Expand Down Expand Up @@ -191,6 +193,9 @@ def _get_initial_middleware():
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',

"django.middleware.locale.LocaleMiddleware",
"django_ftl.middleware.activate_from_request_language_code",

'csp.middleware.CSPMiddleware',
'django_referrer_policy.middleware.ReferrerPolicyMiddleware',
'dockerflow.django.middleware.DockerflowMiddleware',
Expand All @@ -215,6 +220,7 @@ def _get_initial_middleware():

'emails.context_processors.relay_from_domain',
'privaterelay.context_processors.django_settings',
'privaterelay.context_processors.ftl_mode',
],
},
},
Expand Down
5 changes: 4 additions & 1 deletion privaterelay/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{% load socialaccount %}
{% load static %}
{% load ftl %}
{% ftlconf mode=ftl_mode %}


<!DOCTYPE html>
<html lang="en" dir="ltr">
<html lang="{{ request.LANGUAGE_CODE }}" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
Expand Down
7 changes: 6 additions & 1 deletion privaterelay/templates/home.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{% extends "base.html" %}

{% load ftl %}
{% load socialaccount %}

{% block content %}

{% include "includes/messages.html" %}

{% withftl bundle='privaterelay.ftl_bundles.main' %}

<main data-landing-page="" class="flx row-full-width home-hero">
<div class="flx flx-row hero-content">
<div class="hero-left flx flx-col">
<h1 class="home-hero-headline">Hide your real email address to help protect your identity</h1>
<h1 class="home-hero-headline">{% ftlmsg 'home-hero-headline' %}</h1>
<span class="sub-head hero-sub-head">Firefox Relay makes it easy to create aliases, randomly generated email addresses that forward to your real inbox. Use it to protect your online accounts - and your identity - from hackers. Sign in with your Firefox account to get started.</span>
{% include "includes/landing_ctas.html" with page_position="landing-hero" %}
</div>
Expand Down Expand Up @@ -59,4 +62,6 @@ <h3 class="step-headline ff-Met">Manage your account</h3>
</div>
</div>

{% endwithftl %}

{% endblock %}
5 changes: 4 additions & 1 deletion privaterelay/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
)
from emails.utils import get_post_data_from_request

from .ftl_bundles import main as main_bundle

FXA_PROFILE_CHANGE_EVENT = (
'https://schemas.accounts.firefox.com/event/profile-change'
Expand All @@ -55,7 +56,9 @@
def home(request):
if (request.user and not request.user.is_anonymous):
return redirect(reverse('profile'))
return render(request, 'home.html')
return render(request, 'home.html', {
'ftl_bundle': main_bundle,
})


def faq(request):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ django-allauth==0.39.1
django-csp==3.5
django-debug-toolbar==2.2.1
django-redis==4.12.1
django-ftl==0.12.1
django-referrer-policy==1.0
dockerflow==2020.6.0
google-measurement-protocol==1.0.0
Expand Down

0 comments on commit 4d23fd7

Please sign in to comment.