When learning gettext in lua, a strange problem arose: it simply does not work. Folder structure:

gtest -> locale -> ru -> LC_MESSAGES -> test.mo test.po test.lua 

The code that loads it is:

 gettext = require 'gettext' --> библиотека https://github.com/bungle/lua-resty-gettext/blob/master/lib/resty/gettext.lua gettext.bindtextdomain ('test', 'locale'); gettext.textdomain ('test'); _ = gettext.gettext 

However, the translation is not displayed. What's the matter?
UPD: LANG = en_RU.UTF8.

  • How do you translate that into test.po and how did you get test.mo? - andreymal
  • test.po: paste.ubuntu.com/17426690 , test.mo - using msgfmt test.po. - val
  • And if export LANG=ru_RU.UTF-8 in the console and then run the program in the same console? - andreymal
  • @andreymal is set like this. - val

1 answer 1

Before defining a domain, you must complete

 os.setlocale (''); 

If you want to change the language, then you need this code (before setlocale ):

 ffi = require 'ffi' ffi.cdef [[int putenv(const char *asetting);]] ffi.C.putenv('LANG=ru_RU.utf8') -- поменять ru_RU.utf8 на требуемое значение