summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/locale/index.js
diff options
context:
space:
mode:
authorπŸŒ΄πŸ‡ΏπŸ‡¦ Lukas Eipert (OOO until Summit) <leipert@gitlab.com>2018-08-16 19:03:57 +0000
committerMike Greiling <mike@pixelcog.com>2018-08-16 19:03:57 +0000
commit8f9442fcdf9d98ea28e6abd582aad1dc2086e1bd (patch)
tree347faa88ea898062b131e047a77130f44333704b /app/assets/javascripts/locale/index.js
parent76cd1dd68198bb464b12de7525ab067c6d4dc025 (diff)
downloadgitlab-ce-8f9442fcdf9d98ea28e6abd582aad1dc2086e1bd.tar.gz
Frontend: Proper gettext extraction with gettext-extractor
Diffstat (limited to 'app/assets/javascripts/locale/index.js')
-rw-r--r--app/assets/javascripts/locale/index.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/app/assets/javascripts/locale/index.js b/app/assets/javascripts/locale/index.js
index 2cc5fb10027..1ae3362c4bc 100644
--- a/app/assets/javascripts/locale/index.js
+++ b/app/assets/javascripts/locale/index.js
@@ -1,4 +1,5 @@
import Jed from 'jed';
+import ensureSingleLine from './ensure_single_line';
import sprintf from './sprintf';
const languageCode = () => document.querySelector('html').getAttribute('lang') || 'en';
@@ -10,7 +11,7 @@ delete window.translations;
@param text The text to be translated
@returns {String} The translated text
*/
-const gettext = locale.gettext.bind(locale);
+const gettext = text => locale.gettext.bind(locale)(ensureSingleLine(text));
/**
Translate the text with a number
@@ -23,7 +24,10 @@ const gettext = locale.gettext.bind(locale);
@returns {String} Translated text with the number replaced (eg. '2 days')
*/
const ngettext = (text, pluralText, count) => {
- const translated = locale.ngettext(text, pluralText, count).replace(/%d/g, count).split('|');
+ const translated = locale
+ .ngettext(ensureSingleLine(text), ensureSingleLine(pluralText), count)
+ .replace(/%d/g, count)
+ .split('|');
return translated[translated.length - 1];
};
@@ -40,7 +44,7 @@ const ngettext = (text, pluralText, count) => {
@returns {String} Translated context based text
*/
const pgettext = (keyOrContext, key) => {
- const normalizedKey = key ? `${keyOrContext}|${key}` : keyOrContext;
+ const normalizedKey = ensureSingleLine(key ? `${keyOrContext}|${key}` : keyOrContext);
const translated = gettext(normalizedKey).split('|');
return translated[translated.length - 1];
@@ -52,8 +56,7 @@ const pgettext = (keyOrContext, key) => {
@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);
+const createDateTimeFormat = formatOptions => Intl.DateTimeFormat(languageCode(), formatOptions);
export { languageCode };
export { gettext as __ };