mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
Merge commit '35dec7c96f7ee3eb17dd444f7067f0c776fb56ae'
This commit is contained in:
@@ -1,27 +1,21 @@
|
||||
---
|
||||
title: lang.FormatAccounting
|
||||
description: Returns a currency representation of a number for the given currency and precision for the current language in accounting notation.
|
||||
categories: [functions]
|
||||
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: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/lang/FormatCurrency
|
||||
- functions/lang/FormatNumber
|
||||
- functions/lang/FormatNumberCustom
|
||||
- functions/lang/FormatPercent
|
||||
returnType: string
|
||||
signatures: [lang.FormatAccounting PRECISION CURRENCY NUMBER]
|
||||
relatedFunctions:
|
||||
- lang.FormatAccounting
|
||||
- lang.FormatCurrency
|
||||
- lang.FormatNumber
|
||||
- lang.FormatNumberCustom
|
||||
- lang.FormatPercent
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
{{ 512.5032 | lang.FormatAccounting 2 "NOK" }} → NOK512.50
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
{{% readfile file="/functions/_common/locales.md" %}}
|
||||
{{% /note %}}
|
||||
{{% include "functions/_common/locales.md" %}}
|
||||
|
@@ -1,27 +1,21 @@
|
||||
---
|
||||
title: lang.FormatCurrency
|
||||
description: Returns a currency representation of a number for the given currency and precision for the current language.
|
||||
categories: [functions]
|
||||
description: Returns a currency representation of a number for the given currency and precision for the current language and region.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/lang/FormatAccounting
|
||||
- functions/lang/FormatNumber
|
||||
- functions/lang/FormatNumberCustom
|
||||
- functions/lang/FormatPercent
|
||||
returnType: string
|
||||
signatures: [lang.FormatAccounting PRECISION CURRENCY NUMBER]
|
||||
relatedFunctions:
|
||||
- lang.FormatAccounting
|
||||
- lang.FormatCurrency
|
||||
- lang.FormatNumber
|
||||
- lang.FormatNumberCustom
|
||||
- lang.FormatPercent
|
||||
signatures: [lang.FormatCurrency PRECISION CURRENCY NUMBER]
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
{{ 512.5032 | lang.FormatCurrency 2 "USD" }} → $512.50
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
{{% readfile file="/functions/_common/locales.md" %}}
|
||||
{{% /note %}}
|
||||
{{% include "functions/_common/locales.md" %}}
|
||||
|
@@ -1,27 +1,21 @@
|
||||
---
|
||||
title: lang.FormatNumber
|
||||
description: Returns a numeric representation of a number with the given precision for the current language.
|
||||
categories: [functions]
|
||||
description: Returns a numeric representation of a number with the given precision for the current language and region.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/lang/FormatAccounting
|
||||
- functions/lang/FormatCurrency
|
||||
- functions/lang/FormatNumberCustom
|
||||
- functions/lang/FormatPercent
|
||||
returnType: string
|
||||
signatures: [lang.FormatNumber PRECISION NUMBER]
|
||||
relatedFunctions:
|
||||
- lang.FormatAccounting
|
||||
- lang.FormatCurrency
|
||||
- lang.FormatNumber
|
||||
- lang.FormatNumberCustom
|
||||
- lang.FormatPercent
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
{{ 512.5032 | lang.FormatNumber 2 }} → 512.50
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
{{% readfile file="/functions/_common/locales.md" %}}
|
||||
{{% /note %}}
|
||||
{{% include "functions/_common/locales.md" %}}
|
||||
|
@@ -1,31 +1,26 @@
|
||||
---
|
||||
title: lang.FormatNumberCustom
|
||||
description: Returns a numeric representation of a number with the given precision using negative, decimal, and grouping options.
|
||||
categories: [functions]
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/lang/FormatAccounting
|
||||
- functions/lang/FormatCurrency
|
||||
- functions/lang/FormatNumber
|
||||
- functions/lang/FormatPercent
|
||||
returnType: string
|
||||
signatures: ['lang.FormatNumberCustom PRECISION NUMBER [OPTIONS...]']
|
||||
relatedFunctions:
|
||||
- lang.FormatAccounting
|
||||
- lang.FormatCurrency
|
||||
- lang.FormatNumber
|
||||
- lang.FormatNumberCustom
|
||||
- lang.FormatPercent
|
||||
aliases: ['/functions/numfmt/']
|
||||
---
|
||||
|
||||
This function formats a number with the given precision. The first options parameter is a space-delimited string of characters to represent negativity, the decimal point, and grouping. The default value is `- . ,`. The second options parameter defines an alternate delimiting character.
|
||||
|
||||
Note that numbers are rounded up at 5 or greater. So, with precision set to 0, 1.5 becomes 2, and 1.4 becomes 1.
|
||||
Note that numbers are rounded up at 5 or greater. So, with precision set to 0, 1.5 becomes 2, and 1.4 becomes 1.
|
||||
|
||||
For a simpler function that adapts to the current language, see [`lang.FormatNumber`].
|
||||
|
||||
|
||||
```go-html-template
|
||||
{{ lang.FormatNumberCustom 2 12345.6789 }} → 12,345.68
|
||||
{{ lang.FormatNumberCustom 2 12345.6789 "- , ." }} → 12.345,68
|
||||
@@ -34,8 +29,6 @@ For a simpler function that adapts to the current language, see [`lang.FormatNum
|
||||
{{ lang.FormatNumberCustom 0 -12345.6789 "-|.| " "|" }} → -12 346
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
{{% readfile file="/functions/_common/locales.md" %}}
|
||||
{{% /note %}}
|
||||
{{% include "functions/_common/locales.md" %}}
|
||||
|
||||
[`lang.FormatNumber`]: /functions/lang/formatnumber
|
||||
|
@@ -1,27 +1,21 @@
|
||||
---
|
||||
title: lang.FormatPercent
|
||||
description: Returns a percentage representation of a number with the given precision for the current language.
|
||||
categories: [functions]
|
||||
description: Returns a percentage representation of a number with the given precision for the current language and region.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
action:
|
||||
aliases: []
|
||||
related:
|
||||
- functions/lang/FormatAccounting
|
||||
- functions/lang/FormatCurrency
|
||||
- functions/lang/FormatNumber
|
||||
- functions/lang/FormatNumberCustom
|
||||
returnType: string
|
||||
signatures: [lang.FormatPercent PRECISION NUMBER]
|
||||
relatedFunctions:
|
||||
- lang.FormatAccounting
|
||||
- lang.FormatCurrency
|
||||
- lang.FormatNumber
|
||||
- lang.FormatNumberCustom
|
||||
- lang.FormatPercent
|
||||
---
|
||||
|
||||
```go-html-template
|
||||
{{ 512.5032 | lang.FormatPercent 2 }} → 512.50%
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
{{% readfile file="/functions/_common/locales.md" %}}
|
||||
{{% /note %}}
|
||||
{{% include "functions/_common/locales.md" %}}
|
||||
|
@@ -1,31 +1,27 @@
|
||||
---
|
||||
title: lang.Merge
|
||||
description: Merge missing translations from other languages.
|
||||
categories: [functions]
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
action:
|
||||
aliases: []
|
||||
related: []
|
||||
returnType: any
|
||||
signatures: [lang.Merge FROM TO]
|
||||
relatedFunctions: []
|
||||
aliases: [/functions/lang.merge]
|
||||
---
|
||||
|
||||
As an example:
|
||||
|
||||
```bash
|
||||
```sh
|
||||
{{ $pages := .Site.RegularPages | lang.Merge $frSite.RegularPages | lang.Merge $enSite.RegularPages }}
|
||||
```
|
||||
|
||||
Will "fill in the gaps" in the current site with, from left to right, content from the French site, and lastly the English.
|
||||
|
||||
|
||||
A more practical example is to fill in the missing translations from the other languages:
|
||||
|
||||
```bash
|
||||
```sh
|
||||
{{ $pages := .Site.RegularPages }}
|
||||
{{ range .Site.Home.Translations }}
|
||||
{{ $pages = $pages | lang.Merge .Site.RegularPages }}
|
||||
|
@@ -1,23 +1,19 @@
|
||||
---
|
||||
title: lang.Translate
|
||||
linkTitle: i18n
|
||||
description: Translates a string using the translation tables in the i18n directory.
|
||||
categories: [functions]
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
aliases: [i18n,T]
|
||||
action:
|
||||
aliases: [T, i18n]
|
||||
related: []
|
||||
returnType: string
|
||||
signatures: ['lang.Translate KEY [CONTEXT]']
|
||||
relatedFunctions: []
|
||||
aliases: [/functions/i18n]
|
||||
---
|
||||
|
||||
Let's say your multilingual site supports two languages, English and Polish. Create a translation table for each language in the `i18n` directory.
|
||||
|
||||
```
|
||||
```text
|
||||
i18n/
|
||||
├── en.toml
|
||||
└── pl.toml
|
||||
@@ -34,12 +30,10 @@ The Unicode [CLDR Plural Rules chart] describes the pluralization categories for
|
||||
|
||||
The English translation table:
|
||||
|
||||
{{< code-toggle file=i18n/en copy=false >}}
|
||||
# simple translations
|
||||
{{< code-toggle file=i18n/en >}}
|
||||
privacy = 'privacy'
|
||||
security = 'security'
|
||||
|
||||
# translations with pluralization
|
||||
[day]
|
||||
one = 'day'
|
||||
other = 'days'
|
||||
@@ -51,12 +45,10 @@ other = '{{ . }} days'
|
||||
|
||||
The Polish translation table:
|
||||
|
||||
{{< code-toggle file=i18n/pl copy=false >}}
|
||||
# simple translations
|
||||
{{< code-toggle file=i18n/pl >}}
|
||||
privacy = 'prywatność'
|
||||
security = 'bezpieczeństwo'
|
||||
|
||||
# translations with pluralization
|
||||
[day]
|
||||
one = 'miesiąc'
|
||||
few = 'miesiące'
|
||||
@@ -108,17 +100,17 @@ When viewing the Polish language site:
|
||||
{{ T "day_with_count" 5 }} → 5 miesięcy
|
||||
```
|
||||
|
||||
In the pluralization examples above, we passed an integer in context (the second argument). You can also pass a map in context, creating a `count` key to control pluralization.
|
||||
In the pluralization examples above, we passed an integer in context (the second argument). You can also pass a map in context, providing a `count` key to control pluralization.
|
||||
|
||||
Translation table:
|
||||
|
||||
{{< code-toggle file=i18n/en copy=false >}}
|
||||
{{< code-toggle file=i18n/en >}}
|
||||
[age]
|
||||
one = '{{ .name }} is {{ .count }} year old.'
|
||||
other = '{{ .name }} is {{ .count }} years old.'
|
||||
{{< /code-toggle >}}
|
||||
|
||||
Template:
|
||||
Template code:
|
||||
|
||||
```go-html-template
|
||||
{{ T "age" (dict "name" "Will" "count" 1) }} → Will is 1 year old.
|
||||
|
12
docs/content/en/functions/lang/_index.md
Normal file
12
docs/content/en/functions/lang/_index.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
title: Lang functions
|
||||
linkTitle: lang
|
||||
description: Template 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