talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 1 | import React from 'react'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 2 | import { storiesOf } from '@kadira/storybook'; |
| 3 | import { withKnobs } from '@kadira/storybook-addon-knobs'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 4 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 5 | import i18nJson from 'nfvo-utils/i18n/en.json'; |
| 6 | |
| 7 | const stories = storiesOf('i18n', module); |
| 8 | stories.addDecorator(withKnobs); |
| 9 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 10 | i18nJson['added'] = 'this is my test'; |
| 11 | i18nJson['added with {param}'] = 'this is my test with {param}'; |
| 12 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 13 | stories.add('i18n tests', () => { |
| 14 | let keys = [ |
| 15 | 'I do not exist', |
| 16 | 'Delete', |
| 17 | 'OrchestrationTemplateCandidate/File Structure' |
| 18 | ]; |
| 19 | let translations = []; |
| 20 | let i = 0; |
| 21 | translations.push(<div id={i++}>KEY: VALUE</div>); |
| 22 | keys.forEach(key => { |
| 23 | translations.push( |
| 24 | <div id={i++}> |
| 25 | {key} : {i18n(key)}{' '} |
| 26 | </div> |
| 27 | ); |
| 28 | }); |
| 29 | var param = 'param'; |
| 30 | translations.push(<div id={i++}>added : {i18n('added')} </div>); |
| 31 | translations.push( |
| 32 | <div id={i++}> |
| 33 | <font color="red"> |
| 34 | <b>WRONG</b> |
| 35 | </font>{' '} |
| 36 | - added with ${param} in translation : {i18n(`added with ${param}`)}{' '} |
| 37 | </div> |
| 38 | ); |
| 39 | translations.push( |
| 40 | <div id={i++}> |
| 41 | <font color="green"> |
| 42 | <b>RIGHT</b> |
| 43 | </font>{' '} |
| 44 | - added with ${param} and options object{' '} |
| 45 | {JSON.stringify({ param: param })}:{' '} |
| 46 | {i18n('added with {param}', { param: param })}{' '} |
| 47 | </div> |
| 48 | ); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 49 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 50 | return <div>{translations}</div>; |
| 51 | }); |