Skip to content

Instantly share code, notes, and snippets.

@stefanoortisi
Created November 21, 2013 13:00
Show Gist options
  • Save stefanoortisi/7581165 to your computer and use it in GitHub Desktop.
Save stefanoortisi/7581165 to your computer and use it in GitHub Desktop.
localise_routes: ( ) ->
# Deep clone the default routes
old_routes = _.cloneDeep @Routes.routes
# Create a brand new routes object
@Routes.routes = {}
# Copy the utility routes
@Routes.routes[ "/pages" ] = old_routes[ "/pages" ]
# Create new routes with localised keys
for key, item of old_routes
if key isnt "/pages"
if key is "/"
_key = "homepage"
else
# Remove the /
_key = key.replace(/(\/\?\(:.+\)\?$)/g, "").substring 1
# # Get the localised url from the xml
value = @dictionary.get( "item#" + _key + " url", "urls.xml" )
value = key.replace "/" + _key, value
# # Create the item with the localised value
@Routes.routes[ value ] = item
# # Delete the old reference
item = null
if key is "/notfound"
@Routes.notfound = value
# Delete the old routes reference
old_routes = null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment