How can i use Hindu–Arabic numeral system for numbers in my website, so that numbers look like this (١٢٣) instead of this (123).
mostly for dates, readingTime and wordCount, i type arabic numbers manualy when i am writing an article.
website: nakibrayan2.pages.dev
repo: nakibrayan2/website
Number i18n should be a Go issue. Not sure if Hugo can be used to change that.
layouts/partials/digits-english-to-arabic.html
{{ $t := "" }}
{{ $m := dict "0" "٠" "1" "١" "2" "٢" "3" "٣" "4" "٤" "5" "٥" "6" "٦" "7" "٧" "8" "٨" "9" "٩" }}
{{ range split (string .) "" }}
{{ $t = add $t (index $m .) }}
{{ end }}
{{ return $t }}
layouts/_default/single.html
{{ partial "digits-english-to-arabic.html" .WordCount }}
You can feed it an integer or a string representation of an integer. Returns a string.
this works, but only if you give the partial a number. it returns an error when i give it a date like this:
{{ partial "digits-english-to-arabic.html" (.Date | time.Format ":date_long") }}
can you make it ignore non number characters?
where can i report a bug?
There is nothing to report. This is not a bug.
Yes, that’s why I wrote, “You can feed it an integer or a string representation of an integer.”
Sure, just fallback to the original character if it isn’t found in the map:
{{ $t := "" }}
{{ $m := dict "0" "٠" "1" "١" "2" "٢" "3" "٣" "4" "٤" "5" "٥" "6" "٦" "7" "٧" "8" "٨" "9" "٩" }}
{{ range split (string .) "" }}
{{ $t = add $t (or (index $m .) .) }}
{{ end }}
{{ return $t }}
1 Like
system
Closed
8
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.