alerque / fluent-lua

Lua implementation of Project Fluent https://projectfluent.org
MIT License
20 stars 4 forks source link

Loading multiple resources into a locale does bad things #15

Closed alerque closed 2 years ago

alerque commented 5 years ago

After loading multiple strings (and hence merging Resources), access using "format()" seems okay but access using table properties is borked. The last thing added seems to win out.

alerque commented 5 years ago

Might be a parse error after attributes (too greedy?)

Works:

local FluentBundle = require("fluent")
local bundle = FluentBundle()
bundle:add_messages([[
baz = qux
foo = bar
    .attr = BAR
]])
print(bundle.baz)
print(bundle.foo.attr)

Fails:

local FluentBundle = require("fluent")
local bundle = FluentBundle()
bundle:add_messages([[
foo = bar
    .attr = BAR
baz = qux
]])
print(bundle.baz)
print(bundle.foo.attr)
alerque commented 2 years ago

I just sunk large bits of 2 days into whacking out this bug and have nothing to show. Much better understanding of Lua perhaps, a few more debug tricks up my sleeve, a dive into Visual Studio Code plugins, and a lot of incidental bug fixes. But no fix for this.

At this point I suspect foul play in Penlight. I actually made it work by isolating fluent/resource.lua into two copies in two files and loading it twice and loading the messages after the attribute with the second copy, but I can't make out why the clobbering happens when that class is reused.