mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-13 17:55:16 -04:00
tpl/lang: Add new localized versions of lang.FormatNumber etc.
Fixes #8820
This commit is contained in:
parent
93f986ecc8
commit
198cdf8f04
@ -134,7 +134,7 @@ Or individually access EXIF data with dot access, e.g.:
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
```
|
```
|
||||||
|
|
||||||
Some fields may need to be formatted with [`lang.NumFmt`]({{< relref "functions/numfmt" >}}) function to prevent display like `Aperture: 2.278934289` instead of `Aperture: 2.28`.
|
Some fields may need to be formatted with [`lang.FormatNumberCustom`]({{< relref "functions/lang" >}}) function to prevent display like `Aperture: 2.278934289` instead of `Aperture: 2.28`.
|
||||||
|
|
||||||
#### Exif fields
|
#### Exif fields
|
||||||
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
---
|
---
|
||||||
title: lang.NumFmt
|
title: lang
|
||||||
description: "Formats a number with a given precision using the requested `negative`, `decimal`, and `grouping` options. The `options` parameter is a string consisting of `<negative> <decimal> <grouping>`."
|
package: lang
|
||||||
godocref: ""
|
description: "TODO.."
|
||||||
date: 2017-02-01
|
date: 2021-07-28
|
||||||
publishdate: 2017-02-01
|
|
||||||
lastmod: 2017-08-21
|
|
||||||
categories: [functions]
|
categories: [functions]
|
||||||
keywords: [numbers]
|
keywords: [numbers]
|
||||||
menu:
|
menu:
|
||||||
@ -12,18 +10,13 @@ menu:
|
|||||||
parent: "functions"
|
parent: "functions"
|
||||||
toc: false
|
toc: false
|
||||||
signature: ["lang.NumFmt PRECISION NUMBER [OPTIONS [DELIMITER]]"]
|
signature: ["lang.NumFmt PRECISION NUMBER [OPTIONS [DELIMITER]]"]
|
||||||
workson: []
|
aliases: ['/functions/numfmt/']
|
||||||
hugoversion:
|
type: 'template-func'
|
||||||
relatedfuncs: []
|
|
||||||
deprecated: false
|
|
||||||
draft: false
|
|
||||||
aliases: []
|
|
||||||
comments:
|
|
||||||
---
|
---
|
||||||
|
|
||||||
The default options value is `- . ,`. The default delimiter within the options
|
The default options value is `- . ,`. The default delimiter within the options
|
||||||
value is a space. If you need to use a space as one of the options, set a
|
value is a space. If you need to use a space as one of the options, set a
|
||||||
custom delimiter.
|
custom delimiter.s
|
||||||
|
|
||||||
Numbers greater than or equal to 5 are rounded up. For example, if precision is set to `0`, `1.5` becomes `2`, and `1.4` becomes `1`.
|
Numbers greater than or equal to 5 are rounded up. For example, if precision is set to `0`, `1.5` becomes `2`, and `1.4` becomes `1`.
|
||||||
|
|
@ -19,6 +19,7 @@ deprecated: false
|
|||||||
aliases: []
|
aliases: []
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
`time` converts a timestamp string with an optional default location into a [`time.Time`](https://godoc.org/time#Time) structure so you can access its fields:
|
`time` converts a timestamp string with an optional default location into a [`time.Time`](https://godoc.org/time#Time) structure so you can access its fields:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -1677,6 +1677,9 @@
|
|||||||
"caches": {
|
"caches": {
|
||||||
"_merge": "none"
|
"_merge": "none"
|
||||||
},
|
},
|
||||||
|
"cascade": {
|
||||||
|
"_merge": "none"
|
||||||
|
},
|
||||||
"frontmatter": {
|
"frontmatter": {
|
||||||
"_merge": "none"
|
"_merge": "none"
|
||||||
},
|
},
|
||||||
@ -1745,7 +1748,7 @@
|
|||||||
"keepDocumentTags": true,
|
"keepDocumentTags": true,
|
||||||
"keepEndTags": true,
|
"keepEndTags": true,
|
||||||
"keepQuotes": false,
|
"keepQuotes": false,
|
||||||
"keepWhitespace": false
|
"keepWhitespace": true
|
||||||
},
|
},
|
||||||
"css": {
|
"css": {
|
||||||
"keepCSS2": true,
|
"keepCSS2": true,
|
||||||
@ -1756,7 +1759,8 @@
|
|||||||
"keepVarNames": false
|
"keepVarNames": false
|
||||||
},
|
},
|
||||||
"json": {
|
"json": {
|
||||||
"precision": 0
|
"precision": 0,
|
||||||
|
"keepNumbers": false
|
||||||
},
|
},
|
||||||
"svg": {
|
"svg": {
|
||||||
"precision": 0
|
"precision": 0
|
||||||
@ -3898,14 +3902,52 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lang": {
|
"lang": {
|
||||||
"Merge": {
|
"FormatAccounting": {
|
||||||
"Description": "",
|
"Description": "FormatAccounting returns the currency reprecentation of number for the given currency and precision\nfor the current language in accounting notation.",
|
||||||
"Args": null,
|
"Args": [
|
||||||
|
"precision",
|
||||||
|
"currency",
|
||||||
|
"number"
|
||||||
|
],
|
||||||
"Aliases": null,
|
"Aliases": null,
|
||||||
"Examples": null
|
"Examples": [
|
||||||
|
[
|
||||||
|
"{{ 512.5032 | lang.FormatAccounting 2 \"NOK\" }}",
|
||||||
|
"NOK512.50"
|
||||||
|
]
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"NumFmt": {
|
"FormatCurrency": {
|
||||||
"Description": "NumFmt formats a number with the given precision using the\nnegative, decimal, and grouping options. The `options`\nparameter is a string consisting of `\u003cnegative\u003e \u003cdecimal\u003e \u003cgrouping\u003e`. The\ndefault `options` value is `- . ,`.\n\nNote that numbers are rounded up at 5 or greater.\nSo, with precision set to 0, 1.5 becomes `2`, and 1.4 becomes `1`.",
|
"Description": "FormatCurrency returns the currency reprecentation of number for the given currency and precision\nfor the current language.",
|
||||||
|
"Args": [
|
||||||
|
"precision",
|
||||||
|
"currency",
|
||||||
|
"number"
|
||||||
|
],
|
||||||
|
"Aliases": null,
|
||||||
|
"Examples": [
|
||||||
|
[
|
||||||
|
"{{ 512.5032 | lang.FormatCurrency 2 \"USD\" }}",
|
||||||
|
"$512.50"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"FormatNumber": {
|
||||||
|
"Description": "FormatNumber formats number with the given precision for the current language.",
|
||||||
|
"Args": [
|
||||||
|
"precision",
|
||||||
|
"number"
|
||||||
|
],
|
||||||
|
"Aliases": null,
|
||||||
|
"Examples": [
|
||||||
|
[
|
||||||
|
"{{ 512.5032 | lang.FormatNumber 2 }}",
|
||||||
|
"512.50"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"FormatNumberCustom": {
|
||||||
|
"Description": "FormatNumberCustom formats a number with the given precision using the\nnegative, decimal, and grouping options. The `options`\nparameter is a string consisting of `\u003cnegative\u003e \u003cdecimal\u003e \u003cgrouping\u003e`. The\ndefault `options` value is `- . ,`.\n\nNote that numbers are rounded up at 5 or greater.\nSo, with precision set to 0, 1.5 becomes `2`, and 1.4 becomes `1`.\n\nFor a simpler function that adapts to the current language, see FormatNumberCustom.",
|
||||||
"Args": [
|
"Args": [
|
||||||
"precision",
|
"precision",
|
||||||
"number",
|
"number",
|
||||||
@ -3914,19 +3956,19 @@
|
|||||||
"Aliases": null,
|
"Aliases": null,
|
||||||
"Examples": [
|
"Examples": [
|
||||||
[
|
[
|
||||||
"{{ lang.NumFmt 2 12345.6789 }}",
|
"{{ lang.FormatNumberCustom 2 12345.6789 }}",
|
||||||
"12,345.68"
|
"12,345.68"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"{{ lang.NumFmt 2 12345.6789 \"- , .\" }}",
|
"{{ lang.FormatNumberCustom 2 12345.6789 \"- , .\" }}",
|
||||||
"12.345,68"
|
"12.345,68"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"{{ lang.NumFmt 6 -12345.6789 \"- .\" }}",
|
"{{ lang.FormatNumberCustom 6 -12345.6789 \"- .\" }}",
|
||||||
"-12345.678900"
|
"-12345.678900"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"{{ lang.NumFmt 0 -12345.6789 \"- . ,\" }}",
|
"{{ lang.FormatNumberCustom 0 -12345.6789 \"- . ,\" }}",
|
||||||
"-12,346"
|
"-12,346"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@ -3935,6 +3977,32 @@
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"FormatPercent": {
|
||||||
|
"Description": "FormatPercent formats number with the given precision for the current language.\nNote that the number is assumbed to be percent.",
|
||||||
|
"Args": [
|
||||||
|
"precision",
|
||||||
|
"number"
|
||||||
|
],
|
||||||
|
"Aliases": null,
|
||||||
|
"Examples": [
|
||||||
|
[
|
||||||
|
"{{ 512.5032 | lang.FormatPercent 2 }}",
|
||||||
|
"512.50%"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Merge": {
|
||||||
|
"Description": "",
|
||||||
|
"Args": null,
|
||||||
|
"Aliases": null,
|
||||||
|
"Examples": null
|
||||||
|
},
|
||||||
|
"NumFmt": {
|
||||||
|
"Description": "",
|
||||||
|
"Args": null,
|
||||||
|
"Aliases": null,
|
||||||
|
"Examples": null
|
||||||
|
},
|
||||||
"Translate": {
|
"Translate": {
|
||||||
"Description": "Translate returns a translated string for id.",
|
"Description": "Translate returns a translated string for id.",
|
||||||
"Args": [
|
"Args": [
|
||||||
|
54
layouts/template-func/page.html
Normal file
54
layouts/template-func/page.html
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
{{ $pkg := .Params.package}}
|
||||||
|
{{ $funcs := index site.Data.docs.tpl.funcs $pkg }}
|
||||||
|
|
||||||
|
{{ range $k, $v := $funcs }}
|
||||||
|
{{ if $v.Description }}
|
||||||
|
{{ $func := printf "%s.%s" $pkg $k }}
|
||||||
|
<h2>
|
||||||
|
<a class="header-link" href="#{{ $func | anchorize | safeURL }}">
|
||||||
|
<svg class="fill-current o-60 hover-accent-color-light" height="22px" viewBox="0 0 24 24" width="22px" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M0 0h24v24H0z" fill="none"/>
|
||||||
|
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
{{ $func }}
|
||||||
|
</h2>
|
||||||
|
{{ with $v.Description }}
|
||||||
|
<p class="f4 lh-copy">
|
||||||
|
{{ . | $.RenderString | safeHTML }}
|
||||||
|
</p>
|
||||||
|
{{ end }}
|
||||||
|
<h4 class="minor mb3 pt2 primary-color-dark">
|
||||||
|
Syntax
|
||||||
|
</h4>
|
||||||
|
<div class="f5 mb4 ph3 pv2 bg-light-gray" style="border-left:4px solid #0594CB;">
|
||||||
|
{{ $pkg }}.{{ $k }}
|
||||||
|
{{ with $v.Args }}
|
||||||
|
<span class="ttu">
|
||||||
|
{{ delimit $v.Args ", "}}
|
||||||
|
</span>
|
||||||
|
{{ end }}
|
||||||
|
<span></span>
|
||||||
|
</div>
|
||||||
|
{{ if $v.Examples }}
|
||||||
|
<h4 class="minor mb3 pt2 primary-color-dark">
|
||||||
|
Examples
|
||||||
|
</h4>
|
||||||
|
{{ end }}
|
||||||
|
{{ range $v.Examples }}
|
||||||
|
{{ $input := index . 0 }}
|
||||||
|
{{ $result := index . 1 }}
|
||||||
|
{{ $example := printf "%s ---> %s" $input $result }}
|
||||||
|
|
||||||
|
{{ highlight $example "go-html-template" "" }}
|
||||||
|
{{ end }}
|
||||||
|
{{ with $v.Aliases }}
|
||||||
|
<h4 class="minor mb3 pt2 primary-color-dark">
|
||||||
|
Aliases
|
||||||
|
</h4>
|
||||||
|
<p>
|
||||||
|
{{ delimit . ", "}}
|
||||||
|
</p>
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
Loading…
x
Reference in New Issue
Block a user