Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinnie Hellmann <winnie@gitlab.com>2017-12-11 15:25:49 +0300
committerWinnie Hellmann <winnie@gitlab.com>2017-12-18 13:13:41 +0300
commit4f73e14f2c30c907d4ead31dd8034aea37f14544 (patch)
treeceac6268f2a8942fdd30fbea372ce85b1205d32b /app/assets/javascripts/locale
parent2bad3b0eaf855a8050e565a05deebdf323ca4fd2 (diff)
Add createDateTimeFormat to format dates based on locale
Diffstat (limited to 'app/assets/javascripts/locale')
-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;