Browse Source

Add language to html tag (#197)

Hayley Hartman 5 years ago
parent
commit
7b18229697

+ 7 - 2
coderedcms/project_template/project_name/settings/base.py

@@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/
 
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 import os
+from django.utils.translation import gettext_lazy as _
 
 PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 BASE_DIR = os.path.dirname(PROJECT_DIR)
@@ -138,15 +139,19 @@ AUTH_PASSWORD_VALIDATORS = [
     },
 ]
 
-
 # Internationalization
 # https://docs.djangoproject.com/en/{{ docs_version }}/topics/i18n/
 
+# To add or change language of the project, modify the list below.
 LANGUAGE_CODE = 'en-us'
 
+LANGUAGES = [
+    ('en-us', _('English'))
+]
+
 TIME_ZONE = 'America/New_York'
 
-USE_I18N = False
+USE_I18N = True
 
 USE_L10N = True
 

+ 4 - 1
coderedcms/templates/coderedcms/pages/base.html

@@ -1,8 +1,11 @@
 {% load static coderedcms_tags i18n wagtailcore_tags wagtailimages_tags wagtailsettings_tags wagtailuserbar %}
 {% get_settings %}
+{% load i18n %}
+{% get_current_language as LANGUAGE_CODE %}
+
 
 <!doctype html>
-<html prefix="og: http://ogp.me/ns#">
+<html prefix="og: http://ogp.me/ns#" lang="{{ LANGUAGE_CODE }}">
   <head>
         {% block tracking %}
         {% if settings.coderedcms.AnalyticsSettings.ga_tracking_id %}

+ 7 - 1
coderedcms/tests/settings.py

@@ -12,6 +12,8 @@ https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/
 
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 import os
+from django.utils.translation import gettext_lazy as _
+
 
 PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 BASE_DIR = os.path.dirname(PROJECT_DIR)
@@ -145,9 +147,13 @@ AUTH_PASSWORD_VALIDATORS = [
 
 LANGUAGE_CODE = 'en-us'
 
+LANGUAGES = [
+    ('en-us', _('English')),
+]
+
 TIME_ZONE = 'America/New_York'
 
-USE_I18N = False
+USE_I18N = True
 
 USE_L10N = True
 

+ 20 - 0
docs/getting_started/customize_develop.rst

@@ -35,3 +35,23 @@ affect the caching decision. For example::
         if 'nocache' in request.GET:
             return False
 
+
+Default Language
+----------------
+
+To adjust the default language of a project, navigate to Project_Name/Project_Name/settings/base.py. Change both the
+LANGUAGE_CODE setting and the LANGUAGES setting. For example::
+
+        LANGUAGE_CODE = 'es'
+
+        LANGUAGES = [
+            ('es', _('Spanish'))
+        ]
+
+Note that these settings are both in use to communicate to the users' browser about the default language of the project.
+This ensures that users requiring assistive technology have a smooth experience using the site. These settings do not,
+on their own, translate or enable multiple languages on the project.
+
+`For a full list of language codes, see this list from W3 Docs. <https://www.w3docs.com/learn-html/html-language-codes.html>`_
+
+