SlideShare a Scribd company logo
1 of 27
i18n & L10n

 Thierry Sans
Internationalization (i18n)



” Internationalization is the process of designing a software
application so that it can be adapted to various languages and
regions without engineering changes. “                    Wikipedia


➡   Make an application language agnostic
Localization (L10n)



” Localization is the process of adapting internationalized
software for a specific region or language by adding locale-
specific components and translating text. “               Wikipedia


➡   Adapting an application for a specific language (aka locale)
It is is not only about language translation


  • Number format
  • Date/Time
  •   Sort orders
  • Units and conversion
  • Currency
  • Paper size
How does it work
Configure your locale preference
GET index.html
GET index.html
GET index.html




Google Français
GET index.html




Google Français
What are the difference locales?




   http://www.i18nguy.com/unicode/language-identifiers.html
Step 1 - Configure Django
settings.py

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'


# If you set this to False, Django will make some optimizations so as
# not to load the internationalization machinery.
USE_I18N = True


# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
Detects your locale from the HTTP request


                                                            settings.py
MIDDLEWARE_CLASSES = (
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)
settings.py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'WebDirectory',
    'HelloLocale',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)
Step 2 - Marking
Mark translation messages from a template
                                       HelloLocale/templates/HelloLocale/index.html

{% load i18n %}
<html>
<head>
   <title>{% trans "Hello World!" %}</title>
   ...
</head>
<body>
   <form action='sayhello/' method='post'>
          {% csrf_token %}
          <label>{% trans "Your name" %}</label>
          <input type="text" name="name"/>
   </form>
   <input type="button" value="{% trans "send" %}" onclick=" ...
<body>
</html>
Mark translation messages from views.py



                                                HelloLocale/views.py

  from django.utils.translation import ugettext as _


  def sayHello(request):
     name = request.POST['name']
     output = _('Hello %(name)s!') % {'name' : name}
      return HttpResponse(strip_tags(output))
Step 3 - Creating a locale
Create a locale


•   Create a locale directory in the app

•
$ cd HelloLocale
                                           The locale identifier
$ mkdir Locale

$ django-admin.py makemessages -l fr

➡   Generates a .po file
Define the translations
                                    HelloLocale/locale/fr/LC_MESSAGES/Django.po
#: views.py:20
#, python-format
msgid "Hello %(name)s!"
msgstr "Bonjour %(name)s!"


#: templates/HelloLocale/index.html:4
msgid "Hello World!"
msgstr "Bonjour tout le monde!"


#: templates/HelloLocale/index.html:11
msgid "Your name"
msgstr "Votre nom"


#: templates/HelloLocale/index.html:13
msgid "send"
msgstr "envoyer"
Compile locales




$ django-admin.py compilemessages

➡   Creates a .mo file
Update locales




$ django-admin.py makemessages -a

$ django-admin.py compilemessages
Custom locale
Custom locale



  from django.utils.translation import ugettext as _


  def sayHello(request):
      language = 'en-us'
     translation.activate(language)
     request.LANGUAGE_CODE = translation.get_language()
     name = request.POST['name']
     output = _('Hello %(name)s!') % {'name' : name}
     return HttpResponse(strip_tags(output))
Idea




•   The language preference is stored in the user’s profile

•   When the user is authenticated, store the language in a
    cookie or a session

More Related Content

What's hot

Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperf
New Relic
 

What's hot (20)

Catalog display
Catalog displayCatalog display
Catalog display
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
 
Build a bot workshop async primer - php[tek]
Build a bot workshop  async primer - php[tek]Build a bot workshop  async primer - php[tek]
Build a bot workshop async primer - php[tek]
 
Build REST API clients for AngularJS
Build REST API clients for AngularJSBuild REST API clients for AngularJS
Build REST API clients for AngularJS
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperf
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScript
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the web
 
REST in AngularJS
REST in AngularJSREST in AngularJS
REST in AngularJS
 
