[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Maposmatic-dev] [PATCH] Add small infrastructure t o translate the Payp
From: |
Thomas Petazzoni |
Subject: |
[Maposmatic-dev] [PATCH] Add small infrastructure t o translate the Paypal stuff |
Date: |
Sat, 31 Mar 2012 11:59:11 +0200 |
We want the Paypal donation button to be translated, and the user to
be redirected to a page in his/her language when making a donation.
Unfortunately, Paypal does not seem to have translations for all the
languages we support, so we default to English when the language is
not available from Paypal.
This new mechanism requires translators to add a new entry in the
PAYPAL_LANGUAGES dictionary if Paypal provides a button and a site in
their language.
Signed-off-by: Thomas Petazzoni <address@hidden>
---
www/maposmatic/context_processors.py | 12 ++++++++++++
www/settings.py | 15 +++++++++++++++
www/templates/maposmatic/base.html | 5 +++--
www/templates/maposmatic/donate.html | 5 +++--
4 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/www/maposmatic/context_processors.py
b/www/maposmatic/context_processors.py
index a4cb772..f09ddef 100644
--- a/www/maposmatic/context_processors.py
+++ b/www/maposmatic/context_processors.py
@@ -22,6 +22,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.core.urlresolvers import reverse
+import django.utils.translation
import feedparser
from models import MapRenderingJob
@@ -54,10 +55,21 @@ def all(request):
# the rss feed
if request.path == reverse('rss-feed', args=['maps']):
return {}
+
+ l = django.utils.translation.get_language()
+ if www.settings.PAYPAL_LANGUAGES.has_key(l):
+ paypal_lang_code = www.settings.PAYPAL_LANGUAGES[l][0]
+ paypal_country_code = www.settings.PAYPAL_LANGUAGES[l][1]
+ else:
+ paypal_lang_code = "en_US"
+ paypal_country_code = "US"
+
return {
'randommap': MapRenderingJob.objects.get_random_with_thumbnail(),
'blogposts': get_latest_blog_posts(),
'MAPOSMATIC_DAEMON_RUNNING': www.settings.is_daemon_running(),
'osm_date': get_osm_database_last_update(),
'DEBUG': www.settings.DEBUG,
+ 'paypal_lang_code': paypal_lang_code,
+ 'paypal_country_code': paypal_country_code,
}
diff --git a/www/settings.py b/www/settings.py
index a3d50e1..aef3fde 100644
--- a/www/settings.py
+++ b/www/settings.py
@@ -123,6 +123,21 @@ LANGUAGES = (("fr", u"Français"),
("es", u"Español"),
("id", u"Bahasa Indonesia"))
+# Associate a Django language code with:
+# the language code used to select the Paypal button
+# the country code that allows to get the proper translation of the
+# PayPal payment page
+# When no association is found, we automatically default to english
+PAYPAL_LANGUAGES = {
+ "fr": ("fr_FR", "FR"),
+ "de": ("de_DE", "DE"),
+ "it": ("it_IT", "IT"),
+ "pt-br": ("pt_BR", "BR"),
+ "nl": ("nl_NL", "NL"),
+ "pl": ("pl_PL", "PL"),
+ "es": ("es_ES", "ES"),
+}
+
# Languages must be ordered by country (in xx_YY, YY is the country
# code), and then ordered with the most widely used language in the
# country first. For example, in France, we will want "French" to be
diff --git a/www/templates/maposmatic/base.html
b/www/templates/maposmatic/base.html
index e02a222..9831b81 100644
--- a/www/templates/maposmatic/base.html
+++ b/www/templates/maposmatic/base.html
@@ -92,8 +92,9 @@
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"
style="float: right; margin-left: 5px;">
<input type="hidden" name="cmd" value="_s-xclick"/>
<input type="hidden" name="hosted_button_id" value="YQPBAUM3JW8T2"/>
- <input type="image"
src="https://www.paypalobjects.com/en_GB/i/btn/btn_donate_LG.gif" border="0"
name="submit" alt="PayPal — The safer, easier way to pay online."/>
- <img alt="" border="0"
src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1"/>
+ <input type="hidden" name="country"
value="{{paypal_country_code}}"/>
+ <input type="image"
src="https://www.paypalobjects.com/{{paypal_lang_code}}/i/btn/btn_donate_LG.gif"
border="0" name="submit" alt="PayPal — The safer, easier way to pay online."/>
+ <img alt="" border="0"
src="https://www.paypalobjects.com/{{paypal_lang_code}}/i/scr/pixel.gif"
width="1" height="1"/>
</form>
<p>{% blocktrans %}You can donate to help us improve the
diff --git a/www/templates/maposmatic/donate.html
b/www/templates/maposmatic/donate.html
index 344d7c4..e9680e4 100644
--- a/www/templates/maposmatic/donate.html
+++ b/www/templates/maposmatic/donate.html
@@ -73,8 +73,9 @@ helpful.{%endblocktrans%}</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick"/>
<input type="hidden" name="hosted_button_id" value="YQPBAUM3JW8T2"/>
- <input type="image"
src="https://www.paypalobjects.com/en_GB/i/btn/btn_donate_LG.gif" border="0"
name="submit" alt="PayPal — The safer, easier way to pay online."/>
- <img alt="" border="0"
src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1"/>
+ <input type="hidden" name="country" value="{{paypal_country_code}}"/>
+ <input type="image"
src="https://www.paypalobjects.com/{{paypal_lang_code}}/i/btn/btn_donate_LG.gif"
border="0" name="submit" alt="PayPal — The safer, easier way to pay online."/>
+ <img alt="" border="0"
src="https://www.paypalobjects.com/{{paypal_lang_code}}/i/scr/pixel.gif"
width="1" height="1"/>
</form>
{% endblock %}
--
1.7.4.1
- [Maposmatic-dev] [PATCH] Add small infrastructure t o translate the Paypal stuff,
Thomas Petazzoni <=