Multi-language PHP: internationalisation for PHP developers
4.8 (13 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
180 students enrolled

Multi-language PHP: internationalisation for PHP developers

Learn how to easily adapt your PHP website or web application to offer multiple languages to its visitors
Bestseller
4.8 (13 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
180 students enrolled
Created by Dave Hollingworth
Last updated 5/2020
English
English [Auto]
Current price: $48.99 Original price: $69.99 Discount: 30% off
5 hours left at this price!
30-Day Money-Back Guarantee
This course includes
  • 3 hours on-demand video
  • 56 downloadable resources
  • 1 coding exercise
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
Training 5 or more people?

Get your team access to 4,000+ top Udemy courses anytime, anywhere.

Try Udemy for Business
What you'll learn
  • Display your site's content in more than one language
  • Use gettext with PHP
  • Translate simple strings
  • Translate plurals, numbers and dates
  • Detect the visitor's preferred language
  • Translate content in databases
  • Use industry standards and best practices for localised content
  • Get support directly from the instructor
Course content
Expand all 58 lectures 02:44:40
+ Introduction: software installation, configuration and setup
5 lectures 07:52

In this lecture you'll get an overview of what you need to install to code along with the instructor, and you'll learn how to get the most out of the course.

Preview 01:38

In this lecture you'll learn how to install a web server, PHP, a database server like MySQL or MariaDB, and phpMyAdmin to administer it.

Install a web server with PHP, a database server and phpMyAdmin
01:16

In this lecture you'll learn how to configure a virtual host to host your content. This will allow you to develop your code in its own web root folder, and access it with its own address in the web browser.

Optional: configure a virtual host with its own root folder and hostname
03:10

In this lecture you'll learn how to install the Composer dependency manager, required for later on in the course.

Install the Composer dependency manager
00:52

In this lecture you'll learn what the internationalization extension is in PHP, and how to enable it.

Enable the PHP internationalization extension
00:56
+ An introduction to translating content using PHP
4 lectures 09:59

In this lecture we'll start by copying the entire page to show a translated version. You'll learn how this works, and why it's not a good way to translate content.

Preview 02:14

In this lecture you'll learn how to show translated content using conditional statements around each string.

Translate a page by using conditional statements for every string
01:57

In this lecture you'll learn how to store translations separately from the code where they're displayed, and why this is a good idea.

Store translated strings in an array with one array for each language
02:47

In this lecture you'll learn how to encode your source files so that characters from any language are displayed properly.

Display any character by encoding files using UTF-8
03:01
+ Getting the language from the URL
5 lectures 14:41

In this lecture you'll learn about international standards for language codes, and why we use them when passing the language in the URL.

Preview 01:17

In this lecture you'll learn how to get the language code from the query string.

Get the language code from the query string
01:15

In this lecture you'll learn how to get the language code from a subfolder or URL segment. You'll learn how to use .htaccess files to rewrite the URL so the subfolder is converted to the query string in the code.

Get the language code from a subfolder or URL segment
04:31

In this lecture you'll learn how to get the language code from a subdomain.

Get the language code from a subdomain
03:09

In this lecture you'll learn how to get the language code from the top-level domain.

Get the language code from the top-level domain
04:29
+ Locale identifiers and validating the language from the URL
6 lectures 17:22

In this lecture we'll start building an I18n class that we can use for various functionality throughout the rest of the course.

Add an I18n class with a list of supported languages
02:54

In this lecture you'll learn what locale codes are, and the international standards used to create them.

Preview 01:52

In this lecture you'll learn how to canonicalise the locale code so that we can accept any variation from the URL.

Canonicalise the locale code from the URL
02:36

In this lecture we'll match the incoming locale code from the URL to the ones that we support on the site, matching just the language code if necessary.

Get the best match from the list of supported locales
03:48

In this lecture you'll learn how to redirect to a default language if the one supplied is invalid or not present. Thus making it more user friendly by always showing content instead of an error message.

Redirect to the default locale if the value in the URL is invalid
04:18

In this lecture you'll learn why it's important to declare the language of the HTML document, and how to do it in a valid way.

Declare the language of the HTML document with the lang attribute
01:54
Specifying the language of the HTML document
1 question
+ Detecting the visitor's preferred language
7 lectures 23:29

In this lecture you'll learn how the browser has a list of preferred languages, and how to access these in PHP.

Preview 03:06

In this lecture we'll process the Accept-Language header from the browser to get a list of the visitor's preferred languages.

Parse the Accept-Language header to get a list of locales in order of preference
04:18

In this lecture we'll compare the locales we support to the list of preferred ones from the browser to get the best match.

Compare supported locales to the browser preferences and choose the best match
03:27

In this lecture we'll get the best match just taking the language codes into consideration.

Get the best match to the browser preferences using just the language codes
03:01

In this lecture we'll refactor the code we've written so far so it's clearer and easier to maintain.

Refactor the code to make it clearer
03:29

In this lecture you'll learn how we can match the visitor's IP address to a country code using geolocation, including the various options for doing so in PHP.

Geolocation: matching the user's IP address to their location
01:45

In this lecture we'll use the IPinfo geolocation API to match the visitor's IP address to the country, then use that to select the default language.

Use a geolocation API to get the country code from the IP address
04:23
+ Using gettext with PHP
5 lectures 16:27

In this lecture we'll look at the various formats available for storing translations, from PHP arrays, to XML and YAML. We'll also learn about PO and MO files, the format used by gettext.

The options for storing translations in separate files
01:37

In this lecture you'll learn how to use the gettext function in PHP to mark up code that needs to be translated.

Preview 03:12

In this lecture you'll create the specific folder structure that gettext requires.

Preview 02:18

In this lecture you'll install the Poedit editor and create the .po translation file getttext needs.

Install the Poedit editor and create a .po translation file
04:57

In this lecture you'll learn how to configure gettext in PHP with the necessary locale and location of the translation files.

Preview 04:23
+ Using MoTranslator as a gettext-compatible alternative
5 lectures 12:38

In this lecture we'll install MoTranslator, which overcomes gettext's limitations but is still compatible with po and mo files.

MoTranslator: a .mo-file-compatible alternative to gettext
01:35

In this lecture you'll learn how to use MoTranslator in gettext-mode.

Using MoTranslator with its gettext compatibility functions
02:18

In this lecture you'll learn how to configure Poedit to work with MoTranslator.

Configure Poedit to extract MoTranslator translations
02:42

In this lecture you'll learn how to use the simpler object API in MoTranslator.

Use the simpler MoTranslator object API
02:50

In this lecture you'll learn the advantages and disadvantages of using real or keyword messages in the translation file.

Using real or keyword messages: the advantages and disadvantages
03:13
+ Translating dynamic content: variable substitution, plurals, decimals and dates
4 lectures 17:24

In this lecture you'll learn how to translate a string containing an interpolated variable.

Including variables in translated strings: use sprintf with gettext
03:50

In this lecture you'll learn how to handle translating plural strings that depend on the value of a number.

Display plural forms of messages using ngettext
04:45

In this lecture you'll learn how to display decimal numbers using the decimal separator character based on the locale.

Decimal separators: format decimal numbers based on the locale
04:46

In this lecture you'll learn how to display dates based on the locale, with the month and day names translated.

Translate day and month names in dates based on the locale
04:03
+ Translating content unsuited to gettext: long text, databases and images
7 lectures 19:41

In this lecture you'll learn how to handle strings of text that are too long for gettext.

Handle long strings of text in separate files
02:50

In this lecture you'll learn how to display a message if the file containing the translation is unavailable.

Display a message if the file containing the translation is unavailable
02:36

In this lecture you'll learn why using a plain-text markup language is a good idea when using an external translator.

Use a plain-text formatting language to help translators
01:57

In this lecture we'll convert the HTML in our translation files to Markdown, and install a Markdown parser to convert them back to HTML.

Convert translations in separate files to Markdown
03:10

In this lecture you'll learn one method of translating text in a database, by adding additional columns to the same table.

Translate data from a database: multiple columns in one table
04:25

In this lecture you'll learn another method of translating text in a database, by adding an additional table with the translations.

Translate data from a database: separate table for the translations
03:02

In this lecture you'll learn how to display localised versions of images that contain text.

Display localised versions of images that contain text
01:41
+ Selecting and remembering the language
9 lectures 24:06

In this lecture you'll add navigation links to the HTML to switch between languages more easily.

Add navigation links for switching between languages
02:14

In this lecture you'll learn how best to create language navigation links - where to put them, what they should say, and why you shouldn't use flags.

Preview 03:35

In this lecture we'll remove some code duplication so we're not repeating ourselves when we add more pages.

Remove code duplication: extract common i18n code out to separate files
02:43

In this lecture we'll add a second page so we can see how language switching links work with multiple pages.

Add a second page and include the common i18n code
02:04

In this lecture you'll learn how to calculate the full URL of the current page based on the $_SERVER data, including the protocol, hostname, and port.

Calculate the full current URL from the $_SERVER data
02:06

In this lecture we'll generate the data needed for the language navigation links, based on the supported locales and the current URL.

Generate the data for the language navigation links
04:06

In this lecture we'll use the data from the previous lecture to add the language navigation links to the HTML.

Add the language navigation links to the HTML
01:41

In this lecture we'll remember the selected locale in a cookie, so that we can redirect back to that if the visitor returns to the site without a language code in the URL.

Preview 03:11

In this lecture we'll redirect back to the locale that we previously remembered in the cookie.

Preview 02:26
Requirements
  • You must know PHP, including the basics of object-oriented code
  • You need to know the basics of using Composer to install packages
  • Ideally have a web server with PHP and Composer installed, but a brief overview of installing these will be covered
Description

If you are a PHP developer and you want to display your site in more than one language, then you need to learn how to internationalise your code. Offering your content in several languages will enable you to reach a larger audience.

Learn how to Internationalise your PHP code in this Comprehensive Course.

  • Learn how to get the language from the URL

  • Use international standards for identifying languages

  • Build reusable code for handling multi-language sites

  • Learn how to use the industry standard gettext

  • Translate dynamic content including plurals and dates

  • Translate content in databases

  • Create a user-friendly interface for visitors

The essential skills required if you want to develop a multi-language website or web application in PHP.

Not everyone understands the same language. To reach a larger audience with your content, you need to display your content in more than one language. gettext has been the industry standard for translating content for many years. In addition to learning how to use gettext with PHP, we'll learn how to offer the best experience for the international visitor.

Content and Overview

This course is designed for the PHP developer who currently has some content developed in one language. Learning the techniques on this course will enable you to internationalise your site, so you can display its content in multiple languages.

  • Suitable for all PHP developers, you'll start by learning the basics of internationalization (i18n) in PHP.

  • You'll learn best practices for getting the language code from the URL, and how to use it in your code.

  • Throughout the course, we'll build code that you can reuse in all your projects.

  • You'll learn how to use gettext, and also an alternative that overcomes its limitations.

  • In addition to simple strings, you'll learn how to translate plurals, numbers, dates and long strings of text.

  • You'll learn how to handle content in a database, along with how to handle images that contain text.

  • All the time we'll adhere to industry standards and best practices.

When you complete the course you'll be able to internationalise your PHP code, allowing you to display your content in more than one language.

Complete with all the code shown in the lectures, you'll be able to work alongside the instructor and will receive a verifiable certificate of completion upon finishing the course.

Also, at all times throughout the course you have access to the instructor in the Q&A section to ask for help with any topic related to the course.

Enrol now and add internationalization to your PHP skillset!

Who this course is for:
  • PHP developers that want to make their site's content available in more than one language