From 7fdf733a64670fceefc3ded35cfa581e1c458179 Mon Sep 17 00:00:00 2001 From: Einav Weiss Keidar Date: Tue, 20 Mar 2018 14:45:40 +0200 Subject: Adding Prettier and fixing up eslint version Issue-ID: SDC-1094 Change-Id: Ie83ad95a03899345dd90235daf0323cbe3bc6afd Signed-off-by: Einav Weiss Keidar --- openecomp-ui/src/nfvo-utils/i18n/i18n.js | 132 ++++++++++++----------- openecomp-ui/src/nfvo-utils/i18n/i18n.stories.js | 64 ++++++----- 2 files changed, 109 insertions(+), 87 deletions(-) (limited to 'openecomp-ui/src/nfvo-utils/i18n') diff --git a/openecomp-ui/src/nfvo-utils/i18n/i18n.js b/openecomp-ui/src/nfvo-utils/i18n/i18n.js index ef97b8bab4..43a183def4 100644 --- a/openecomp-ui/src/nfvo-utils/i18n/i18n.js +++ b/openecomp-ui/src/nfvo-utils/i18n/i18n.js @@ -22,88 +22,94 @@ import i18nJson from 'i18nJson'; Intl libs are using out dated transpailer from ecmascript6. * TODO: As soon as they fix it, remove this assignments!!! * */ -var Intl = window.Intl || IntlObj.default, - IntlMessageFormat = IntlMessageFormatObj.default, - IntlRelativeFormat = IntlRelativeFormatObj.default, - createFormatCache = createFormatCacheObj.default; +var Intl = window.Intl || IntlObj.default, + IntlMessageFormat = IntlMessageFormatObj.default, + IntlRelativeFormat = IntlRelativeFormatObj.default, + createFormatCache = createFormatCacheObj.default; /*extract locale*/ var _locale = window.localStorage && localStorage.getItem('user_locale'); -if(!_locale) { - if(window.navigator) { - _locale = navigator.language || navigator.userLanguage; +if (!_locale) { + if (window.navigator) { + _locale = navigator.language || navigator.userLanguage; - //For now removing the dashes from the language. - let indexOfDash = _locale.indexOf('-'); - if(-1 !== indexOfDash) { - _locale = _locale.substr(0, indexOfDash); - } - } - if(!_locale) { - _locale = 'en'; - } + //For now removing the dashes from the language. + let indexOfDash = _locale.indexOf('-'); + if (-1 !== indexOfDash) { + _locale = _locale.substr(0, indexOfDash); + } + } + if (!_locale) { + _locale = 'en'; + } } var _localeUpper = _locale.toUpperCase(); var i18n = { + _locale: _locale, + _localeUpper: _localeUpper, + _i18nData: i18nJson || {}, - _locale: _locale, - _localeUpper: _localeUpper, - _i18nData: i18nJson || {}, + number(num) { + return createFormatCache(Intl.NumberFormat)(this._locale).format(num); + }, - number(num) { - return createFormatCache(Intl.NumberFormat)(this._locale).format(num); - }, + date(date, options, relativeDates) { + if (undefined === relativeDates || relativeDates) { + return this.dateRelative(date, options); + } else { + return this.dateNormal(date, options); + } + }, - date(date, options, relativeDates) { - if (undefined === relativeDates || relativeDates) { - return this.dateRelative(date, options); - } else { - return this.dateNormal(date, options); - } - }, - - dateNormal(date, options) { - return createFormatCache(Intl.DateTimeFormat)(this._locale, options).format(date); - }, - - dateRelative(date, options) { - return createFormatCache(IntlRelativeFormat)(this._locale, options).format(date); - }, - message(messageId, options) { - let messageTxt = null; - if (i18nJson && i18nJson[messageId]) { - messageTxt = i18nJson[messageId]; - } else { - messageTxt = String(messageId); - } - return createFormatCache(IntlMessageFormat)(messageTxt, this._locale).format(options); - - }, - getLocale() { - return this._locale; - }, - getLocaleUpper() { - return this._localeUpper; - }, - setLocale(locale) { - localStorage.setItem('user_locale', locale); - window.location.reload(); - } + dateNormal(date, options) { + return createFormatCache(Intl.DateTimeFormat)( + this._locale, + options + ).format(date); + }, + dateRelative(date, options) { + return createFormatCache(IntlRelativeFormat)( + this._locale, + options + ).format(date); + }, + message(messageId, options) { + let messageTxt = null; + if (i18nJson && i18nJson[messageId]) { + messageTxt = i18nJson[messageId]; + } else { + messageTxt = String(messageId); + } + return createFormatCache(IntlMessageFormat)( + messageTxt, + this._locale + ).format(options); + }, + getLocale() { + return this._locale; + }, + getLocaleUpper() { + return this._localeUpper; + }, + setLocale(locale) { + localStorage.setItem('user_locale', locale); + window.location.reload(); + } }; function i18nWrapper() { - return i18nWrapper.message.apply(i18nWrapper, arguments); + return i18nWrapper.message.apply(i18nWrapper, arguments); } /*replace with some kind of extend method*/ var prop, propKey; for (propKey in i18n) { - prop = i18n[propKey]; - if (typeof prop === 'function') { - prop = prop.bind(i18nWrapper); - } - i18nWrapper[propKey] = prop; + prop = i18n[propKey]; + if (typeof prop === 'function') { + prop = prop.bind(i18nWrapper); + } + i18nWrapper[propKey] = prop; } export default i18nWrapper; diff --git a/openecomp-ui/src/nfvo-utils/i18n/i18n.stories.js b/openecomp-ui/src/nfvo-utils/i18n/i18n.stories.js index 816915b1c9..79f95057a0 100644 --- a/openecomp-ui/src/nfvo-utils/i18n/i18n.stories.js +++ b/openecomp-ui/src/nfvo-utils/i18n/i18n.stories.js @@ -1,35 +1,51 @@ import React from 'react'; -import {storiesOf, action} from '@kadira/storybook'; -import {text, number} from '@kadira/storybook-addon-knobs'; -import {withKnobs} from '@kadira/storybook-addon-knobs'; +import { storiesOf } from '@kadira/storybook'; +import { withKnobs } from '@kadira/storybook-addon-knobs'; import i18n from 'nfvo-utils/i18n/i18n.js'; import i18nJson from 'nfvo-utils/i18n/en.json'; const stories = storiesOf('i18n', module); stories.addDecorator(withKnobs); - i18nJson['added'] = 'this is my test'; i18nJson['added with {param}'] = 'this is my test with {param}'; -stories - .add('i18n tests', () => { - let keys = [ - 'I do not exist', - 'Delete', - 'OrchestrationTemplateCandidate/File Structure' - ]; - let translations = []; - let i=0; - translations.push(
KEY: VALUE
) - keys.forEach((key) => { - translations.push((
{key} : {i18n(key)}
)); - }); - var param = 'param'; - translations.push((
added : {i18n('added')}
)); - translations.push((
WRONG - added with ${param} in translation : {i18n(`added with ${param}`)}
)); - translations.push((
RIGHT - added with ${param} and options object {JSON.stringify({param:param})}: {i18n('added with {param}', {param: param})}
)); +stories.add('i18n tests', () => { + let keys = [ + 'I do not exist', + 'Delete', + 'OrchestrationTemplateCandidate/File Structure' + ]; + let translations = []; + let i = 0; + translations.push(
KEY: VALUE
); + keys.forEach(key => { + translations.push( +
+ {key} : {i18n(key)}{' '} +
+ ); + }); + var param = 'param'; + translations.push(
added : {i18n('added')}
); + translations.push( +
+ + WRONG + {' '} + - added with ${param} in translation : {i18n(`added with ${param}`)}{' '} +
+ ); + translations.push( +
+ + RIGHT + {' '} + - added with ${param} and options object{' '} + {JSON.stringify({ param: param })}:{' '} + {i18n('added with {param}', { param: param })}{' '} +
+ ); - return (
{translations}
); - }) -; + return
{translations}
; +}); -- cgit 1.2.3-korg