19.7.1. ProblemYou want to display images that have text in them and have that text in a locale-appropriate language. 19.7.2. SolutionMake an image directory for each locale you want to support, as well as a global image directory for images that have no locale-specific information in them. Create copies of each locale-specific image in the appropriate locale-specific directory. Make sure that the images have the same filename in the different directories. Instead of printing out image URLs directly, use a wrapper function similar to the msg( ) function in 19.4 that prints out locale-specific text. 19.7.3. DiscussionThe img( ) wrapper function in Example 19-18 looks for a locale-specific version of an image first, then a global one. If neither are present, it prints a message to the error log. Finding locale-specific images
The img( ) function needs to know both the path to the image file in the filesystem ($image_base_path) and the path to the image from the base URL of your site (/images). It uses the first to test if the file can be read and the second to construct an appropriate URL for the image. A localized image must have the same filename in each localization directory. For example, an image that says "New!" on a yellow starburst should be called new.gif in both the images/en_US directory and the images/es_US directory, even though the file images/es_US/new.gif is a picture of a yellow starburst with "¡Nuevo!" on it. Don't forget that the alt text you display in your image tags also needs to be localized. Example 19-19 prints a complete localized <img/> element. A localized <img> element
If the localized versions of a particular image have varied dimensions, store image height and width in the message catalog as well. Example 19-20 prints a localized <img/> element with height and width attributes. A localized <img/> element with height and width
The localized messages for img-cancel-height and img-cancel-width are not text strings, but integers that describe the dimensions of the cancel.png image in each locale. 19.7.4. See Also19.4 discusses locale-specific message catalogs. |