You want to include locale-specific files in your pages.
Modify include_path once you’ve determined the appropriate locale, as shown in Example 19-5.
Example 19-5. Modifying include_path for localization
1 2 3 4 5 |
$base = '/usr/local/php-include'; $locale = 'en_US'; $include_path = ini_get('include_path'); ini_set('include_path',"$base/$locale:$base/global:$include_path"); |
In Example 19-5, the $base variable holds the name of the base directory for your included localized files.
Files that are not locale-specific go in the global subdirectory of $base, and locale-specific files go in a subdirectory named after their locale (e.g.,en_US).
Prepending the locale-specific directory and then the global directory to the include path makes them the first two places PHP looks when you include a file.
Putting the locale-specific directory first ensures that nonlocalized information is loaded only if localized information isn’t available.
Here, however, you can take advantage of PHP’s include_path feature to have the directory searching happen automatically.
For maximum utility, reset include_path as early as possible in your code, preferably at the top of a file loaded via auto_prepend_file on every request.