88
99export default class LanguageModel {
1010 constructor ( options ) {
11+ this . enterKey = 'Enter' ,
12+ this . shiftKey = 'Shift' ,
1113 this . ok = 'OK'
1214 this . continue = 'Continue'
13- this . pressEnter = 'Press :key(Enter) ' ;
15+ this . pressEnter = 'Press :enterKey ' ;
1416 this . multipleChoiceHelpText = 'Choose as many as you like'
1517 this . otherPrompt = 'Other'
1618 this . placeholder = 'Type your answer here...'
1719 this . submitText = 'Submit'
18- this . longTextHelpText = ':key(Shift) + :key(Enter) to make a line break.'
20+ this . longTextHelpText = ':shiftKey + :enterKey to make a line break.'
1921 this . prev = 'Prev'
2022 this . next = 'Next'
2123 this . percentCompleted = ':percent% completed'
@@ -32,18 +34,19 @@ export default class LanguageModel {
3234
3335
3436 Object . assign ( this , options || { } )
35-
36- // Inserts a new CSS class into the language model string to format the :key
37- Object . keys ( this ) . forEach ( property => {
38- if ( ! this [ property ] ) return ''
39- let stringArr = this [ property ] . toString ( ) . split ( " " )
40- for ( let i = 0 ; i < stringArr . length ; i ++ ) {
41- if ( stringArr [ i ] . slice ( 0 , 4 ) === ":key" ) {
42- stringArr [ i ] = '<span class="f-language-key">' + stringArr [ i ] . substring ( 5 , stringArr [ i ] . length - 1 ) + '</span>'
43- }
44- }
45- this [ property ] = stringArr . join ( " " )
46- } ) ;
4737 }
38+ /**
39+ * Inserts a new CSS class into the language model string to format the :string
40+ * Use it in the component v-html directive: v-html="language.formatString(language.languageString)"
41+ */
42+ formatString ( string ) {
43+ return string . replace ( / : ( \w + ) / g, ( match , word ) => {
44+ if ( this [ word ] ) {
45+ return '<span class="f-uppercase">' + this [ word ] + '</span>'
46+ }
47+ return match
48+ } )
49+ }
4850}
4951
52+
0 commit comments