| 1 |
--- |
| 2 |
title: LanguagePrefix |
| 3 |
description: Returns the URL language prefix, if any, for the given site. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: string |
| 9 |
signatures: [SITE.LanguagePrefix] |
| 10 |
--- |
| 11 |
|
| 12 |
Consider this project configuration: |
| 13 |
|
| 14 |
{{< code-toggle file=hugo >}} |
| 15 |
defaultContentLanguage = 'de' |
| 16 |
defaultContentLanguageInSubdir = false |
| 17 |
|
| 18 |
[languages.de] |
| 19 |
direction = 'ltr' |
| 20 |
label = 'Deutsch' |
| 21 |
locale = 'de-DE' |
| 22 |
title = 'Projekt Dokumentation' |
| 23 |
weight = 1 |
| 24 |
|
| 25 |
[languages.en] |
| 26 |
direction = 'ltr' |
| 27 |
label = 'English' |
| 28 |
locale = 'en-US' |
| 29 |
title = 'Project Documentation' |
| 30 |
weight = 2 |
| 31 |
{{< /code-toggle >}} |
| 32 |
|
| 33 |
When visiting the German language site: |
| 34 |
|
| 35 |
```go-html-template |
| 36 |
{{ .Site.LanguagePrefix }} → "" |
| 37 |
``` |
| 38 |
|
| 39 |
When visiting the English language site: |
| 40 |
|
| 41 |
```go-html-template |
| 42 |
{{ .Site.LanguagePrefix }} → /en |
| 43 |
``` |
| 44 |
|
| 45 |
If you change `defaultContentLanguageInSubdir` to `true`, when visiting the German language site: |
| 46 |
|
| 47 |
```go-html-template |
| 48 |
{{ .Site.LanguagePrefix }} → /de |
| 49 |
``` |
| 50 |
|
| 51 |
You may use the `LanguagePrefix` method with both monolingual and multilingual projects. |