kikito / i18n.lua

A very complete i18n lib for Lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot define mid tree sections

josefnpat opened this issue · comments

commented

So I'm working on a game, and I'm using i18n, and I've tracked down this "bug".

If this is how it's meant to work, a better error message should be made. If it isn't, then I'm happy to report this issue.

In this example I want en.name and en.namebetty (So I can reasonably make "Name: Betty") but I get this error:

nothanks@DESKTOP-P3PO2HO ~/repos/i18n.lua
$ cat fail.lua
i18n = require'i18n.init'

i18n.set('en.name',"Name:")
i18n.set('en.name.betty',"Betty")

nothanks@DESKTOP-P3PO2HO ~/repos/i18n.lua
$ lua fail.lua
lua: ./i18n/init.lua:129: attempt to index local 'node' (a string value)
stack traceback:
        ./i18n/init.lua:129: in function 'set'
        fail.lua:4: in main chunk
        [C]: ?

First, you don't need to namespace everything with 'en.'. The locale is set by default. If you namespace with 'en.' you will be creating entries in 'en.en.name'.

Second, the example is working as intented. Internally this is done with tables. If you set 'en.name' to a string ('Name:'), you can't use the "dot" on it.

My suggestion for your particular case would be creating an entry called en.name.default and using it when getting the name.

i18n.set('name.default', 'Betty')
...

i18n('something', default: i18n.get('name.default'))
commented

That's what I ended up doing; thanks!

Would you mind adding an error message for this edge case then?

commented

Also, the readme has the following code:

-- loading stuff
i18n.set('en.welcome', 'welcome to this program')

would this not create en.welcome.welcome?

You are right, those examples where poorly written. I have fixed the readme accordingly. Thanks for reporting this.