Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Alain Schlesser:
Structuring PHP Exceptions
Oct 31, 2016 @ 10:46:25

Alain Schlesser has written up a new post for his site sharing some of his suggestions for structuring your PHP exceptions including localization, catching them and using them with named constructors.

I seem to constantly work on improving my habits regarding the use of exceptions. I think it is an area that I haven’t yet fully explored, and it is very difficult to find anything more than very basic explanations and tutorials online. While the consensus is to use exceptions, there is very little information on how to structure and manage them in a larger codebase. The larger and more complex your projects become, the more important it is to start with a proper structure to avoid expensive refactoring later on. Your client will surely be thankful!

In this article, I want to talk about the way I currently set them up and use them in PHP, in the hopes to spark some discussion on the topic and get further feedback.

He starts with a few thoughts about why even using exceptions is a good idea (over just errors) and how to build on the included SPL exception set. He then gets into the suggestions about:

  • naming conventions
  • using named constructors to encapsulate logic
  • working with localized exception messages
  • catching exceptions

He ends the post by suggesting one last piece that can help make catching and handling exceptions easier - a centralized handler, something potentially like BooBoo from The PHP League.

tagged: exception handling tutorial naming namedconstructors localization catching

Link: https://www.alainschlesser.com/structuring-php-exceptions/

TutsPlus.com:
Internationalizing WordPress Projects: Updates With WordPress 4.6
Oct 13, 2016 @ 12:07:47

TutsPlus.com has posted the latest in their "Internationalizing WordPress" series today, focusing on some of the changes that have come with the release of WordPress 4.6.

Throughout this series, we've covered exactly what you need to do to internationalize your WordPress projects. If you've not read any of the previous posts, I recommend checking them out.

Though there have been some changes to how internationalization and localization work in WordPress 4.6, that doesn't mean the previous tutorials are irrelevant. It just means that the way you opt to distribute your plugins and their localizations will change.

And that's what we're going to be covering in this tutorial.

You'll need to be caught up on the series before following along with this article. It defines some of the basics and gets your WordPress install in a certain state. Then they get into the changes with the WordPress update including a brief overview of how the internationalization and localization functionality now works and the idea of "just-in-time" translations.

tagged: wordpress update internnationalization localization version

Link: https://code.tutsplus.com/tutorials/internationalizing-wordpress-projects-updates-with-wordpress-46--cms-27155

SitePoint PHP Blog:
Localizing Dates, Currency, and Numbers with Php-Intl
May 23, 2016 @ 12:52:32

On the SitePoint PHP blog Younes Rafie has continued his series about the PHP "Intl" extension for use in internationalizing an application. in this second part of the series he moves away from just strings and looks at using it for currencies and numbers.

The first part of this series was an introduction of the PHP Intl extension and of how to localize your application’s messages. In this part, we’re going to learn about localizing numbers, dates, calendars, and similar complex data.

The post is broken down into a few different sections, each with their own examples:

  • Localizing Decimals
  • Localizing Currencies
  • Timezones
  • Calendars

The "Intl" extension makes these operations relatively simple with plenty of built-in objects and methods to help with the translations between the formats. You can find out more about this extension in the PHP manual.

tagged: date currency localization number tutorial intl extension series part2

Link: https://www.sitepoint.com/localizing-dates-currency-and-numbers-with-php-intl/

SitePoint PHP Blog:
Localization Demystified: Php-Intl for Everyone
May 17, 2016 @ 09:44:39

The SitePoint PHP blog has posted a tutorial from Younes Rafie that wants to help demystify internationalization functionality in your PHP application...with the help from a handy extension, the intl extension.

Most applications perform locale aware operations like working with texts, dates, timezones, etc. The PHP Intl extension provides a good API for accessing the widely known ICU library’s functions.

He walks you through the installation of the extension if you don't have it already for both PHP 5 and PHP 7 (the second requires adding a custom apt-get repository). With that all installed and configured he starts in on the code to output a simple message with formatting using the MessageFormat functionality. His first example is in English but he also shows the difference between that and Arabic and Bengali and they're related output. He looks at a few other topics including pluralization, "choices" (different messages for different values) and more complex cases. He ends the post briefly looking at message parsing - extracting a value according to the provided format.

tagged: localization internationalization i18n messageformat intl extension tutorial

Link: https://www.sitepoint.com/localization-demystified-understanding-php-intl/

Simon Holywell:
PHP date localisation with setlocale
Jul 21, 2015 @ 12:57:07

Simon Holywell as written up a tutorial for his site showing you how to use setlocale to do PHP date localization.

Localising sites can be a chore, but PHP has the venerable setlocale() to use system locales. These are like templates or profiles that describe how various types of data should be displayed. Should a price have a comma or point to indicate the decimals? When printing a date should PHP output Monday or Montag?

