diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-12-21 11:24:21 +0000 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-12-21 11:24:21 +0000 |
commit | e615565756e2a73de85fcf1e1c352d217c23d9fc (patch) | |
tree | cb527bc27d33c1d189cea6d7b99919a1c339e828 | |
parent | 058dd30af27c175b063cdc92c1612ccbdba19c10 (diff) | |
parent | 4a95302d3e54407b77b45584f7f927d22b775d86 (diff) | |
download | gitlab-ce-e615565756e2a73de85fcf1e1c352d217c23d9fc.tar.gz |
Merge branch 'winh-fix-datetime_utility' into 'master'
Restore missing language code in datetime_utility.js
Closes #41248
See merge request gitlab-org/gitlab-ce!16009
-rw-r--r-- | app/assets/javascripts/lib/utils/datetime_utility.js | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/app/assets/javascripts/lib/utils/datetime_utility.js b/app/assets/javascripts/lib/utils/datetime_utility.js index 198b5164c92..1fa6715180e 100644 --- a/app/assets/javascripts/lib/utils/datetime_utility.js +++ b/app/assets/javascripts/lib/utils/datetime_utility.js @@ -2,7 +2,7 @@ import timeago from 'timeago.js'; import dateFormat from 'vendor/date.format'; import { pluralize } from './text_utility'; import { - lang, + languageCode, s__, } from '../../locale'; @@ -24,7 +24,15 @@ export const getDayName = date => ['Sunday', 'Monday', 'Tuesday', 'Wednesday', ' */ export const formatDate = datetime => dateFormat(datetime, 'mmm d, yyyy h:MMtt Z'); +/** + * Timeago uses underscores instead of dashes to separate language from country code. + * + * see https://github.com/hustcc/timeago.js/tree/v3.0.0/locales + */ +const timeagoLanguageCode = languageCode().replace(/-/g, '_'); + let timeagoInstance; + /** * Sets a timeago Instance */ @@ -67,8 +75,8 @@ export function getTimeago() { ][index]; }; - timeago.register(lang, locale); - timeago.register(`${lang}-remaining`, localeRemaining); + timeago.register(timeagoLanguageCode, locale); + timeago.register(`${timeagoLanguageCode}-remaining`, localeRemaining); timeagoInstance = timeago(); } @@ -83,7 +91,7 @@ export const renderTimeago = ($els) => { const timeagoEls = $els || document.querySelectorAll('.js-timeago-render'); // timeago.js sets timeouts internally for each timeago value to be updated in real time - getTimeago().render(timeagoEls, lang); + getTimeago().render(timeagoEls, timeagoLanguageCode); }; /** @@ -118,7 +126,7 @@ export const timeFor = (time, expiredLabel) => { if (new Date(time) < new Date()) { return expiredLabel || s__('Timeago|Past due'); } - return getTimeago().format(time, `${lang}-remaining`).trim(); + return getTimeago().format(time, `${timeagoLanguageCode}-remaining`).trim(); }; export const getDayDifference = (a, b) => { |