kikito/i18n.lua

How to add the % symbol to a string?

josefnpat opened this issue · 4 comments

Is there a way to have a string with a % symbol in it?

I think the library thinks it's a variable, and tries to format it. I've tried \% and %%.

Can you provide an example code showing the issue?

No problem!;

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

i18n.set('en.test','%{name} feels 100%!')

print(i18n('test',{
  name = "Seppi",
}))

nothanks@DESKTOP-P3PO2HO ~/repos/i18n.lua
$ lua fail.lua
lua: ./i18n/interpolate.lua:32: bad argument #2 to 'format' (no value)
stack traceback:
        [C]: in function 'format'
        ./i18n/interpolate.lua:32: in function <./i18n/interpolate.lua:27>
        (tail call): ?
        (tail call): ?
        ./i18n/init.lua:140: in function <./i18n/init.lua:132>
        (tail call): ?
        fail.lua:5: in main chunk
        [C]: ?

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

i18n.set('en.test','%{name} feels 100 percent!')

print(i18n('test',{
  name = "Seppi",
}))

nothanks@DESKTOP-P3PO2HO ~/repos/i18n.lua
$ lua good.lua
Seppi feels 100 percent!

Hi, I have updated a change that should fix the issue. Thanks for reporting it!

Awesome! You rock; i'll be updating my internal repos asap!