In what ways can custom Smarty functions be used to streamline the process of language localization in PHP web development?

Language localization in PHP web development can be streamlined using custom Smarty functions to easily translate text within templates. By creating custom Smarty functions for translating strings, developers can centralize the translation logic and make it easier to manage language files. This approach helps to maintain clean and readable template files while also allowing for easy updates and modifications to translations.

// Custom Smarty function for language localization
function smarty_function_translate($params, $smarty) {
    // Load language file based on user's selected language
    $lang_file = 'lang/' . $params['lang'] . '.php';
    if (file_exists($lang_file)) {
        include($lang_file);
    } else {
        // Fallback to default language file
        include('lang/en.php');
    }
    
    // Translate the text using the loaded language array
    $translated_text = $lang[$params['text']] ?? $params['text'];
    
    return $translated_text;
}
```

To use this custom Smarty function in a template file, you can simply call it with the text to be translated and the language code as parameters:

```smarty
{* Example usage of custom translate function *}
{$lang = 'en'} {* Set the language code *}

{* Translate a string using the custom function *}
{translate text='Hello' lang=$lang}