All of these considerations are locale specific and they map to a geographical area. Various cultures have their own standards for displaying this kind of information not to mention different languages to accommodate.

He shows how to find the locales your system supports and how to install them if the one(s) you need are missing. With it correctly installed, the system knows how to use it but PHP needs a little extra help. With a call to the setlocale method and the use of a special date string modifier (in this case "%B" for the month name) PHP knows to use the locale-aware version of the data...but only with strftime not the normal PHP date handling.

tagged: simonholywell setlocale locale localization strftime

Link: https://www.simonholywell.com/post/2015/07/php-date-setlocale-localisation/

NetTuts.com:
Building Your Startup With PHP: Localization With I18n
Mar 09, 2015 @ 10:43:08

In the latest part of their series of "building a startup" application in PHP, NetTuts.com looks at supporting internationalization with the functionality of the Yii framework.

This is part four of the Building Your Startup With PHP series on Tuts+. In this series, I'm guiding you through launching a startup from concept to reality using my Meeting Planner app as a real life example. Every step along the way, we'll release the Meeting Planner code as open source examples you can learn from. We'll also address startup-related business issues as they arise. In this tutorial, I wanted to step back and add I18n internationalization support to our application before we build more and more code.

They start off with a look at some of the overall goals of internationalization (i18n) and about how it works in the Yii system. It uses placeholders with a key/value system to replace the data based on which language is selected. They show you how to configure Yii's support including default language, sorting of the data and files to exclude when looking for i18n configurations. With this configuration in place they show how to use the command line tool to extract these messages out into separate folders for easier management and faster reference. Finally they show how to select a language and use the Yii code generator together with the translations to create models and forms.

tagged: build startup series part4 internationalization i18n localization language yii framework

Link: http://code.tutsplus.com/tutorials/building-your-startup-with-php-localization-with-i18n--cms-23102

Sebastian Bergmann's Blog:
Test Dependencies in PHPUnit 3.4
Nov 14, 2008 @ 10:25:20

Sebastian Bergmann talks about a new bit of functionality he's put into the 3.4 release of PHPUnit (the popular unit testing tool for PHP) based on a suggestion from a paper he'd read:

Back in July, I came across an academic paper (more academic papers on testing that I read recently) titled "JExample: Exploiting Dependencies Between Tests to Improve Defect Localization". [...] For the upcoming PHPUnit 3.4 I have implemented support for the idea expressed in the paper mentioned above.

The feature is a system that helps localize problems at the source, stripping away all of the cascading issues it might have tripped off, causing other tests to fail. This new feature (as illustrated by his code example using a DependencyFailureTest class) makes it simple to fail a test immediately whenever the scripts needs to via a fail() method. Check out the full post for the rest of the code and some further explanation on how it works.

tagged: phpunit test dependencies fail cascade source defect localization

Link:

Zend Developer Zone:
L10N==Localization (See there are ten letters...Oh, you get it...OK)
Jun 09, 2006 @ 06:57:37

Internationalization and Localization are concepts that all web sites and applications will have to deal with at some point. Why not design it form the start? Most people just don’t think about it but in an increasingly global society, you need to. The earlier you design for it, the easier it is to do.

They continue on in this post on the Zend Developer Zone with a resource to get you thinking - an Internationalization Primer from Johnathan Snook (as printed in Digital Web Magazine). He looks at the basics you'll need to know when putting in multi-language support, including database designs and precompiling.

tagged: localization article digital web magazine primer localization article digital web magazine primer

Link:

Zend Developer Zone:
L10N==Localization (See there are ten letters...Oh, you get it...OK)
Jun 09, 2006 @ 06:57:37

Internationalization and Localization are concepts that all web sites and applications will have to deal with at some point. Why not design it form the start? Most people just don’t think about it but in an increasingly global society, you need to. The earlier you design for it, the easier it is to do.

They continue on in this post on the Zend Developer Zone with a resource to get you thinking - an Internationalization Primer from Johnathan Snook (as printed in Digital Web Magazine). He looks at the basics you'll need to know when putting in multi-language support, including database designs and precompiling.

tagged: localization article digital web magazine primer localization article digital web magazine primer

Link:

Zend Developer Zone:
The Speed of Going Local
Apr 13, 2006 @ 06:55:10

The Zend Developer Zone has a quick post today covering localization and points to another article with more information.

Localization is becoming more and more important for web designers and developers. It’s coming to a web site near you soon and you need to know how to do it and do it fast. And it isn’t only about swapping strings that you understand with ones you don’t, it is about doing it quickly and smoothly to give your site a global image.

The article, a piece by Pablo Hoch, does some benchmarking of the gettext functionality in PHP. He pits the pure PHP gettext function he wrote against an array containing string translations and the gettext extension. Not surprisingly, the extension beat both of them out, topping the array of strings by just a bit.

tagged: localization extension benchmark array pure-php localization extension benchmark array pure-php

Link: