Translating dates (weekdays, months, etc)?
yangm97 opened this issue · comments
Thank you for the library, it's incredible, but I would like to ask how should I handle these? The readme mentions only plurals.
For instance, consider the following code:
temp = os.date("*t")
api.sendAdmin(i18n('bot_started',temp), true)
Lua will return integers for both weekdays and months, which kind of makes it easier to work with. So, how can I turn those integers into their respective translations?
The concrete problem of "given a list of month names, obtain the name from the list", I would just use a table:
local month_names = {'Jan', 'Feb', 'Mar' ... }
print(month_names[3]) -- Mar
But that's not the interesting problem. The interesting problem is that each country represents dates in a way. Sometimes the month goes first, then the day, then the year. Other times the day goes first. Sometimes the day is a ordinal ("21st") and others a plain number ("21"). Sometimes they are separated by '/'. Other times by '-'. And other times by complete words, or commas. And some locales require different ways to represent a date (tiny, short, mid, and long).
I'm sorry, but this lib does not include facilities for solving the interesting problem (if you want to try to send a PR, feel free!). In the meantime my recommendation is just using ISO 8601 for dates, like so:
local function iso_8601(d)
return os.date("!%Y-%m-%dT%TZ",d)
end
...
api.sendAdmin(iso_8601(temp), true)