Skip to content

Commit ad71bdf

Browse files
committed
Miscellaneous multilingual edits
1 parent 016adc8 commit ad71bdf

File tree

2 files changed

+13
-101
lines changed

2 files changed

+13
-101
lines changed

content/en/content-management/multilingual.md

Lines changed: 12 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,16 @@ Example:
162162

163163
{{< code-toggle file=hugo >}}
164164
[languages]
165-
[languages.fr]
166-
baseURL = "https://example.fr"
167-
languageName = "Français"
168-
weight = 1
169-
title = "En Français"
170-
171-
[languages.en]
172-
baseURL = "https://example.org/"
173-
languageName = "English"
174-
weight = 2
175-
title = "In English"
165+
[languages.en]
166+
baseURL = 'https://en.example.org/'
167+
languageName = 'English'
168+
title = 'In English'
169+
weight = 2
170+
[languages.fr]
171+
baseURL = 'https://fr.example.org'
172+
languageName = 'Français'
173+
title = 'En Français'
174+
weight = 1
176175
{{</ code-toggle >}}
177176

178177
With the above, the two sites will be generated into `public` with their own root:
@@ -334,96 +333,9 @@ The above also uses the [`i18n` function][i18func] described in the next section
334333

335334
## Translation of strings
336335

337-
Hugo uses [go-i18n] to support string translations. [See the project's source repository][go-i18n-source] to find tools that will help you manage your translation workflows.
338-
339-
Translations are collected from the `themes/<THEME>/i18n/` folder (built into the theme), as well as translations present in `i18n/` at the root of your project. In the `i18n`, the translations will be merged and take precedence over what is in the theme folder. Language files should be named according to [RFC 5646] with names such as `en-US.toml`, `fr.toml`, etc.
340-
341-
Artificial languages with private use subtags as defined in [RFC 5646 &#167; 2.2.7](https://datatracker.ietf.org/doc/html/rfc5646#section-2.2.7) are also supported. You may omit the `art-x-` prefix for brevity. For example:
342-
343-
```text
344-
art-x-hugolang
345-
hugolang
346-
```
347-
348-
Private use subtags must not exceed 8 alphanumeric characters.
349-
350-
### Query basic translation
351-
352-
From within your templates, use the [`i18n`] function like this:
353-
354-
[`i18n`]: /functions/lang/translate/
336+
See the [`lang.Translate`] template function.
355337

356-
```go-html-template
357-
{{ i18n "home" }}
358-
```
359-
360-
The function will search for the `"home"` id:
361-
362-
{{< code-toggle file=i18n/en-US >}}
363-
[home]
364-
other = "Home"
365-
{{< /code-toggle >}}
366-
367-
The result will be
368-
369-
```text
370-
Home
371-
```
372-
373-
### Query a flexible translation with variables
374-
375-
Often you will want to use the page variables in the translation strings. To do so, pass the `.` context when calling `i18n`:
376-
377-
```go-html-template
378-
{{ i18n "wordCount" . }}
379-
```
380-
381-
The function will pass the `.` context to the `"wordCount"` id:
382-
383-
{{< code-toggle file=i18n/en-US >}}
384-
[wordCount]
385-
other = "This article has {{ .WordCount }} words."
386-
{{< /code-toggle >}}
387-
388-
Assume `.WordCount` in the context has value is 101. The result will be:
389-
390-
```text
391-
This article has 101 words.
392-
```
393-
394-
### Query a singular/plural translation
395-
396-
To enable pluralization when translating, pass a map with a numeric `.Count` property to the `i18n` function. The example below uses `.ReadingTime` variable which has a built-in `.Count` property.
397-
398-
```go-html-template
399-
{{ i18n "readingTime" .ReadingTime }}
400-
```
401-
402-
The function will read `.Count` from `.ReadingTime` and evaluate whether the number is singular (`one`) or plural (`other`). After that, it will pass to `readingTime` id in `i18n/en-US.toml` file:
403-
404-
{{< code-toggle file=i18n/en-US >}}
405-
[readingTime]
406-
one = "One minute to read"
407-
other = "{{ .Count }} minutes to read"
408-
{{< /code-toggle >}}
409-
410-
Assuming `.ReadingTime.Count` in the context has value is 525600. The result will be:
411-
412-
```text
413-
525600 minutes to read
414-
```
415-
416-
If `.ReadingTime.Count` in the context has value is 1. The result is:
417-
418-
```text
419-
One minute to read
420-
```
421-
422-
In case you need to pass a custom data: (`(dict "Count" numeric_value_only)` is minimum requirement)
423-
424-
```go-html-template
425-
{{ i18n "readingTime" (dict "Count" 25 "FirstArgument" true "SecondArgument" false "Etc" "so on, so far") }}
426-
```
338+
[`lang.Translate`]: /functions/lang/translate
427339

428340
## Localization
429341

content/en/functions/hugo/IsMultihost.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The `hugo.IsMultihost` function reports whether each configured language has a u
2222
title = 'In English'
2323
weight = 2
2424
[languages.fr]
25-
baseURL = 'https://fr.example.fr'
25+
baseURL = 'https://fr.example.org'
2626
languageName = 'Français'
2727
title = 'En Français'
2828
weight = 1

0 commit comments

Comments
 (0)