Programmatically change the Base URL? Is there any way to programmatically change the Base URL, Just as the "locale" module does..
My Website is multi-lingual which has to recognize 3rd argument, after the language identifier. Some custom code will be triggered when base on the third argument.

Have tried to Find a solution for this but the most of the Solutions suggest settings.php approach. 

I am looking for a hook that will allow me to alter the third parameter in the URL for custom functionality.

Sample URL: www.example.com/hi/arg3
Above "hi" is the language identifier and "arg3" will be used for custom functionality. Hence a node to be rendered will have url as  www.example.com/hi/arg3/node/1
You can do that with:

hook_url_outbound_alter

Keep in mind all URLs run through that function so your hook implementation should be as fast as possible.

Example from locale module:


  Rewrite outbound URLs with language based prefixes:locale_url_outbound_alter  


See also: Language Negotiation API