Apex & jQuery Mobile
Apex & jQuery MobileApex & jQuery Mobile
Apex & jQuery Mobile
 
Testing JavaScript with Jasmine in Rails Applications
Testing JavaScript with Jasmine in Rails Applications Testing JavaScript with Jasmine in Rails Applications
Testing JavaScript with Jasmine in Rails Applications
 
Automated testing with RSpec
Automated testing with RSpecAutomated testing with RSpec
Automated testing with RSpec
 
Dash of ajax
Dash of ajaxDash of ajax
Dash of ajax
 
Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium
 
Rspec API Documentation
Rspec API DocumentationRspec API Documentation
Rspec API Documentation
 
Angularjs Performance
Angularjs PerformanceAngularjs Performance
Angularjs Performance
 
Introduction to testing in Rails
Introduction to testing in RailsIntroduction to testing in Rails
Introduction to testing in Rails
 
Angular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd MottoAngular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd Motto
 
Beyond DOM Manipulations: Building Stateful Modules with Events and Promises
Beyond DOM Manipulations: Building Stateful Modules with Events and PromisesBeyond DOM Manipulations: Building Stateful Modules with Events and Promises
Beyond DOM Manipulations: Building Stateful Modules with Events and Promises
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless Apps
 
Tests in Javascript using Jasmine and Testacular
Tests in Javascript using Jasmine and TestacularTests in Javascript using Jasmine and Testacular
Tests in Javascript using Jasmine and Testacular
 

Viewers also liked

Viewers also liked (6)

Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
Running Node Applications on iOS and Android
Running Node Applications on iOS and AndroidRunning Node Applications on iOS and Android
Running Node Applications on iOS and Android
 
Titanium appcelerator kickstart
Titanium appcelerator kickstartTitanium appcelerator kickstart
Titanium appcelerator kickstart
 
Where Node.JS Meets iOS
Where Node.JS Meets iOSWhere Node.JS Meets iOS
Where Node.JS Meets iOS
 
Node.js code tracing
Node.js code tracingNode.js code tracing
Node.js code tracing
 
Create responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJSCreate responsive websites with Django, REST and AngularJS
Create responsive websites with Django, REST and AngularJS
 

Similar to I18n

GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
Yared Ayalew
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
Bo-Yi Wu
 

Similar to I18n (20)

WCRI 2015 I18N L10N
WCRI 2015 I18N L10NWCRI 2015 I18N L10N
WCRI 2015 I18N L10N
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Internationalizing Your AngularJS App
Internationalizing Your AngularJS AppInternationalizing Your AngularJS App
Internationalizing Your AngularJS App
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Introduction to angular js
Introduction to angular jsIntroduction to angular js
Introduction to angular js
 
Internationalization(i18n) of Web Page
Internationalization(i18n) of Web PageInternationalization(i18n) of Web Page
Internationalization(i18n) of Web Page
 
Django
DjangoDjango
Django
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
 
AngularJS and SharePoint
AngularJS and SharePointAngularJS and SharePoint
AngularJS and SharePoint
 
Building a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBuilding a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profit
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
TYPO3 Extension development using new Extbase framework
TYPO3 Extension development using new Extbase frameworkTYPO3 Extension development using new Extbase framework
TYPO3 Extension development using new Extbase framework
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatterns
 
Internationalization and Localization for Translators
Internationalization and Localization for TranslatorsInternationalization and Localization for Translators
Internationalization and Localization for Translators
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Kogito: cloud native business automation
Kogito: cloud native business automationKogito: cloud native business automation
Kogito: cloud native business automation
 
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
 
Writing Multilingual Plugins and Themes - WCMIA 2016
Writing Multilingual Plugins and Themes - WCMIA 2016Writing Multilingual Plugins and Themes - WCMIA 2016
Writing Multilingual Plugins and Themes - WCMIA 2016
 

