Retrieve localizations through an api

When you have a need to use available localizations from e.g. a headless app, one way to do it is through a custom api. In this gist you can find a basic api controller that you could use.

It uses the LocalizationService to retrieve all localizations grouped by culture, localizations with a specific key grouped by culture or localizations with a specific key for a specific culture. The result is returned as json.

Calling “/api/translation/episerver.shell.ui” would give the following result (abbreviated)

{
"en": {
		"EPiServer.shell.ui.resources.componentselection.addgadgetstitle": "Add Gadgets",
		"EPiServer.shell.ui.resources.componentselection.dialogtitle": "Gadgets",
		"EPiServer.shell.ui.resources.componentselection.rearrangegadgets": "Rearrange Gadgets",
		"EPiServer.shell.ui.resources.componentselection.selectdateinterval": "Select Date Interval",
		"EPiServer.shell.ui.resources.contextservice.errors.couldnotloadcontext.description": "Unable to connect to the web server. What would you like to do?"
		
	}
}

The code is pretty straight forward, so have a look and maybe it will come in handy one day

Leave a comment