You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
334
333
335
334
## Translation of strings
336
335
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 § 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.
355
337
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") }}
0 commit comments