> For the complete documentation index, see [llms.txt](https://developers.weglot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.weglot.com/craft-cms/architecture.md).

# Architecture

This page explains what happens under the hood when a visitor requests a translated URL. You don't need to know any of this to use the plugin — it is here for developers who want to understand or debug its behavior.

### Language-prefixed URLs

Weglot serves each destination language under a path prefix, for example `/fr/about` for the French version of `/about`. These prefixed URLs are **virtual**: the plugin registers URL rules that map them to its own router, and no extra entries are created in Craft. The router resolves the request against your original Craft route, then the response is translated on the way out.

### The translation pipeline

```mermaid
flowchart TD
    A[Visitor requests /fr/about] --> B[URL rule maps it to Weglot router]
    B --> C[Router resolves the original Craft route]
    C --> D[Craft renders the page in the original language]
    D --> E{Content type?}
    E -->|HTML| F[Send HTML to the Weglot API for translation]
    E -->|JSON / XML| G[Translate supported fields]
    F --> H[Rewrite internal links to add the language prefix]
    G --> H
    H --> I[Inject hreflang tags, switcher and scripts]
    I --> J[Return the translated page]
```

### Post-processing

After the Weglot API returns the translated HTML, the plugin:

* rewrites internal links (`<a>`, forms, canonical, `next`/`prev`, and similar) so they keep the current language prefix;
* injects the `hreflang` alternate tags in the `<head>` for SEO;
* injects the language switcher and Weglot's front-end script;
* maps translated URL slugs both ways, so a translated slug resolves back to the right Craft entry.

### Caching

The plugin caches the data it fetches from Weglot (your project options, available languages, slug maps) using Craft's cache, under keys prefixed with `weglot_`. This avoids calling the Weglot API on every request. If configuration changes don't appear, clearing the Craft cache forces a refresh — see **Troubleshooting**.
