summaryrefslogtreecommitdiff
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorWinnie Hellmann <winnie@gitlab.com>2017-12-11 13:25:49 +0100
committerWinnie Hellmann <winnie@gitlab.com>2017-12-18 11:13:41 +0100
commit4f73e14f2c30c907d4ead31dd8034aea37f14544 (patch)
treeceac6268f2a8942fdd30fbea372ce85b1205d32b /app/assets/javascripts
parent2bad3b0eaf855a8050e565a05deebdf323ca4fd2 (diff)
downloadgitlab-ce-4f73e14f2c30c907d4ead31dd8034aea37f14544.tar.gz
Add createDateTimeFormat to format dates based on locale
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/locale/index.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/app/assets/javascripts/locale/index.js b/app/assets/javascripts/locale/index.js
index 1003b9ba0af..2f4328b56e1 100644
--- a/app/assets/javascripts/locale/index.js
+++ b/app/assets/javascripts/locale/index.js
@@ -1,8 +1,7 @@
import Jed from 'jed';
import sprintf from './sprintf';
-const langAttribute = document.querySelector('html').getAttribute('lang');
-const lang = (langAttribute || 'en').replace(/-/g, '_');
+const languageCode = () => document.querySelector('html').getAttribute('lang') || 'en';
const locale = new Jed(window.translations || {});
delete window.translations;
@@ -47,9 +46,19 @@ const pgettext = (keyOrContext, key) => {
return translated[translated.length - 1];
};
-export { lang };
+/**
+ Creates an instance of Intl.DateTimeFormat for the current locale.
+
+ @param formatOptions for available options, please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
+ @returns {Intl.DateTimeFormat}
+*/
+const createDateTimeFormat =
+ formatOptions => Intl.DateTimeFormat(languageCode(), formatOptions);
+
+export { languageCode };
export { gettext as __ };
export { ngettext as n__ };
export { pgettext as s__ };
export { sprintf };
+export { createDateTimeFormat };
export default locale;