neptune2 / esp8266-weather-station-oled-DST

Customized version of Squix78 ESP8266 OLED Weather Station w/ Auto Daylight Saving Time Adjust and other mods using SSD1306 OLED. See https://github.com/squix78/esp8266-weather-station for original code and library
61 stars 17 forks source link

Localize the date #5

Closed Supersimo88 closed 7 years ago

Supersimo88 commented 7 years ago

I'm changing the code to make the station entirely in my native language, the only thing that I could not change is the date. can you help me? I would like to have the date in my language, and have the day before the month "Sun 5 February 2017" instead of "sun February 05 2017"

neptune2 commented 7 years ago

The date is fully customizable in line 404 of the code:

https://github.com/neptune2/esp8266-weather-station-oled-DST/blob/master/esp8266-weather-station-oled-DST.ino#L404

change the line to date = date.substring(0,4) + String(timeinfo->tm_mday) + date.substring(3,8) + String(1900+timeinfo->tm_year); to get the format you want.

Also note that there is an updated version of this code as an example in the original Squix78 esp8266-weather-station library https://github.com/squix78/esp8266-weather-station/tree/master/examples/WeatherStationDemoExtendedDST

Supersimo88 commented 7 years ago

There is a way to have it localized?

neptune2 commented 7 years ago

I am not aware of any built-in localization the esp8266 or Arduino libraries. It is typically a feature of a much larger operating system such as Linux, OS X or Windows.

However, it is easy to implement for dates. Simply change the #define to one of the languages below or add your own language. If you don't like any of the abbreviations used below - you can change them.

#define espanol

#ifdef english
String str_mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
String str_wday[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
#endif

#ifdef espanol
String str_mon[] = {"enero", "feb", "marzo", "abr", "mayo", "jun", "jul", "agosto", "set", "oct", "nov", "dic"};
String str_wday[] = {"lun", "mar", "mie", "jue", "vie", "sab", "dom"};  // 3 letras
// String str_wday[] = {"lu", "ma", "mi", "ju", "vi", "sa", "do"}; // 2 letras
#endif

#ifdef deutsche
String str_mon[] = {"Jan", "Feb", "Marz", "Apr", "Mai", "Juni", "Juli", "Aug", "Sept", "Okt", "Nov", "Dez"};
String str_wday[] = {"Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"};
#endif

#ifdef francais
String str_mon[] = {"janv", "fevr", "mars", "avril", "mai", "juin", "juil", "aout", "sept", "oct", "nov", "dec"};
String str_wday[] = {"lun", "mar", "mer", "jeu", "ven", "sam", "dim"};
#endif

And change the date code on line 404 to the format you want:

date = str_wday[timeinfo->tm_wday] + ", " + str_mon[timeinfo->tm_mon] + " " + String(timeinfo->tm_mday) + ", " + String(1900+timeinfo->tm_year);
Supersimo88 commented 7 years ago

thanks a lot, now I would say that is perfect