Skip to content

Commit 2d105fb

Browse files
committed
Update README with usage alaternative message access examples
1 parent 27df5f0 commit 2d105fb

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,32 @@ Initialized project with some boiler plate Lua aparatus.
4949
Lua code `demo.lua`:
5050

5151
```lua
52+
-- Import and start a new instance
5253
local 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

6271
Output of `lua demo.lua`:
6372

6473
```txt
6574
bar
6675
Hello World!
76+
bar
77+
Hello World!
6778
```
6879

6980
## Alternative(s)

0 commit comments

Comments
 (0)