-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathexample.js
51 lines (45 loc) · 1.59 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const LocalizedStrings = require('./lib/LocalizedStrings').default;
const strings = new LocalizedStrings({
en: {
question: "I'd like {0} and {1}, or just {0}",
questionWithObject: "I'd like {bread} and {eggs}, or just {bread}",
questionWithReferences:
"I'd like $ref{fridge.bread} and $ref{fridge.butter}, or just $ref{fridge.bread}",
login: 'login',
onlyForMembers: 'You have to {0} in order to use our app',
bold: 'bold',
iAmText: 'I am {0} text',
january: 'January',
currentDate: 'The current date is {month} {day}, {year}!',
fridge: {
milk: 'milk',
eggs: 'eggs',
bread: 'bread',
butter: 'butter',
},
},
});
// Will output: I'd like bread and butter, or just bread
console.log('Input each value');
console.log(
' ',
strings.formatString(
strings.question,
strings.fridge.bread,
strings.fridge.butter,
),
);
// Will output: I'd like bread and butter, or just bread
console.log('Input object');
console.log(
' ',
strings.formatString(strings.questionWithObject, strings.fridge),
);
// Will output: I'd like bread and butter, or just bread
console.log('Input references from string');
console.log(' ', strings.formatString(strings.questionWithReferences));
// Possible to use formatString with dot-notation, this is same as .getString and will not crash the application if the key isn't found.
console.log('Input string that doesnt exists');
console.log(' ', strings.formatString('fridge.missing'));
console.log('Input object that doesnt exists');
console.log(' ', strings.formatString(strings.fridge.missing.more));