mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -3,19 +3,15 @@ title: lang.FormatAccounting
|
||||
description: Returns a currency representation of a number for the given currency and precision for the current language and region in accounting notation.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/lang/FormatCurrency
|
||||
- functions/lang/FormatNumber
|
||||
- functions/lang/FormatNumberCustom
|
||||
- functions/lang/FormatPercent
|
||||
returnType: string
|
||||
signatures: [lang.FormatAccounting PRECISION CURRENCY NUMBER]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: string
|
||||
signatures: [lang.FormatAccounting PRECISION CURRENCY NUMBER]
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
{{ 512.5032 | lang.FormatAccounting 2 "NOK" }} → NOK512.50
|
||||
```
|
||||
|
||||
{{% include "functions/_common/locales.md" %}}
|
||||
{{% include "/_common/functions/locales.md" %}}
|
||||
|
@@ -3,19 +3,15 @@ title: lang.FormatCurrency
|
||||
description: Returns a currency representation of a number for the given currency and precision for the current language and region.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/lang/FormatAccounting
|
||||
- functions/lang/FormatNumber
|
||||
- functions/lang/FormatNumberCustom
|
||||
- functions/lang/FormatPercent
|
||||
returnType: string
|
||||
signatures: [lang.FormatCurrency PRECISION CURRENCY NUMBER]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: string
|
||||
signatures: [lang.FormatCurrency PRECISION CURRENCY NUMBER]
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
{{ 512.5032 | lang.FormatCurrency 2 "USD" }} → $512.50
|
||||
```
|
||||
|
||||
{{% include "functions/_common/locales.md" %}}
|
||||
{{% include "/_common/functions/locales.md" %}}
|
||||
|
@@ -3,19 +3,15 @@ title: lang.FormatNumber
|
||||
description: Returns a numeric representation of a number with the given precision for the current language and region.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/lang/FormatAccounting
|
||||
- functions/lang/FormatCurrency
|
||||
- functions/lang/FormatNumberCustom
|
||||
- functions/lang/FormatPercent
|
||||
returnType: string
|
||||
signatures: [lang.FormatNumber PRECISION NUMBER]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: string
|
||||
signatures: [lang.FormatNumber PRECISION NUMBER]
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
{{ 512.5032 | lang.FormatNumber 2 }} → 512.50
|
||||
```
|
||||
|
||||
{{% include "functions/_common/locales.md" %}}
|
||||
{{% include "/_common/functions/locales.md" %}}
|
||||
|
@@ -3,15 +3,11 @@ title: lang.FormatNumberCustom
|
||||
description: Returns a numeric representation of a number with the given precision using negative, decimal, and grouping options.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/lang/FormatAccounting
|
||||
- functions/lang/FormatCurrency
|
||||
- functions/lang/FormatNumber
|
||||
- functions/lang/FormatPercent
|
||||
returnType: string
|
||||
signatures: ['lang.FormatNumberCustom PRECISION NUMBER [OPTIONS...]']
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: string
|
||||
signatures: ['lang.FormatNumberCustom PRECISION NUMBER [OPTIONS...]']
|
||||
aliases: ['/functions/numfmt/']
|
||||
---
|
||||
|
||||
@@ -29,6 +25,6 @@ For a simpler function that adapts to the current language, see [`lang.FormatNum
|
||||
{{ lang.FormatNumberCustom 0 -12345.6789 "-|.| " "|" }} → -12 346
|
||||
```
|
||||
|
||||
{{% include "functions/_common/locales.md" %}}
|
||||
{{% include "/_common/functions/locales.md" %}}
|
||||
|
||||
[`lang.FormatNumber`]: /functions/lang/formatnumber/
|
||||
|
@@ -3,19 +3,15 @@ title: lang.FormatPercent
|
||||
description: Returns a percentage representation of a number with the given precision for the current language and region.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/lang/FormatAccounting
|
||||
- functions/lang/FormatCurrency
|
||||
- functions/lang/FormatNumber
|
||||
- functions/lang/FormatNumberCustom
|
||||
returnType: string
|
||||
signatures: [lang.FormatPercent PRECISION NUMBER]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: string
|
||||
signatures: [lang.FormatPercent PRECISION NUMBER]
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
{{ 512.5032 | lang.FormatPercent 2 }} → 512.50%
|
||||
```
|
||||
|
||||
{{% include "functions/_common/locales.md" %}}
|
||||
{{% include "/_common/functions/locales.md" %}}
|
||||
|
@@ -3,11 +3,11 @@ title: lang.Merge
|
||||
description: Merge missing translations from other languages.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: []
|
||||
related: []
|
||||
returnType: any
|
||||
signatures: [lang.Merge FROM TO]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: []
|
||||
returnType: any
|
||||
signatures: [lang.Merge FROM TO]
|
||||
aliases: [/functions/lang.merge]
|
||||
---
|
||||
|
||||
|
@@ -3,31 +3,24 @@ title: lang.Translate
|
||||
description: Translates a string using the translation tables in the i18n directory.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [T, i18n]
|
||||
related: []
|
||||
returnType: string
|
||||
signatures: ['lang.Translate KEY [CONTEXT]']
|
||||
toc: true
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [T, i18n]
|
||||
returnType: string
|
||||
signatures: ['lang.Translate KEY [CONTEXT]']
|
||||
aliases: [/functions/i18n]
|
||||
---
|
||||
|
||||
The `lang.Translate` function returns the value associated with given key as defined in the translation table for the current language.
|
||||
The `lang.Translate` function returns the value associated with given key as defined in the translation table for the current language.
|
||||
|
||||
If the key is not found in the translation table for the current language, the `lang.Translate` function falls back to the translation table for the [`defaultContentLanguage`].
|
||||
|
||||
[`defaultContentLanguage`]: /getting-started/configuration/#defaultcontentlanguage
|
||||
|
||||
If the key is not found in the translation table for the `defaultContentLanguage`, the `lang.Translate` function returns an empty string.
|
||||
|
||||
{{% note %}}
|
||||
To list missing and fallback translations, use the `--printI18nWarnings` flag when building your site.
|
||||
|
||||
To render placeholders for missing and fallback translations, set
|
||||
[`enableMissingTranslationPlaceholders`] to `true` in your site configuration.
|
||||
|
||||
[`enableMissingTranslationPlaceholders`]: /getting-started/configuration/#enablemissingtranslationplaceholders
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> To list missing and fallback translations, use the `--printI18nWarnings` flag when building your site.
|
||||
>
|
||||
> To render placeholders for missing and fallback translations, set [`enableMissingTranslationPlaceholders`] to `true` in your site configuration.
|
||||
|
||||
## Translation tables
|
||||
|
||||
@@ -38,7 +31,7 @@ i18n/en.toml
|
||||
i18n/en-US.toml
|
||||
```
|
||||
|
||||
The base name must match the language key as defined in your site configuration.
|
||||
The base name must match the [language key] as defined in your site configuration.
|
||||
|
||||
Artificial languages with private use subtags as defined in [RFC 5646 § 2.2.7] are also supported. You may omit the `art-x-` prefix for brevity. For example:
|
||||
|
||||
@@ -47,10 +40,8 @@ i18n/art-x-hugolang.toml
|
||||
i18n/hugolang.toml
|
||||
```
|
||||
|
||||
Private use subtags must not exceed 8 alphanumeric characters.
|
||||
|
||||
[RFC 5646]: https://datatracker.ietf.org/doc/html/rfc5646
|
||||
[RFC 5646 § 2.2.7]: https://datatracker.ietf.org/doc/html/rfc5646#section-2.2.7
|
||||
> [!note]
|
||||
> Private use subtags must not exceed 8 alphanumeric characters.
|
||||
|
||||
## Simple translations
|
||||
|
||||
@@ -76,9 +67,8 @@ privacy = 'prywatność'
|
||||
security = 'bezpieczeństwo'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
{{% note %}}
|
||||
The examples below use the `T` alias for brevity.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> The examples below use the `T` alias for brevity.
|
||||
|
||||
When viewing the English language site:
|
||||
|
||||
@@ -106,8 +96,6 @@ i18n/
|
||||
|
||||
The Unicode [CLDR Plural Rules chart] describes the pluralization categories for each language.
|
||||
|
||||
[CLDR Plural Rules chart]: https://www.unicode.org/cldr/charts/43/supplemental/language_plural_rules.html
|
||||
|
||||
The English translation table:
|
||||
|
||||
{{< code-toggle file=i18n/en >}}
|
||||
@@ -136,9 +124,8 @@ many = '{{ . }} miesięcy'
|
||||
other = '{{ . }} miesiąca'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
{{% note %}}
|
||||
The examples below use the `T` alias for brevity.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> The examples below use the `T` alias for brevity.
|
||||
|
||||
When viewing the English language site:
|
||||
|
||||
@@ -185,16 +172,13 @@ Template code:
|
||||
{{ T "age" (dict "name" "John" "count" 3) }} → John is 3 years old.
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
Translation tables may contain both simple translations and translations with pluralization.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Translation tables may contain both simple translations and translations with pluralization.
|
||||
|
||||
## Reserved keys
|
||||
|
||||
Hugo uses the [go-i18n] package to look up values in translation tables. This package reserves the following keys for internal use:
|
||||
|
||||
[go-i18n]: https://github.com/nicksnyder/go-i18n
|
||||
|
||||
id
|
||||
: (`string`) Uniquely identifies the message.
|
||||
|
||||
@@ -228,8 +212,6 @@ many
|
||||
other
|
||||
: (`string`) The content of the message for the [CLDR] plural form "other".
|
||||
|
||||
[CLDR]: https://www.unicode.org/cldr/charts/43/supplemental/language_plural_rules.html
|
||||
|
||||
If you need to provide a translation for one of the reserved keys, you can prepend the word with an underscore. For example:
|
||||
|
||||
{{< code-toggle file=i18n/es >}}
|
||||
@@ -253,3 +235,12 @@ Then in your templates:
|
||||
{{ T "_zero" }} → cero
|
||||
{{ T "_other" }} → otro
|
||||
```
|
||||
|
||||
[`defaultContentLanguage`]: /configuration/all/#defaultcontentlanguage
|
||||
[`enableMissingTranslationPlaceholders`]: /configuration/all/#enablemissingtranslationplaceholders
|
||||
[CLDR]: https://www.unicode.org/cldr/charts/43/supplemental/language_plural_rules.html
|
||||
[CLDR Plural Rules chart]: https://www.unicode.org/cldr/charts/43/supplemental/language_plural_rules.html
|
||||
[go-i18n]: https://github.com/nicksnyder/go-i18n
|
||||
[language key]: /configuration/languages/#language-keys
|
||||
[RFC 5646]: https://datatracker.ietf.org/doc/html/rfc5646
|
||||
[RFC 5646 § 2.2.7]: https://datatracker.ietf.org/doc/html/rfc5646#section-2.2.7
|
||||
|
@@ -1,12 +1,7 @@
|
||||
---
|
||||
title: Lang functions
|
||||
linkTitle: lang
|
||||
description: Template functions to adapt your site to meet language and regional requirements.
|
||||
description: Use these functions to adapt your site to meet language and regional requirements.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these functions to adapt your site to meet language and regional requirements.
|
||||
|
Reference in New Issue
Block a user