summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMarcia Ramos <marcia@gitlab.com>2019-01-29 09:23:04 +0000
committerMarcia Ramos <marcia@gitlab.com>2019-01-29 09:23:04 +0000
commit257d5a80558eaaa34b078a06adb10e3fa475594a (patch)
tree992bd7f65d339949c8161a69ef0b1b6361a70fc4 /doc
parent8b25e00f47b534735585f72d848a2829aef0ba94 (diff)
parenta00810e3607c7b178d590e47a985c59a2401c99d (diff)
downloadgitlab-ce-257d5a80558eaaa34b078a06adb10e3fa475594a.tar.gz
Merge branch 'docs-localized-dates-in-ruby' into 'master'
Document how to format localized dates in Ruby Closes #41237 See merge request gitlab-org/gitlab-ce!24585
Diffstat (limited to 'doc')
-rw-r--r--doc/development/i18n/externalization.md10
1 files changed, 10 insertions, 0 deletions
diff --git a/doc/development/i18n/externalization.md b/doc/development/i18n/externalization.md
index 6323275426f..00db58a45a2 100644
--- a/doc/development/i18n/externalization.md
+++ b/doc/development/i18n/externalization.md
@@ -228,6 +228,16 @@ This makes use of [`Intl.DateTimeFormat`].
[`Intl.DateTimeFormat`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
+- In Ruby/HAML, we have two ways of adding format to dates and times:
+
+ 1. **Through the `l` helper**, i.e. `l(active_session.created_at, format: :short)`. We have some predefined formats for
+[dates](https://gitlab.com/gitlab-org/gitlab-ce/blob/v11.7.0/config/locales/en.yml#L54) and [times](https://gitlab.com/gitlab-org/gitlab-ce/blob/v11.7.0/config/locales/en.yml#L261).
+ If you need to add a new format, because other parts of the code could benefit from it,
+ you'll need to add it to [en.yml](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/config/locales/en.yml) file.
+ 2. **Through `strftime`**, i.e. `milestone.start_date.strftime('%b %-d')`. We use `strftime` in case none of the formats
+ defined on [en.yml](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/config/locales/en.yml) matches the date/time
+ specifications we need, and if there is no need to add it as a new format because is very particular (i.e. it's only used in a single view).
+
## Best practices
### Splitting sentences