Localised os.date() when bundled as HTML5

According to the Lua manual, os.date() should return a localised strings for day and month:

print(os.date("today is %A, in %B"))

All representations follow the current locale. Therefore, in a locale for Brazil-Portuguese, %B would result in "setembro" and %x in "16/09/98" .

When exporting to HTML5 and Facebook Instant the locale appears to be hard coded to English (which is the language of the build machine) in the dmloade.js file. Is this right?

Not sure if it’s right. It sounds wrong :slight_smile:

And I’m not sure what we can do to solve the problem. I’ll make a note to investigate but I can’t promise a swift resolution.

1 Like

The Lua code for os.date() is here (5.2, but 5.1 is almost identical):

It uses gmtime() or localtime() in combination with strftime() to get the time in a struct, parse the string and use strftime() to replace %A, %B etc.

This means that it is strftime() that is responsible for transforming values into localized variants.

Calling os.setlocale() before calling os.date() works on desktop:

os.setlocale("pt_BR")
print(os.date("today is %A, in %B")) -- today is Terça Feira, in Março

But unfortunately not on HTML5… I’m uncertain if it’s possible to somehow change this at runtime. I think it’s better to use html5.run() and call some Javascript function to get a formatted string.

3 Likes