The code for the slug translation feature is located in the WPML String Translation plugin inc/slug-translation.php


1.How urls are being decoded

In the rewrite rules array from WordPress, we expect that the rules that are relevant to the custom post for which we want to use the slug translation use the slug in the strings language.
If we have a site in which English is the default language and French is the translated language and a url like this:

http://example.com/livre/french-livre

In this example the slug is 'book' and the translated slug is 'livre'.

The function WPML_Slug_Translation::rewrite_rules_filter filters the rewrite rules and replaces all ocurrences of 'book' with 'livre'. This way the url will resolve to the correct post type.

2. How permalinks are generated

On a translated page, a url of a post in the same language is being generated thanks to:
filter::filters_gettext_with_context

This is responsible for changing slug used in the custom post registration (e.g. _x('book', 'Url slug', 'some-theme')) into the translated value (in this case 'livre').
Beside this it's the normal WordPress process for generating a url.

A special case is the one of displaying a url of a post in a different language than the current language.
In this case the function WPML_Slug_Translation::post_type_link_filter handles the filtering of the rewrite logic in WordPress.

It temporarily replaces the post type slug from the version in the current language into the translation in the language of the post for which we need to get the url.