Inspect the DXA Localization object

Sometimes you just want to look under the hood and see what DXA is doing. Here is a tool to inspect the Localization object for DXA .NET. This also gives insight in all the published resources and configuration parameters. I use this when I have to use such a resource or configuration property in webapp code. 
 
DXA keeps the information about the publication it is serving pages from in the Localization object. The information published through the _System\Publish Settings page is available though this Localization object. The language selector also uses the Localization object to find the other publications to link to.
 
Adding the following little tool to your project will add a controller in /admin/sitelocalization which lists the Localization object's properties, the other site localizations, the resources and configuration parameters.
 
  • AdminController.cs; An action method you can add to your admin controller.
  • LocalizationExtensions.cs; An extension to the Localization object to fetch all configuration parameters.
  • SiteLocalization.cs; A view to add to the views in the shared views.
 
The controller will take the Localization from the WebRequestContext and make sure all localizations in the SiteLocalizations are properly loaded. The view will display everything in a convenient way. That's it.
 
The LocalizationExtension helps to find all the configuration parameters. The Localization class only has a public method GetConfigValue(string key) to get one specific configuration parameter, and there is no method to explore all configuration parameters. The LocalizationExtension's GetConfiigValues() will read the configuration from the DXA published configuration from the configuration binary variants, just like DXA's private methods do.
 
There is no need to add a route. The admin routes (admin/{action} and {localization}/admin/{action}) are already mapping the sitelocalization action. Just like the out-of-the-box admin/refresh controller you probably do not want to expose this feature publicly on your live website.