File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed
Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -49,21 +49,32 @@ Initialized project with some boiler plate Lua aparatus.
4949Lua code ` demo.lua ` :
5050
5151``` lua
52+ -- Import and start a new instance
5253local FluentBundle = require (" fluent" )
53- local en = FluentBundle (" en-US" )
54- en :add_messages ({
55- " foo = bar" ,
56- " hello = Hello { $name }!"
57- })
58- print (en :format (" foo" ))
59- print (en :format (" hello" , { name = " World" }))
54+ local bundle = FluentBundle ()
55+
56+ -- Load some messages (can be a string or table of strings)
57+ bundle :add_messages ([[
58+ foo = bar
59+ hello = Hello { $name }!
60+ ]] )
61+
62+ -- Access methods like other Fluent implementations
63+ print (bundle :format (" foo" ))
64+ print (bundle :format (" hello" , { name = " World" }))
65+
66+ -- Alternate idomatic Lua access methods
67+ print (bundle [" foo" ]) -- access property, implicit cast to string, cannot pass parammeters
68+ print (bundle .hello ({ name = " World" })) -- access as property is callable, parameters passed to format()
6069```
6170
6271Output of ` lua demo.lua ` :
6372
6473``` txt
6574bar
6675Hello World!
76+ bar
77+ Hello World!
6778```
6879
6980## Alternative(s)
You can’t perform that action at this time.
0 commit comments