More from soon

Deploying
DeployingDeploying
Deploying
soon
 
Google
GoogleGoogle
Google
soon
 
Authentication
AuthenticationAuthentication
Authentication
soon
 
Admin
AdminAdmin
Admin
soon
 
Templates
TemplatesTemplates
Templates
soon
 
Files
FilesFiles
Files
soon
 

More from soon (6)

Deploying
DeployingDeploying
Deploying
 
Google
GoogleGoogle
Google
 
Authentication
AuthenticationAuthentication
Authentication
 
Admin
AdminAdmin
Admin
 
Templates
TemplatesTemplates
Templates
 
Files
FilesFiles
Files
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

I18n

  • 1. i18n & L10n Thierry Sans
  • 2. Internationalization (i18n) ” Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. “ Wikipedia ➡ Make an application language agnostic
  • 3. Localization (L10n) ” Localization is the process of adapting internationalized software for a specific region or language by adding locale- specific components and translating text. “ Wikipedia ➡ Adapting an application for a specific language (aka locale)
  • 4. It is is not only about language translation • Number format • Date/Time • Sort orders • Units and conversion • Currency • Paper size
  • 5. How does it work
  • 7.
  • 12. What are the difference locales? http://www.i18nguy.com/unicode/language-identifiers.html
  • 13. Step 1 - Configure Django
  • 14. settings.py # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html LANGUAGE_CODE = 'en-us' # If you set this to False, Django will make some optimizations so as # not to load the internationalization machinery. USE_I18N = True # If you set this to False, Django will not format dates, numbers and # calendars according to the current locale USE_L10N = True
  • 15. Detects your locale from the HTTP request settings.py MIDDLEWARE_CLASSES = ( 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', )
  • 16. settings.py INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'WebDirectory', 'HelloLocale', # Uncomment the next line to enable the admin: 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', )
  • 17. Step 2 - Marking
  • 18. Mark translation messages from a template HelloLocale/templates/HelloLocale/index.html {% load i18n %} <html> <head> <title>{% trans "Hello World!" %}</title> ... </head> <body> <form action='sayhello/' method='post'> {% csrf_token %} <label>{% trans "Your name" %}</label> <input type="text" name="name"/> </form> <input type="button" value="{% trans "send" %}" onclick=" ... <body> </html>
  • 19. Mark translation messages from views.py HelloLocale/views.py from django.utils.translation import ugettext as _ def sayHello(request): name = request.POST['name'] output = _('Hello %(name)s!') % {'name' : name} return HttpResponse(strip_tags(output))
  • 20. Step 3 - Creating a locale
  • 21. Create a locale • Create a locale directory in the app • $ cd HelloLocale The locale identifier $ mkdir Locale $ django-admin.py makemessages -l fr ➡ Generates a .po file
  • 22. Define the translations HelloLocale/locale/fr/LC_MESSAGES/Django.po #: views.py:20 #, python-format msgid "Hello %(name)s!" msgstr "Bonjour %(name)s!" #: templates/HelloLocale/index.html:4 msgid "Hello World!" msgstr "Bonjour tout le monde!" #: templates/HelloLocale/index.html:11 msgid "Your name" msgstr "Votre nom" #: templates/HelloLocale/index.html:13 msgid "send" msgstr "envoyer"
  • 23. Compile locales $ django-admin.py compilemessages ➡ Creates a .mo file
  • 24. Update locales $ django-admin.py makemessages -a $ django-admin.py compilemessages
  • 26. Custom locale from django.utils.translation import ugettext as _ def sayHello(request): language = 'en-us' translation.activate(language) request.LANGUAGE_CODE = translation.get_language() name = request.POST['name'] output = _('Hello %(name)s!') % {'name' : name} return HttpResponse(strip_tags(output))
  • 27. Idea • The language preference is stored in the user’s profile • When the user is authenticated, store the language in a cookie or a session

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n